Skip to content

fix(profiling): keep fast-copy intent across faulthandler during warmup [backport 4.16] - #21241

Open
vlad-scherbich wants to merge 1 commit into
4.16from
backport-21230-to-4.16
Open

vlad-scherbich wants to merge 1 commit into
4.16from
backport-21230-to-4.16

Conversation

@vlad-scherbich

@vlad-scherbich vlad-scherbich commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Backport of #21230 to 4.16 (same squash as #21723).

Cherry-pick c1198df465. Conflict in sampler.cpp: kept 4.16's foreign-handler log lines (no ownership APIs on this branch); took PR1's seed_fast_copy_profiler_stats() + sampler_active_.store(false) on the no-fallback stop path.

Testing

Unit tests from source for faulthandler-during-warmup and mid-warmup fork.

Risks

Same as #21230 / #21723.

Additional Notes

https://datadoghq.atlassian.net/browse/PROF-15995

Pre-review checklist

  • The changes have been tested in real services in staging
  • The PR does not result in new crashes

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against 4.16 using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/internal/datadog/profiling/dd_wrapper/include/profiler_stats.hpp  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/dd_wrapper/src/profiler_stats.cpp    @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/echion/echion/vm.h             @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/echion/vm.cc               @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/sampler.cpp                @DataDog/profiling-python
ddtrace/internal/datadog/profiling/stack/src/stack.cpp                  @DataDog/profiling-python
releasenotes/notes/profiling-fast-copy-mid-warmup-fork-15886547dcf91a47.yaml  @DataDog/apm-python
releasenotes/notes/profiling-fast-copy-warmup-faulthandler-3f1c8a4d92b7e05a.yaml  @DataDog/apm-python
tests/profiling/collector/test_copy_memory_stats.py                     @DataDog/profiling-python
tests/profiling/collector/test_utils.py                                 @DataDog/profiling-python

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 199 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 199 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=132)
ddtrace.llmobs._integrations.mcp -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=130)
ddtrace.debugging._exception.replay -×-> ddtrace.trace  (product:debugging -> product:tracing, score=130)
ddtrace.internal.opentelemetry.span -×-> ddtrace.trace  (product:opentelemetry -> product:tracing, score=130)
ddtrace.internal.ci_visibility.recorder -×-> ddtrace.trace  (product:ci_visibility -> product:tracing, score=130)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 1 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector

@pr-commenter

pr-commenter Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-16 21:24:40

Comparing candidate commit 3c33f8d in PR branch backport-21230-to-4.16 with baseline commit 8b92032 in branch 4.16.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 16 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 ----------------------------------'

@vlad-scherbich
vlad-scherbich marked this pull request as ready for review November 12, 2026 19:05
@vlad-scherbich
vlad-scherbich requested review from a team as code owners November 12, 2026 19:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T19:14:58.227063Z 3c33f8d Draft marked ready
ℹ️ 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 Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

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

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bits Code Review: FAIL

During warmup, a no-op faulthandler.disable() can overwrite handlers installed by a native library. This bypasses the intended syscall fallback and can corrupt the crash-handler chain.

Open Bits AI session

🤖 Bits Code Review · Commit da94087

@vlad-scherbich
vlad-scherbich enabled auto-merge (squash) November 12, 2026 19:28
@vlad-scherbich
vlad-scherbich requested a review from a team November 12, 2026 20:20

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Preserved fast-copy intent allows coordinated faulthandler swaps during warmup to restore recovery handlers before fast-copy sampling resumes. Runtime behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 71e5772

…up (#21230)

Warmup clears `fast_copy_active` while our SIGSEGV handler is still installed. Handler install/uninstall/reclaim keyed off that flag, so `faulthandler.enable()` in the window took the handler unnoticed and the warmup deadline pinned the process to the syscall copy for life.

This PR adds persistent `fast_copy_desired` (untouched by warmup), uses `fast_copy_handler_ops_enabled()` for those handler ops, and publishes `fast_copy_memory_desired` in internal metadata. It also pins the mid-warmup fork path: a child re-runs the warmup decision instead of inheriting `fast_copy_active == false` for life (gunicorn/celery prefork).

* new unit tests (faulthandler during warmup; fork during warmup)

None.

Stack: **1/3** (includes mid-warmup fork pin). Next: sticky foreign takeover (#21232).

https://datadoghq.atlassian.net/browse/PROF-15995

- [ ] The changes have been tested in real services in staging
- [ ] The PR does not result in new crashes

Co-authored-by: vlad.scherbich <vlad.scherbich@datadoghq.com>
(cherry picked from commit c1198df)
@vlad-scherbich
vlad-scherbich marked this pull request as draft November 16, 2026 21:05
auto-merge was automatically disabled November 16, 2026 21:05

Pull request was converted to draft

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Separating fast-copy intent from its active state supports recovery after faulthandler coordination and forks during warmup. The completed static review identified no actionable regressions; runtime signal-handler behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 3c33f8d

@vlad-scherbich
vlad-scherbich marked this pull request as ready for review November 21, 2026 19:13

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Static review identified no reportable defect in handler coordination during warmup or sampler restart after fork. Runtime behavior remains unverified because the checkout lacks built native extensions.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 3c33f8d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant