Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(profiling): backup sample types/period #403

Merged
merged 1 commit into from
May 9, 2024

Conversation

morrisonlevi
Copy link
Contributor

@morrisonlevi morrisonlevi commented Apr 25, 2024

What does this PR do?

This refactors the Profile to backup the sample types and period outside of the string table.

Adds api::ValueType::new, and uses that instead of direct instantiation. In most cases, this shortens from 4 lines to 1 (but not always).

Simplifies some vec![...] usage to [...] in tests, since the vector isn't needed at all.

Motivation

Restoring the sample types and period was the only place that used fn get_string(&self, id: StringId) -> &str outside of tests. Requiring the data structure to map in both directions to provide this functionality makes it hard for innovation. The upcoming StringTable PR will not provide the StringId to &str functionality.

Additional Notes

This is stacked on top of another PR, and there will be another PR stacked on this. They should all be merged at roughly the same time.

How to test the change?

This should be an internal change only, so test as usual.

@github-actions github-actions bot added the profiling Relates to the profiling* modules. label Apr 25, 2024
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch from 12fae0b to 2ae7586 Compare April 25, 2024 22:22
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch from 2ae7586 to 31e33c2 Compare April 28, 2024 04:51
examples/ffi/exporter.cpp Outdated Show resolved Hide resolved
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch 2 times, most recently from 5a3f760 to e212171 Compare April 29, 2024 23:12
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch 2 times, most recently from f74b130 to e102e07 Compare May 1, 2024 18:32
@morrisonlevi morrisonlevi force-pushed the levi/alloc-crate branch 3 times, most recently from 0f98317 to 622db33 Compare May 1, 2024 21:39
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch 3 times, most recently from 6ae45a4 to 83b7fa1 Compare May 2, 2024 05:12
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch from e9e34af to a1f5a62 Compare May 4, 2024 15:18
@codecov-commenter
Copy link

codecov-commenter commented May 4, 2024

Codecov Report

Attention: Patch coverage is 93.00699% with 10 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@47c595b). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #403   +/-   ##
=======================================
  Coverage        ?   65.57%           
=======================================
  Files           ?      187           
  Lines           ?    22873           
  Branches        ?        0           
=======================================
  Hits            ?    15000           
  Misses          ?     7873           
  Partials        ?        0           
Components Coverage Δ
crashtracker 20.37% <ø> (?)
data-pipeline 51.45% <ø> (?)
data-pipeline-ffi 0.00% <ø> (?)
ddcommon 81.23% <ø> (?)
ddcommon-ffi 74.93% <ø> (?)
ddtelemetry 53.72% <ø> (?)
ipc 79.30% <ø> (?)
profiling 76.89% <93.00%> (?)
profiling-ffi 60.05% <66.66%> (?)
serverless 0.00% <ø> (?)
sidecar 28.66% <ø> (?)
sidecar-ffi 0.00% <ø> (?)
spawn-worker 50.49% <ø> (?)
trace-mini-agent 69.12% <ø> (?)
trace-normalization 97.79% <ø> (?)
trace-obfuscation 95.74% <ø> (?)
trace-protobuf 25.64% <ø> (?)
trace-utils 68.85% <ø> (?)

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite reasonable! The only part I'm not very confident about is the magic around internal memory management in BackupSampleTypesAndPeriod, I left a few questions there.

profiling/src/api.rs Outdated Show resolved Hide resolved
profiling/src/internal/profile.rs Outdated Show resolved Hide resolved
profiling/src/internal/profile.rs Show resolved Hide resolved
/// Despite our manual drop order, it is still recommended to order the
/// fields in the order things should be dropped.
storage: ManuallyDrop<Vec<(String, String)>>,
period: Option<((String, String), i64)>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Out of curiosity, it seems that often we either omit or pass in a dummy period. I wonder if we should just get rid of this parameter for libdatadog API users (and libdatadog would always just insert a default one).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

@morrisonlevi morrisonlevi May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "period" really makes sense anyway, because we smush everything into a single profile. Only really makes sense for certain sample types, and only then it depends on the implementation.

I think we can file this under "out of scope" for this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, for sure, more of a passing observation.

profiling/src/internal/backup_sample_types.rs Outdated Show resolved Hide resolved
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch from 3883f89 to fa7a21f Compare May 9, 2024 19:12
@morrisonlevi morrisonlevi changed the title refactor(profiling)!: require sample types on profile resets refactor(profiling): backup sample types/period May 9, 2024
This breaks a dependency on the string table implementation details to
be able to reset a profile and preserve the sample types and period. It
does cause more allocations, though.

Adds api::ValueType::new and uses it instead of constructing it
directly, because in most cases with `new` it becomes a single line
instead of four.
@morrisonlevi morrisonlevi force-pushed the levi/sample-types-on-reset branch from fa7a21f to 724f019 Compare May 9, 2024 19:47
@morrisonlevi morrisonlevi changed the base branch from levi/alloc-crate to main May 9, 2024 19:47
@morrisonlevi morrisonlevi marked this pull request as ready for review May 9, 2024 19:47
@morrisonlevi morrisonlevi requested a review from a team as a code owner May 9, 2024 19:47
@morrisonlevi morrisonlevi requested review from ivoanjo and danielsn May 9, 2024 19:52
profiling/src/api.rs Outdated Show resolved Hide resolved
/// Despite our manual drop order, it is still recommended to order the
/// fields in the order things should be dropped.
storage: ManuallyDrop<Vec<(String, String)>>,
period: Option<((String, String), i64)>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

profiling/src/internal/backup_sample_types.rs Outdated Show resolved Hide resolved
@morrisonlevi morrisonlevi merged commit 00e924b into main May 9, 2024
31 checks passed
@morrisonlevi morrisonlevi deleted the levi/sample-types-on-reset branch May 9, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Relates to the profiling* modules.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants