Skip to content

Commit

Permalink
Merge pull request #3806 from DataDog/ivoanjo/fix-profiler-flaky-spec
Browse files Browse the repository at this point in the history
[NO-TICKET] Fix profiler flaky test
  • Loading branch information
ivoanjo authored Jul 25, 2024
2 parents 2f591a1 + 4d7cbce commit f5757c2
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,22 +546,34 @@
# and we clamp it if it goes over the limit.
# But the total amount of allocations recorded should match the number we observed, and thus we record the
# remainder above the clamped value as a separate "Skipped Samples" step.
it 'records skipped allocation samples when weights are clamped' do
start

thread_that_allocates_as_fast_as_possible = Thread.new { loop { BasicObject.new } }
context 'with a high allocation rate' do
let(:options) { { **super(), dynamic_sampling_rate_overhead_target_percentage: 0.1 } }
let(:thread_that_allocates_as_fast_as_possible) { Thread.new { loop { BasicObject.new } } }

allocation_samples = try_wait_until do
samples = samples_from_pprof(recorder.serialize!).select { |it| it.values[:'alloc-samples'] > 0 }
samples if samples.any? { |it| it.labels[:'thread name'] == 'Skipped Samples' }
after do
thread_that_allocates_as_fast_as_possible.kill
thread_that_allocates_as_fast_as_possible.join
end

thread_that_allocates_as_fast_as_possible.kill
thread_that_allocates_as_fast_as_possible.join
it 'records skipped allocation samples when weights are clamped' do
start

cpu_and_wall_time_worker.stop
# Trigger thread creation
thread_that_allocates_as_fast_as_possible

allocation_samples = try_wait_until do
samples = samples_from_pprof(recorder.serialize!).select { |it| it.values[:'alloc-samples'] > 0 }
samples if samples.any? { |it| it.labels[:'thread name'] == 'Skipped Samples' }
end

# Stop thread earlier, since it will slow down the Ruby VM
thread_that_allocates_as_fast_as_possible.kill
thread_that_allocates_as_fast_as_possible.join

expect(allocation_samples).to_not be_empty
cpu_and_wall_time_worker.stop

expect(allocation_samples).to_not be_empty
end
end
end

Expand Down

0 comments on commit f5757c2

Please sign in to comment.