Async Profiler: Instrument custom awaiters in V1 dispatcher.#130297
Merged
lateralusX merged 2 commits intoJul 8, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends async-profiler (V1 / state-machine) instrumentation so that custom awaiters (i.e., awaiters that don’t hit the Task/ValueTask/Yield “known awaiter” fast paths) still get their continuations wrapped in an AsyncStateMachineDispatcher, enabling Create/Resume/Complete events to be emitted for those awaits.
Changes:
- Wrap the state machine box in an
AsyncStateMachineDispatcherfrom the generic builder fallback paths (AwaitOnCompletedand the non-known awaiter branch ofAwaitUnsafeOnCompleted) when async-profiler instrumentation is active. - Align
AsyncStateMachineDispatcher.MoveNextActionwith framework state-machine boxes by backing it with the inheritedTask.m_actionslot. - Add new tests covering custom awaiters across the
(pooling vs non-pooling) × (INotifyCompletion vs ICriticalNotifyCompletion)matrix, asserting the expected Create → Resume → Complete chain.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/System.Runtime.CompilerServices/AsyncProfilerV1Tests.cs | Adds coverage ensuring custom awaiters still produce V1 dispatcher events and callstack markers across pooling/non-pooling and notify/critical notify cases. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs | Creates a dispatcher for the pooling builder’s AwaitOnCompleted fallback path when async-profiler instrumentation is enabled. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs | Creates a dispatcher for AwaitOnCompleted and for the “unknown awaiter” branch of AwaitUnsafeOnCompleted under async-profiler instrumentation. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncStateMachineDispatcher.cs | Changes MoveNextAction caching to use Task.m_action, matching the existing AsyncStateMachineBox<TStateMachine> pattern. |
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
mdh1418
approved these changes
Jul 7, 2026
This was referenced Jul 7, 2026
Open
Open
noahfalk
approved these changes
Jul 8, 2026
Member
Author
|
/ba-g known issue #130177 |
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.
Summary
Extends the async profiler (V1 / StateMachine) so that continuations awaiting a custom awaiter are wrapped in an AsyncStateMachineDispatcher just like the built-in ones, making them visible to instrumentation.
Motivation
The V1 dispatcher is created on the awaiter's box-aware path (IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted), which only the framework awaiters (Task/ValueTask/YieldAwaitable) implement. For an arbitrary user awaiter, the async method builders fall back to the generic AwaitOnCompleted<TAwaiter, TStateMachine> / AwaitUnsafeOnCompleted paths, which registered box.MoveNextAction without creating a dispatcher. As a result, continuations that resumed through a custom awaiter never produced Create/Resume/Complete async-profiler events — leaving a gap in the captured async causality chain.
What changed
Tests
Notes / risk