Repository navigation
fix(profiling): sample an asyncio eager task's first step once - #21744
taegyunkim wants to merge 9 commits into
Conversation
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
BenchmarksBenchmark execution time: 2026-11-23 21:39:19 Comparing candidate commit a54f185 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 607 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
68fa2fa to
e99e72d
Compare
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
|
…eager-task-single-sample
…eager-task-single-sample # Conflicts: # ddtrace/internal/datadog/profiling/stack/src/echion/threads.cc
…'s label The sampler reads the stack before the tasks. If the step ends in between, that tick's sample keeps the step's stack but is labelled with a creator. Accept that on the last sample instead of stopping the profiler from inside the eager task.
Description
JIRA: PROF-16348
An eager task (Python 3.12+) runs its first step inside
create_task, while the task that called it is still running. The stack sampler saw both as on CPU and gave each a full copy of the sample, so that time was counted twice. The eager task's copy also had a wrong stack.When several tasks on a thread are running, the sampler now finds each one's coroutine frame on the thread stack and emits a single sample. That sample has the outermost task's stack and the innermost task's labels. The sampler reads the thread without stopping it, so a step can start or end while it reads. Tasks are placed using the frames read for the stack, and at most one running task gets a sample.
Testing
New
test_asyncio_eager_tasks.py. One test checks an eager child and an eager grandchild for one sample per tick, the right task and the full stack. It lets the step's last sample carry a creator's label, the edge case under Risks. Another runs 10,000 short eager steps and checks one sample per tick at step edges. Both fail without the fix.tests/profilingpassed on Python 3.9, 3.12, 3.13 and 3.14 (Linux aarch64,scripts/run-tests) before the last test change; CI covers that change. Native gtests are left to CI.Risks
At a step's start or end, a sample can be labeled with the creating task instead of the eager task. Its time is still counted once.
Additional Notes
None.