Skip to content

Set during_sample around the worker's final internal-thread sample - #6448

Merged
eregon merged 1 commit into
masterfrom
fix-during_sample-internal-thread-done
Oct 9, 2026
Merged

eregon merged 1 commit into
masterfrom
fix-during_sample-internal-thread-done

Conversation

@eregon

@eregon eregon commented Oct 8, 2026

Copy link
Copy Markdown
Member

thread_context_collector_profiler_internal_thread_done documents "Assumption 1: When called while the profiler is active, during_sample MUST be set", but release_gvl_and_run_sampling_trigger_loop called it bare.

The profiler is still active at that point: disable_hooks and the active_sampler_instance_state = NULL reset only run after rb_protect returns in _native_sampling_loop. So on_newobj_event and on_gc_event can still fire and would observe during_sample unset while we sample the worker thread's own sampling_buffer.

Route the call through _native_profiler_internal_thread_done, the other caller of the same function, which already wraps it in during_sample_enter + rb_ensure(..., during_sample_exit_ensure).

What does this PR do?

Motivation:

Change log entry

Additional Notes:

How to test the change?

`thread_context_collector_profiler_internal_thread_done` documents
"Assumption 1: When called while the profiler is active, `during_sample`
MUST be set", but `release_gvl_and_run_sampling_trigger_loop` called it
bare.

The profiler is still active at that point: `disable_hooks` and the
`active_sampler_instance_state = NULL` reset only run after `rb_protect`
returns in `_native_sampling_loop`. So `on_newobj_event` and
`on_gc_event` can still fire and would observe `during_sample` unset
while we sample the worker thread's own `sampling_buffer`.

Route the call through `_native_profiler_internal_thread_done`, the
other caller of the same function, which already wraps it in
`during_sample_enter` + `rb_ensure(..., during_sample_exit_ensure)`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@eregon
eregon requested a review from a team as a code owner October 8, 2026 14:59
@eregon
eregon requested review from ivoanjo and removed request for a team October 8, 2026 14:59
@dd-octo-sts dd-octo-sts Bot added the profiling Involves Datadog profiling label Oct 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T15:01:29.481397Z 87a6c70 PR opened
🔒 Security Review ✅ Completed 2026-10-08T15:02:31.734296Z 87a6c70 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@datadog-official

datadog-official Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Tests

✅ All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 90.65% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 87a6c70 | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Oct 8, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-10-08 15:26:17

Comparing candidate commit 87a6c70 in PR branch fix-during_sample-internal-thread-done with baseline commit ac74293 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 52 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

@eregon
eregon enabled auto-merge October 8, 2026 15:35

@ivoanjo ivoanjo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 Ah very elegant! It's one of those "obvious in retrospect, but I didn't see it when I was working on it". Thanks for the fix

@eregon
eregon merged commit fbe6901 into master Oct 9, 2026
619 checks passed
@eregon
eregon deleted the fix-during_sample-internal-thread-done branch October 9, 2026 07:41
@dd-octo-sts dd-octo-sts Bot added this to the 2.45.0 milestone Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Involves Datadog profiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants