Skip to content

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

Open
realFlowControl wants to merge 11 commits into
masterfrom
florian/io-profiling-fixes
Open

realFlowControl wants to merge 11 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, skips disabled 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

Unblock PR with BitsAI

⚠️ Warnings

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

🚦 9 Pipeline jobs failed

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 | check-big-regressions — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

DataDog/apm-reliability/dd-trace-php | helper-rust integration coverage — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

View all 9 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: 55.03% (-0.05%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 6a871d9 | 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-14 14:29:53

Comparing candidate commit 6a871d9 in PR branch florian/io-profiling-fixes with baseline commit a0bf05c in branch master.

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

@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
@morrisonlevi

Copy link
Copy Markdown
Collaborator

Closed in favor of #4159 which fixes IO and allocation at the same time

@realFlowControl

realFlowControl commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

Closed in favor of #4159 which fixes IO and allocation at the same time

@morrisonlevi this PR initially had the sampling fixes, but I moved them to #4159, so the fixes in here are not related to sampling/upscaling any more, but other gotchas and correctness issues

@realFlowControl
realFlowControl force-pushed the florian/io-profiling-fixes branch from 1e04c4b to cd92e60 Compare September 14, 2026 10:58
@realFlowControl
realFlowControl marked this pull request as ready for review September 14, 2026 12:10
@realFlowControl
realFlowControl requested review from a team as code owners September 14, 2026 12:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 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-14T12:17:12.386082Z cd92e60 Draft marked ready
🔒 Security Review Completed 2026-09-14T12:17:31.591601Z cd92e60 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd92e60908

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread profiling/src/io/mod.rs
@pr-commenter

pr-commenter Bot commented Sep 14, 2026

Copy link
Copy Markdown

Benchmarks [ tracer ]

Benchmark execution time: 2026-09-14 15:23:25

Comparing candidate commit 6a871d9 in PR branch florian/io-profiling-fixes with baseline commit a0bf05c in branch master.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 191 metrics, 1 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:LaravelBench/benchLaravelOverhead-opcache

  • 🟥 execution_time [+0.923ms; +1.835ms] or [+7.971%; +15.851%]

scenario:TraceFlushBench/benchFlushTrace-opcache

  • 🟥 execution_time [+1.723ms; +1.748ms] or [+457.647%; +464.233%]

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.

2 participants