Async profiler: V1 pooled ValueTask instrumentation.#129801
Open
lateralusX wants to merge 2 commits into
Open
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-threading-tasks |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the V1 async-profiler (state-machine / TaskAsync) instrumentation to cover PoolingAsyncValueTaskMethodBuilder / PoolingAsyncValueTaskMethodBuilder<T>, including correct Resume/Complete/Unwind event emission and callstack walking through pooling-box continuation chains, and adds targeted V1 tests for pooling-ValueTask scenarios.
Changes:
- Add async-profiler hooks to pooling state-machine boxes (resume + complete/unwind) and implement diagnostic-chain exposure for pooling boxes.
- Update dispatcher completion/suspend classification to work uniformly for Task-backed and pooling-box continuations.
- Add/extend V1 async-profiler tests to validate pooling ValueTask lifecycle events, callstacks, ConfigureAwait(false), and append behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Runtime/tests/System.Threading.Tasks.Tests/System.Runtime.CompilerServices/AsyncProfilerV1Tests.cs | Adds pooling-ValueTask coverage and renames/extends ValueTask V1 scenarios to validate event + callstack behavior. |
| src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs | Exposes a continuation object for diagnostic walking from ManualResetValueTaskSourceCore. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ValueTaskAwaiter.cs | Avoids dispatcher interposition for IAsyncStateMachineBox continuations to preserve box→box cascades. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/PoolingAsyncValueTaskMethodBuilderT.cs | Adds V1 async-profiler resume/complete/unwind hooks for pooling boxes and implements GetDiagnosticData. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs | Mirrors the awaiter guard to prevent unnecessary dispatcher insertion for box continuations. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs | Consolidates complete/unwind paths to route through the updated dispatcher helpers with flags. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncStateMachineDispatcher.cs | Tracks completion via TLS flag (works for pooling boxes) and retypes continuation tracking to IAsyncStateMachineBox. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncProfiler.cs | Uses the new continuation accessor path for append/callstack walking and removes Task-only assumptions. |
This was referenced Jun 24, 2026
Open
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 V1 AsyncProfiler instrumentation (added in #129043) to PoolingAsyncValueTaskMethodBuilder / PoolingAsyncValueTaskMethodBuilder. Previously the pooling builder's reusable StateMachineBox was a no-op for the profiler — GetDiagnosticData was a stub and the box emitted no resume/complete/unwind events — leaving trace gaps wherever the pooling builder is used.
Motivation
The pooling builder backs an async method with a poolable IValueTaskSource-based StateMachineBox rather than a Task derived AsyncStateMachineBox. The existing instrumentation assumed Task-backed boxes, so pooling-builder methods produced incomplete async traces (missing per-method Resume/Complete, empty callstacks, and incorrect suspend/complete context classification). This makes the V1 async profiler consistent across the regular Task/ValueTask builders and the pooling builder.
Changes
Pooling box instrumentation (PoolingAsyncValueTaskMethodBuilderT.cs)
Suspend/complete classification for non-Task boxes (AsyncStateMachineDispatcher.cs, AsyncProfiler.cs)
Callstack walk over pooling chains
Cascade guard (ValueTaskAwaiter.cs, ConfiguredValueTaskAwaitable.cs)
Tests
14 new tests in AsyncProfilerV1Tests.cs (13 pooling + 1 regular-ValueTask single-threaded). Each mirrors an existing ValueTask/Task test: