Skip to content

Commit

Permalink
[PROF-10125] Track unscaled allocation counts in allocation profiler
Browse files Browse the repository at this point in the history
**What does this PR do?**

This PR extends the allocation profiler to also track the unscaled
allocation counts.

Specifically, like other profile types, the allocation profiler assigns
a weight to every sample, making it "represent" all the objects that
weren't sampled.

**Motivation:**

For debugging, in corner cases, it comes in handy to know exactly how
many samples the profiler observed, and what was the impact of scaling.

As part of preparing the allocation profiler feature for GA, I'm adding
this feature so we can use it to confirm the exact sample counts
whenever needed.

Note also this is something we do for the cpu/wall-time profiler, where
we track the `cpu_or_wall_samples` as an exact count of how many samples
were taken (and again, without the weight -- which in the case of those
profilers, represents time).

**Additional Notes:**

N/A

**How to test the change?**

This change includes test coverage.
  • Loading branch information
ivoanjo committed Jul 9, 2024
1 parent 78d7d27 commit 87eeb0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ void thread_context_collector_sample_allocation(VALUE self_instance, unsigned in
/* thread: */ current_thread,
/* stack_from_thread: */ current_thread,
get_or_create_context_for(current_thread, state),
(sample_values) {.alloc_samples = sample_weight},
(sample_values) {.alloc_samples = sample_weight, .alloc_samples_unscaled = 1},
INVALID_TIME, // For now we're not collecting timestamps for allocation events, as per profiling team internal discussions
&ruby_vm_type,
optional_class_name
Expand Down
6 changes: 6 additions & 0 deletions spec/datadog/profiling/collectors/thread_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,12 @@ def self.otel_sdk_available?
expect(single_sample.values).to include(:'alloc-samples' => 123)
end

it 'tags the sample with the unscaled weight' do
sample_allocation(weight: 123)

expect(single_sample.values).to include('alloc-samples-unscaled': 1)
end

it 'includes the thread names, if available' do
thread_with_name = Thread.new do
Thread.current.name = 'thread_with_name'
Expand Down

0 comments on commit 87eeb0f

Please sign in to comment.