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

[PROF-10422] Fix flaky GVL profiling integration spec #3936

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,25 @@
samples = samples_for_thread(
samples_from_pprof_without_gc_and_overhead(recorder.serialize!),
background_thread_affected_by_gvl_contention
)
).sort_by { |s| s.labels.fetch(:end_timestamp_ns) }

# Because the background_thread_affected_by_gvl_contention starts BEFORE the profiler, the first few samples
# will have an unknown state because the profiler may have missed the beginning of the Waiting for GVL
#
# So that the below assertions make sense (and are not flaky), we drop these first few samples from our
# consideration
missed_by_profiler_time =
samples.take_while { |s| s.labels[:state] == "unknown" }.sum { |sample| sample.values.fetch(:"wall-time") }

waiting_for_gvl_samples = samples.select { |sample| sample.labels[:state] == "waiting for gvl" }
total_time = samples.sum { |sample| sample.values.fetch(:"wall-time") }
total_time = samples.sum { |sample| sample.values.fetch(:"wall-time") } - missed_by_profiler_time
waiting_for_gvl_time = waiting_for_gvl_samples.sum { |sample| sample.values.fetch(:"wall-time") }

expect(waiting_for_gvl_samples.size).to be > 0

# The background thread should spend almost all of its time waiting to run (since when it gets to run
# it just passes and starts waiting)
expect(total_time).to be >= 200_000_000 # This test should run for at least 200ms, which is how long we sleep for
expect(waiting_for_gvl_time).to be < total_time
expect(waiting_for_gvl_time).to be_within(5).percent_of(total_time)

Expand Down
Loading