dd-trace-php icon indicating copy to clipboard operation
dd-trace-php copied to clipboard

feat(prof): detect parallel threads

Open realFlowControl opened this issue 4 months ago • 4 comments

Description

This PR adds code to detect and label threads that have been created by ext-parallel. It is actually 80% comments and just a few lines of code 😉

So in the end it turns out we can access the thread locals variables from other extensions. We do not need anything from that, just check if it is NULL. In case it is, it is not a ext-parallel thread, otherwise it is one 🎉

Technically I am checking for the php_parallel_scheduler_context TLS being non-NULL, it is set in the php_parallel_scheduler_setup() function right from the start of the thread main loop and before calling ts_resource(0); which triggers GINIT.

Reviewer checklist

  • [ ] Test coverage seems ok.
  • [ ] Appropriate labels assigned.

realFlowControl avatar Dec 03 '25 07:12 realFlowControl

Benchmarks [ profiler ]

Benchmark execution time: 2025-12-11 09:56:15

Comparing candidate commit 78caed3c82744eade76e12eb6c1d949677048d24 in PR branch florian/parallel with baseline commit 2790073f21c7ada33197d1ced184f02d81ee9aa0 in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 28 metrics, 8 unstable metrics.

pr-commenter[bot] avatar Dec 03 '25 07:12 pr-commenter[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 61.69%. Comparing base (2790073) to head (78caed3). :warning: Report is 17 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3515      +/-   ##
==========================================
- Coverage   61.81%   61.69%   -0.12%     
==========================================
  Files         142      142              
  Lines       12923    12923              
  Branches     1695     1695              
==========================================
- Hits         7988     7973      -15     
- Misses       4183     4196      +13     
- Partials      752      754       +2     

see 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2790073...78caed3. Read the comment docs.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Dec 03 '25 07:12 codecov-commenter

Benchmarks [ tracer ]

Benchmark execution time: 2025-12-11 10:47:37

Comparing candidate commit 78caed3c82744eade76e12eb6c1d949677048d24 in PR branch florian/parallel with baseline commit 2790073f21c7ada33197d1ced184f02d81ee9aa0 in branch master.

Found 3 performance improvements and 0 performance regressions! Performance is the same for 190 metrics, 1 unstable metrics.

scenario:EmptyFileBench/benchEmptyFileBaseline

  • 🟩 execution_time [-355.637µs; -129.003µs] or [-10.601%; -3.845%]

scenario:MessagePackSerializationBench/benchMessagePackSerialization

  • 🟩 execution_time [-7.026µs; -4.774µs] or [-6.549%; -4.449%]

scenario:TraceSerializationBench/benchSerializeTrace

  • 🟩 execution_time [-35.506µs; -21.994µs] or [-7.868%; -4.873%]

pr-commenter[bot] avatar Dec 03 '25 08:12 pr-commenter[bot]

[...] since you are a maintainer of ext/parallel, should we instead release a new version of it which does something to make this simpler and easier to know? [...]

I thought of this as well but: this won't allow us to detect "old" versions of parallel that would not export that new symbol (so we'd be left with either this code or being blind for those old versions).

[...] so rather than committing to platform specific code [...]

The code is fairly simple IMHO, it boils down to a dlsym(), a cast, a pointer dereference and a NULL compare, it won't get much simpler and honestly the MacOS code path only exists because we are using MacOS for local development.

I get your point though and it would be "nice" to have something explicit, so I've added 78caed3 and opened https://github.com/krakjoe/parallel/pull/352

realFlowControl avatar Dec 11 '25 10:12 realFlowControl