You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(profiling): link task samples to origin task (#19082)
[PROF-15417](https://datadoghq.atlassian.net/jira/software/c/projects/PROF/boards/11?selectedIssue=PROF-15417)
local
## Description
When an asyncio task offloads blocking work to a `ThreadPoolExecutor` (`await loop.run_in_executor(None, fn)`), that work runs on a pool worker thread that has no asyncio task of its own. Today those samples can't be tied back to the task that submitted and is awaiting them.
This adds two pprof labels on the executor worker thread's samples:
- origin task id -- `id()` of the submitting asyncio task
- origin task name -- that task's name
origin task id is deliberately the same value the profiler already emits as task id for the task on its event-loop thread, so the offloaded work correlates back to the awaiting task with no new join key.
The `futures` integration already wraps `ThreadPoolExecutor.submit` and runs the work through an intermediate `_wrap_execution` on the worker thread. We capture the current asyncio task at submit time, and at execution time register a `thread_id` -> `{task id, name}` entry in a native per-thread map for the duration of the job, clearing it in a `finally`. The stack renderer stamps the labels by looking that map up by sampled thread id. The worker thread isnt predicted ahead of time, rather, the link is made on whichever worker the pool assigns and torn down when the job completes, so pool reuse is handled correctly.
## Testing
<!-- Describe your testing strategy or note what tests are included -->
## Risks
<!-- Note any risks associated with this change, or "None" if no risks -->
## Additional Notes
<!-- Any other information that would be helpful for reviewers -->
[PROF-15417]: https://datadoghq.atlassian.net/browse/PROF-15417?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Co-authored-by: gyuheon.oh <gyuheon.oh@datadoghq.com>
0 commit comments