-
Notifications
You must be signed in to change notification settings - Fork 9
Otel allocation profiling POC #422
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
Draft
nsavoire
wants to merge
1
commit into
main
Choose a base branch
from
nsavoire/otel_allocation_profiling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| #include <atomic> | ||
| #include <cassert> | ||
| #include <cstdlib> | ||
| #include <sys/sdt.h> | ||
| #include <unistd.h> | ||
|
|
||
| namespace ddprof { | ||
|
|
@@ -100,45 +101,49 @@ DDRes AllocationTracker::allocation_tracking_init( | |
| DDRES_RETURN_ERROR_LOG(DD_WHAT_UKNW, "Allocation profiler already started"); | ||
| } | ||
|
|
||
| DDRES_CHECK_FWD(instance->init(allocation_profiling_rate, | ||
| flags & kDeterministicSampling, | ||
| flags & kTrackDeallocations, stack_sample_size, | ||
| ring_buffer, timer_check)); | ||
| DDRES_CHECK_FWD(instance->init(allocation_profiling_rate, flags, | ||
| stack_sample_size, ring_buffer, timer_check)); | ||
| _instance = instance; | ||
|
|
||
| state.init(true, flags & kTrackDeallocations); | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| DDRes AllocationTracker::init(uint64_t mem_profile_interval, | ||
| bool deterministic_sampling, | ||
| bool track_deallocations, | ||
| DDRes AllocationTracker::init(uint64_t mem_profile_interval, uint32_t flags, | ||
| uint32_t stack_sample_size, | ||
| const RingBufferInfo &ring_buffer, | ||
| const IntervalTimerCheck &timer_check) { | ||
| _sampling_interval = mem_profile_interval; | ||
| _deterministic_sampling = deterministic_sampling; | ||
| _deterministic_sampling = flags & kDeterministicSampling; | ||
| _stack_sample_size = stack_sample_size; | ||
| if (ring_buffer.ring_buffer_type != | ||
| static_cast<int>(RingBufferType::kMPSCRingBuffer)) { | ||
| return ddres_error(DD_WHAT_PERFRB); | ||
| _otel_profiler_mode = flags & kOtelProfilerMode; | ||
|
|
||
| if (!_otel_profiler_mode) { | ||
| if (ring_buffer.ring_buffer_type != | ||
| static_cast<int>(RingBufferType::kMPSCRingBuffer)) { | ||
| return ddres_error(DD_WHAT_PERFRB); | ||
| } | ||
|
|
||
| DDRES_CHECK_FWD(ddprof::ring_buffer_attach(ring_buffer, &_pevent)); | ||
|
|
||
| const auto &rb = _pevent.rb; | ||
| if (rb.tsc_available) { | ||
| TscClock::init(TscClock::CalibrationParams{ | ||
| .offset = TscClock::time_point{TscClock::duration{rb.time_zero}}, | ||
| .mult = rb.time_mult, | ||
| .shift = rb.time_shift}); | ||
| } | ||
| PerfClock::init(static_cast<PerfClockSource>(rb.perf_clock_source)); | ||
| } else { | ||
| PerfClock::init(PerfClockSource::kClockMonotonic); | ||
| } | ||
| if (track_deallocations) { | ||
|
|
||
| if (flags & kTrackDeallocations) { | ||
r1viollet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // 16 times as we want to probability of collision to be low enough | ||
| _allocated_address_set = AddressBitset(liveallocation::kMaxTracked * | ||
| k_ratio_max_elt_to_bitset_size); | ||
| } | ||
| DDRES_CHECK_FWD(ddprof::ring_buffer_attach(ring_buffer, &_pevent)); | ||
|
|
||
| const auto &rb = _pevent.rb; | ||
| if (rb.tsc_available) { | ||
| TscClock::init(TscClock::CalibrationParams{ | ||
| .offset = TscClock::time_point{TscClock::duration{rb.time_zero}}, | ||
| .mult = rb.time_mult, | ||
| .shift = rb.time_shift}); | ||
| } | ||
| PerfClock::init(static_cast<PerfClockSource>(rb.perf_clock_source)); | ||
|
|
||
| _interval_timer_check = timer_check; | ||
| if (_interval_timer_check.is_set()) { | ||
|
|
@@ -282,6 +287,7 @@ void AllocationTracker::track_deallocation(uintptr_t addr, | |
| DDRes AllocationTracker::push_lost_sample(MPSCRingBufferWriter &writer, | ||
| TrackerThreadLocalState &tl_state, | ||
| bool ¬ify_needed) { | ||
| DDPROF_DCHECK_FATAL(!_otel_profiler_mode); | ||
| auto lost_count = _state.lost_count.exchange(0, std::memory_order_acq_rel); | ||
| if (lost_count == 0) { | ||
| return {}; | ||
|
|
@@ -322,6 +328,12 @@ DDRes AllocationTracker::push_lost_sample(MPSCRingBufferWriter &writer, | |
| // Return true if consumer should be notified | ||
| DDRes AllocationTracker::push_clear_live_allocation( | ||
| TrackerThreadLocalState &tl_state) { | ||
| if (_otel_profiler_mode) { | ||
| // NOLINTNEXTLINE | ||
| DTRACE_PROBE(ddprof, clear_live_allocations); | ||
| check_timer(PerfClock::now(), tl_state); | ||
| return {}; | ||
| } | ||
| MPSCRingBufferWriter writer{&_pevent.rb}; | ||
| bool timeout = false; | ||
|
|
||
|
|
@@ -361,6 +373,13 @@ DDRes AllocationTracker::push_clear_live_allocation( | |
|
|
||
| DDRes AllocationTracker::push_dealloc_sample( | ||
| uintptr_t addr, TrackerThreadLocalState &tl_state) { | ||
| if (_otel_profiler_mode) { | ||
| // NOLINTNEXTLINE | ||
| DTRACE_PROBE1(ddprof, deallocation, addr); | ||
r1viollet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| check_timer(PerfClock::now(), tl_state); | ||
| return {}; | ||
| } | ||
|
|
||
| MPSCRingBufferWriter writer{&_pevent.rb}; | ||
| bool notify_consumer{false}; | ||
|
|
||
|
|
@@ -414,6 +433,13 @@ DDRes AllocationTracker::push_dealloc_sample( | |
| DDRes AllocationTracker::push_alloc_sample(uintptr_t addr, | ||
| uint64_t allocated_size, | ||
| TrackerThreadLocalState &tl_state) { | ||
| if (_otel_profiler_mode) { | ||
| // NOLINTNEXTLINE | ||
| DTRACE_PROBE2(ddprof, allocation, addr, allocated_size); | ||
| check_timer(PerfClock::now(), tl_state); | ||
| return {}; | ||
| } | ||
|
|
||
| MPSCRingBufferWriter writer{&_pevent.rb}; | ||
| bool notify_consumer{false}; | ||
|
|
||
|
|
@@ -427,12 +453,12 @@ DDRes AllocationTracker::push_alloc_sample(uintptr_t addr, | |
| const auto *stack_base_ptr = reinterpret_cast<const std::byte *>(&p); | ||
| auto stack_size = to_address(tl_state.stack_bounds.end()) - stack_base_ptr; | ||
|
|
||
| // stack will be saved in save_context, add some margin to account for call | ||
| // stack will be saved in save_context, add some ` to account for call | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor, comment was broken here |
||
| // frames | ||
| #ifdef NDEBUG | ||
| constexpr int64_t kStackMargin = 192; | ||
| #else | ||
| constexpr int64_t kStackMargin = 720; | ||
| constexpr int64_t kStackMargin = 4000; | ||
| #endif | ||
| uint32_t const sample_stack_size = | ||
| align_up(std::min(std::max(stack_size + kStackMargin, 0L), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| add_subdirectory(CLI) | ||
| add_subdirectory(llvm) | ||
| add_subdirectory(systemtap) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| add_library(systemtap INTERFACE) | ||
| target_include_directories(systemtap INTERFACE include/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /* @configure_input@ | ||
|
|
||
| This file just defines _SDT_ASM_SECTION_AUTOGROUP_SUPPORT to 0 or 1 to | ||
| indicate whether the assembler supports "?" in .pushsection directives. */ | ||
|
|
||
| #define _SDT_ASM_SECTION_AUTOGROUP_SUPPORT 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because monotonic is what the full host profiler would expect, and tsc logic is not available
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On otel profiler mode,
PerfClockis not used to timestamp samples (since it's done on eBFP side), I had to initialize it because it's also used to determine when periodically check for newly loaded libraries.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And indeed TSC calibration is done on ddprof side and is not available here.