Skip to content

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

Merged
taegyunkim merged 1 commit into
4.17from
backport-21230-to-4.17
Nov 12, 2026
Merged

taegyunkim merged 1 commit into
4.17from
backport-21230-to-4.17

Conversation

@dd-octo-sts

@dd-octo-sts dd-octo-sts Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

…up (#21230)

## Description

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).

## Testing

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

## Risks

None.

## Additional Notes

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

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

Co-authored-by: vlad.scherbich <vlad.scherbich@datadoghq.com>
(cherry picked from commit c1198df)

Co-authored-by: Vlad Scherbich <vlad.scherbich@datadoghq.com>
@dd-octo-sts
dd-octo-sts Bot requested review from a team as code owners November 12, 2026 17:18
@dd-octo-sts
dd-octo-sts Bot requested a review from KowalskiThomas November 12, 2026 17:18
@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-12T17:20:41.638569Z d71edc0 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.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

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

Show existing violations (showing 5 of 104 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=122)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.llmobs._integrations.litellm -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.llmobs._integrations.langchain -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)
ddtrace.llmobs._integrations.langgraph -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=120)

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

Codeowners resolved as

Resolved from the full PR diff against 4.17 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

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 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

Source inspection supports preserving fast-copy intent through warmup, faulthandler changes, and fork restarts while retaining safeguards for foreign signal handlers. Runtime behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit d71edc0

@pr-commenter

pr-commenter Bot commented Nov 12, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-12 17:43:09

Comparing candidate commit d71edc0 in PR branch backport-21230-to-4.17 with baseline commit 4b9b6f7 in branch 4.17.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 587 metrics, 9 unstable metrics, 1 flaky benchmarks without significant changes.

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 ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:coreapiscenario-context_with_data_listeners

  • unstable execution_time [-669.669ns; +712.118ns] or [-6.194%; +6.586%]

scenario:coreapiscenario-core_dispatch_50_listeners

  • unstable execution_time [-1869.026ns; +1777.932ns] or [-9.238%; +8.788%]

scenario:coreapiscenario-core_dispatch_exception_listeners

  • unstable execution_time [-1918.875ns; +1603.577ns] or [-9.845%; +8.227%]

scenario:coreapiscenario-core_dispatch_listeners

  • unstable execution_time [-348.596ns; +374.077ns] or [-8.023%; +8.610%]

scenario:coreapiscenario-core_dispatch_no_args_listeners

  • unstable execution_time [-214.733ns; +210.491ns] or [-7.905%; +7.749%]

scenario:coreapiscenario-core_dispatch_with_results_1_listener

  • unstable execution_time [-88.804ns; +84.857ns] or [-6.096%; +5.825%]

scenario:coreapiscenario-core_dispatch_with_results_50_listeners

  • unstable execution_time [-4570.204ns; +4641.399ns] or [-9.039%; +9.180%]

scenario:coreapiscenario-core_dispatch_with_results_listeners

  • unstable execution_time [-1059.637ns; +841.537ns] or [-9.786%; +7.772%]

scenario:packagesupdateimporteddependencies-import_many_stdlib_cached

  • unstable execution_time [-61.144µs; +49.153µs] or [-10.585%; +8.509%]

Known flaky benchmarks

These benchmarks are marked as flaky and will not trigger a failure. Modify FLAKY_BENCHMARKS_REGEX to control which benchmarks are marked as flaky.

Known flaky benchmarks without significant changes:

  • scenario:packagespackageforrootmodulemapping-cache_off

@taegyunkim
taegyunkim merged commit 68732f4 into 4.17 Nov 12, 2026
539 checks passed
@taegyunkim
taegyunkim deleted the backport-21230-to-4.17 branch November 12, 2026 20:19
vlad-scherbich added a commit that referenced this pull request Nov 21, 2026
…up [backport 4.15] (#21240)

## Description

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

Cherry-pick `c1198df465`. Conflict in `sampler.cpp`: kept 4.15'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

Manual rewrite onto current `4.15` after the automated/draft tip went
DIRTY.

## Pre-review checklist

- [ ] The changes have been tested in real services in staging
- [ ] The PR does not result in new crashes
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