Skip to content

fix(profiling): IO/allocation sampling intervals - #4159

Open
realFlowControl wants to merge 10 commits into
masterfrom
florian/fix-sampling-algo
Open

fix(profiling): IO/allocation sampling intervals#4159
realFlowControl wants to merge 10 commits into
masterfrom
florian/fix-sampling-algo

Conversation

@realFlowControl

@realFlowControl realFlowControl commented Sep 4, 2026

Copy link
Copy Markdown
Member

Description

I/O and allocation sampling used Poisson-distributed distances, but upscaling assumes exponential distances with inclusion probability p = 1 - exp(-size / interval). Both PHP allocator implementations share the allocation sampler.

This can overestimate totals by about 50%. For 110 KiB operations at the 100 KiB interval, the expected sampling probability is about 67%, but the old I/O sampler picks nearly every operation while upscaling still multiplies by about 1.50. Allocations near the 4 MiB interval have the same problem.

Use one shared exponential interval sampler for I/O and allocation profiling and retain the existing NTS/ZTS RNG choices. Round distances up to whole units with a minimum of one, and sample I/O when the counter reaches zero. Seeded allocation tests cover the default interval and tiny sampling distances; an I/O regression test covers the exact boundary.

Stabilize the I/O correctness tests with larger workloads, 6% byte margins, and 3-percentage-point socket-share margins. The larger workloads produce about 15,000 samples per metric, with roughly 0.8% relative sampling noise.

Strengthen the allocation correctness workload to 512 fixed iterations and check its actual totals: 18,874,368,000 payload bytes and 2,048 allocations. Use 6% total margins and 3-percentage-point share margins. The combined allocation/time test runs at least 128 iterations with 6-percentage-point allocation-share margins.

Keep the generator stack test's allocation-byte share assertions unchanged and remove its unstable allocation-count share assertions. Rare small allocation samples can dominate upscaled counts even when generator frames are correct. Allocation-count accuracy remains covered by the dedicated allocation test.

The old allocation percentage-only tests passed despite inflated totals. With the strengthened test, master reports about 13.78% excess bytes and 17.62% excess allocations and fails 100/100 runs.

Validated with PHP 8.5 NTS and the pinned dependencies: all 29 Rust unit tests pass. The tiny-allocation and I/O boundary regressions both fail without the rounding and boundary fixes.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

Increase I/O workloads and use 6% byte margins and 3-point socket share margins. Document the sampling-noise estimates in the test notes.
@github-actions github-actions Bot added profiling Relates to the Continuous Profiler tracing labels Sep 4, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Sep 4, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 18 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-php | Loader test on amd64 libc: [7.4, nts, amd64, true] — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-php | check libxml2 version — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-php | merge-gate — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

View all 18 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

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

Useful? React with 👍 / 👎

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

@realFlowControl
realFlowControl marked this pull request as ready for review September 4, 2026 10:27
@realFlowControl
realFlowControl requested review from a team as code owners September 4, 2026 10:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 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-09-04T10:30:13.053427Z 6a056e8 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.

@pr-commenter

pr-commenter Bot commented Sep 4, 2026

Copy link
Copy Markdown

Benchmarks [ profiler ]

Benchmark execution time: 2026-09-04 19:18:34

Comparing candidate commit 3d11c53 in PR branch florian/fix-sampling-algo with baseline commit 3b1267d in branch master.

Found 0 performance improvements and 3 performance regressions! Performance is the same for 24 metrics, 9 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 ----------------------------------'

scenario:php-profiler-timeline-memory-control

  • 🟥 cpu_user_time [+33.944ms; +40.617ms] or [+5.250%; +6.282%]
  • 🟥 execution_time [+32.436ms; +35.432ms] or [+4.736%; +5.174%]

scenario:php-profiler-timeline-memory-with-profiler

  • 🟥 cpu_user_time [+32.501ms; +66.701ms] or [+2.351%; +4.824%]

Match allocation sampling to the upscaler's inclusion probability. Add a seeded regression test and workload-derived correctness totals and margins.
@morrisonlevi morrisonlevi changed the title fix(profiling): use exponential intervals for I/O sampling fix(profiling): IO/allocation sampling intervals Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Relates to the Continuous Profiler tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant