Repository navigation
fix(profiling): sample an asyncio eager task's first step once, as the eager task - #22048
taegyunkim wants to merge 1 commit into
Conversation
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
BenchmarksBenchmark execution time: 2026-11-24 00:51:32 Comparing candidate commit 3b38d81 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 604 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
Description
JIRA: PROF-16348. Replaces #21744.
An eager task (Python 3.12 and 3.13) runs its first step inside
create_task, while its creator is still running. The stack sampler saw both tasks as on CPU and emitted a sample for each, so the step was counted twice. The eager task's copy also repeated its own frame and lost the creator's frames.The sampler now gives the sample to the running task found in
asyncio.tasks._eager_tasksand drops the other running tasks. Its stack is the whole thread stack belowHandle._run, which already holds the creator's frames, so nothing else is added. With nested eager steps, the innermost eager task owns the sample.The eager task owns the sample, not its creator, so that the step carries the eager task's span once task samples read their own task's Context.
Customer impact
Eager steps are reported once, under the eager task, with the full stack.
Testing
test_asyncio_eager_tasks.pychecks one sample per tick, the eager task's id and name, and the stack, for an eager child and an eager grandchild. It fails onmainand when the creator keeps the sample. Withtest_stack_asyncio_endpoint_labels.py, it passes on CPython 3.12.15 and 3.13.16 (Linux aarch64,scripts/run-tests). On 3.14.8 the new tests are strict xfails: native tasks never enter_eager_tasks.Risks
The sampler reads the thread while it runs, so one sample at a step's start or end can carry the other task's labels. It is still counted once.
Additional Notes
None.