refactor(profiling): separate task address discovery - #19709
Draft
taegyunkim wants to merge 1 commit into
Draft
Conversation
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
Contributor
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 9bda1d5 | Docs | Datadog PR Page | Give us feedback! |
taegyunkim
force-pushed
the
taegyunkim/profiling-task-address-discovery
branch
from
August 14, 2026 15:53
1fdd48c to
9f3c682
Compare
taegyunkim
force-pushed
the
taegyunkim/profiling-task-address-discovery
branch
from
August 14, 2026 16:54
9f3c682 to
9bda1d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Motivation and scope
This refactor was identified while implementing the CPU timer profiler in #18724. CPU timer signals capture task identity evidence, and the later drain phase needs to scan lightweight task identities before materializing only the matching task and its parents. The existing task traversal could only return fully constructed
TaskInfosnapshots.This PR remains independently mergeable because it contains no CPU timer behavior, configuration, or public API. It only extracts the existing CPython task-source traversal behind a private visitor while preserving the current wall-sampling behavior. PR #18724 is the first planned consumer of the new visitor, but this feature-neutral extraction can be reviewed and merged independently before it.
Before this PR
Asyncio task-source traversal is coupled directly to wall-sampling snapshot construction:
Each Python-version-specific task source contains its own
TaskInfoconstruction and filtering logic. Another sampling path cannot reuse task discovery without either constructing every full task snapshot or duplicating the CPython task-source traversal.After this PR
Task-source traversal reports each address to a shared visitor:
Wall sampling still constructs and filters each
TaskInfoimmediately when its address is visited. It does not collect task addresses for later materialization, so this PR does not add a temporal gap or change the task-snapshot order.The following behavior is unchanged:
tstateandtstate_addrare available.TaskInfoconstruction and event-loop filtering.The CPU timer follow-up can use the same visitor to copy only each task's address, coroutine address, and waiter address. After identifying the task captured by the signal handler, it constructs
TaskInfoonly for that task and the parents needed for logical ancestry.Review guide
This is intended to be a mechanical extraction. The existing comments, helper names, local variables, source conditions, and traversal control flow are retained.
callback(task_address)where they previously constructedTaskInfo.get_all_tasks()supplies a callback containing the previousTaskInfo::create(), event-loop filter, and append operation.There is no intermediate task-address vector and no change to the wall sampler's point of materialization.
Testing
scripts/lint cformat.scripts/lint profiling-native-check.scripts/lint checks.Risks
Low. Task-source traversal now invokes a private callback for each address. Wall sampling performs the same guarded snapshot construction and filtering inside that callback, at the same point in traversal as before.
Additional Notes
No release note is needed because this is an internal refactor with no customer-visible behavior change.