Skip to content

fix(profiling): Fix I/O profiling gotchas - #4156

Draft
realFlowControl wants to merge 9 commits into
masterfrom
florian/io-profiling-fixes
Draft

fix(profiling): Fix I/O profiling gotchas#4156
realFlowControl wants to merge 9 commits into
masterfrom
florian/io-profiling-fixes

Conversation

@realFlowControl

@realFlowControl realFlowControl commented Sep 3, 2026

Copy link
Copy Markdown
Member

Description

This PR addresses several correctness bugs, security improvements, and hot-path performance bottlenecks in the I/O profiler (profiling/src/io):

  • Correctness in observed_poll: Correctly distinguishes returned and requested events, evaluates both read and write readiness across all descriptors, handles output-only events such as POLLHUP, and avoids reading the descriptor array when nfds == 0 or poll() fails.
  • Byte counting in fread and fwrite: Records total bytes (items * size) rather than item count (nobj).
  • GNU_RELRO security: Restores PROT_READ memory protection on Linux after patching GOT entries in RELRO segments.
  • Loader safety: Adds bounds checks to Mach-O indirect symbol and string tables, masks INDIRECT_SYMBOL_LOCAL/ABS flags, bounds ELF dynamic section loops, and skips the ld-musl linker.
  • Fast-path bypass: Non-PHP threads, such as cURL async DNS resolver threads, exit immediately from profiling hooks, avoiding clock reads and sampler TLS initialization. The close hook still invalidates the process-wide file descriptor cache.
  • Removed static mut ORIG_*: All hooks now call libc::* directly because ddtrace.so explicitly excludes itself from GOT hooking, eliminating data races and redundant dlsym(RTLD_NEXT) lookups.

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

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

@github-actions github-actions Bot added profiling Relates to the Continuous Profiler tracing labels Sep 3, 2026
@datadog-datadog-prod-us1

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

Copy link
Copy Markdown

Pipelines  Tests

⚠️ Warnings

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

🚦 6 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-php | appsec integration tests (ssi): [test8.3-release-ssi]

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-php | appsec integration tests: [test8.3-release]

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-php | helper-rust integration coverage

View more details · View in GitLab

View all 6 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: 8d724d8 | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Sep 3, 2026

Copy link
Copy Markdown

Benchmarks [ profiler ]

Benchmark execution time: 2026-09-04 14:54:05

Comparing candidate commit 8d724d8 in PR branch florian/io-profiling-fixes with baseline commit 3b1267d in branch master.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 24 metrics, 10 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 [+32.333ms; +44.230ms] or [+4.976%; +6.807%]
  • 🟥 execution_time [+34.292ms; +36.744ms] or [+4.897%; +5.247%]

@realFlowControl
realFlowControl force-pushed the florian/io-profiling-fixes branch 3 times, most recently from 05ff2e5 to 8297f6b Compare September 4, 2026 08:57
@realFlowControl realFlowControl added the AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos label Sep 4, 2026
@realFlowControl
realFlowControl force-pushed the florian/io-profiling-fixes branch from 8297f6b to 02433cf Compare September 4, 2026 11:25
@realFlowControl
realFlowControl force-pushed the florian/io-profiling-fixes branch from 02433cf to 8d724d8 Compare September 4, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated Largely based on code generated by an AI or LLM. This label is the same across all dd-trace-* repos profiling Relates to the Continuous Profiler tracing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant