Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Improve DumpAsync command
Browse files Browse the repository at this point in the history
- Add a stats summary at the beginning of the output
- Improved single-line-per-entry default behavior for increased readability
- Add option to include all tasks, not just async state machine objects
- Include state value for each async object, the state field for async state machines or the state flags for other tasks
- Support following continuation chains, rendered as "async stacks"
- Support resolving delegate names so that Task.Run and related items have the associated method name displayed
- Optional (experimental) DGML rendering of the graph
- Optionally include completed tasks, by default filtering them out
- Optionally display the fields of state machines
  • Loading branch information
stephentoub committed Nov 5, 2018
1 parent 4df3476 commit 10da33b
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 271 deletions.
5 changes: 3 additions & 2 deletions src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class Task : IAsyncResult, IDisposable
internal object m_stateObject; // A state object that can be optionally supplied, passed to action.
internal TaskScheduler m_taskScheduler; // The task scheduler this task runs under.

internal volatile int m_stateFlags;
internal volatile int m_stateFlags; // SOS DumpAsync command depends on this name

private Task ParentForDebugger => m_contingentProperties?.m_parent; // Private property used by a debugger to access this Task's parent
private int StateFlagsForDebugger => m_stateFlags; // Private property used by a debugger to access this Task's state flags
Expand Down Expand Up @@ -185,7 +185,8 @@ public class Task : IAsyncResult, IDisposable
internal const int TASK_STATE_EXECUTIONCONTEXT_IS_NULL = 0x20000000; //bin: 0010 0000 0000 0000 0000 0000 0000 0000
internal const int TASK_STATE_TASKSCHEDULED_WAS_FIRED = 0x40000000; //bin: 0100 0000 0000 0000 0000 0000 0000 0000

// A mask for all of the final states a task may be in
// A mask for all of the final states a task may be in.
// SOS DumpAsync command depends on these values.
private const int TASK_STATE_COMPLETED_MASK = TASK_STATE_CANCELED | TASK_STATE_FAULTED | TASK_STATE_RAN_TO_COMPLETION;

// Values for ContingentProperties.m_internalCancellationRequested.
Expand Down
62 changes: 9 additions & 53 deletions src/ToolBox/SOS/Strike/apollososdocs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,64 +344,20 @@ The arguments in detail:
\\

COMMAND: dumpasync.
!DumpAsync [-mt <MethodTable address>]
!DumpAsync [-mt <MethodTable address>]
[-type <partial type name>]
[-waiting]
[-roots]]
[-tasks]
[-completed]
[-fields]
[-stacks]
[-roots]
[-dgmlPath <output DGML file path>]

!DumpAsync traverses the garbage collected heap, looking for objects representing
async state machines as created when an async method's state is transferred to the
heap. This command recognizes async state machines defined as "async void", "async Task",
"async Task<T>", "async ValueTask", and "async ValueTask<T>".

The output includes a block of details for each async state machine object found.
These details include:
- a line for the type of the async state machine object, including its MethodTable address,
its object address, its size, and its type name.
- a line for the state machine type name as contained in the object.
- a listing of each field on the state machine.
- a line for a continuation from this state machine object, if one or more has been registered.
- discovered GC roots for this async state machine object.

For example:

0:011> !DumpAsync -roots
#0
000001989f413de0 00007ff88c506ba8 112 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
StateMachine: Program+<MethodD>d__4 (struct)
MT Field Offset Type VT Attr Value Name
00007ff8d3df4b80 400000d 0 System.Int32 1 instance 0 <>1__state
00007ff8d3e082c0 400000e 8 ...TaskMethodBuilder 1 instance 000001989f413e38 <>t__builder
00007ff8d3dfea90 400000f 10 ...vices.TaskAwaiter 1 instance 000001989f413e40 <>u__1
Continuation: 000001989f413e50 (System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodC>d__3, test]])
GC roots:
Thread 2936c:
000000071a37e050 00007ff8d3ac1657 System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken) [d:\repos\coreclr\src\System.Private.CoreLib\src\System\Threading\Tasks\Task.cs @ 2977]
rbp+10: 000000071a37e0c0
-> 000001989f413fa0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<Main>d__0, test]]
-> 000001989f413f30 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodA>d__1, test]]
-> 000001989f413ec0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodB>d__2, test]]
-> 000001989f413e50 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodC>d__3, test]]
-> 000001989f413de0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
HandleTable:
000001989d8415f8 (pinned handle)
-> 00000198af3e1038 System.Object[]
-> 000001989f413410 System.Threading.TimerQueue[]
-> 000001989f413468 System.Threading.TimerQueue
-> 000001989f413330 System.Threading.TimerQueueTimer
-> 000001989f412e40 System.Threading.Tasks.Task+DelayPromise
-> 000001989f413de0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
...


The arguments in detail:

-mt List only those state machine objects with the MethodTable given.
-type List only those state machine objects whose type name is a
substring match of the string provided.
-waiting List only those state machines that are currently at an await point.
-roots Include GC root information for each state machine object.

"async Task<T>", "async ValueTask", and "async ValueTask<T>". It also optionally supports
any other tasks.
\\

COMMAND: dumpstackobjects.
Expand Down
62 changes: 9 additions & 53 deletions src/ToolBox/SOS/Strike/sosdocs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,64 +342,20 @@ The arguments in detail:
\\

COMMAND: dumpasync.
!DumpAsync [-mt <MethodTable address>]
!DumpAsync [-mt <MethodTable address>]
[-type <partial type name>]
[-waiting]
[-roots]]
[-tasks]
[-completed]
[-fields]
[-stacks]
[-roots]
[-dgmlPath <output DGML file path>]

!DumpAsync traverses the garbage collected heap, looking for objects representing
async state machines as created when an async method's state is transferred to the
heap. This command recognizes async state machines defined as "async void", "async Task",
"async Task<T>", "async ValueTask", and "async ValueTask<T>".

The output includes a block of details for each async state machine object found.
These details include:
- a line for the type of the async state machine object, including its MethodTable address,
its object address, its size, and its type name.
- a line for the state machine type name as contained in the object.
- a listing of each field on the state machine.
- a line for a continuation from this state machine object, if one or more has been registered.
- discovered GC roots for this async state machine object.

For example:

0:011> !DumpAsync -roots
#0
000001989f413de0 00007ff88c506ba8 112 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
StateMachine: Program+<MethodD>d__4 (struct)
MT Field Offset Type VT Attr Value Name
00007ff8d3df4b80 400000d 0 System.Int32 1 instance 0 <>1__state
00007ff8d3e082c0 400000e 8 ...TaskMethodBuilder 1 instance 000001989f413e38 <>t__builder
00007ff8d3dfea90 400000f 10 ...vices.TaskAwaiter 1 instance 000001989f413e40 <>u__1
Continuation: 000001989f413e50 (System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodC>d__3, test]])
GC roots:
Thread 2936c:
000000071a37e050 00007ff8d3ac1657 System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken) [d:\repos\coreclr\src\System.Private.CoreLib\src\System\Threading\Tasks\Task.cs @ 2977]
rbp+10: 000000071a37e0c0
-> 000001989f413fa0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<Main>d__0, test]]
-> 000001989f413f30 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodA>d__1, test]]
-> 000001989f413ec0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodB>d__2, test]]
-> 000001989f413e50 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodC>d__3, test]]
-> 000001989f413de0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
HandleTable:
000001989d8415f8 (pinned handle)
-> 00000198af3e1038 System.Object[]
-> 000001989f413410 System.Threading.TimerQueue[]
-> 000001989f413468 System.Threading.TimerQueue
-> 000001989f413330 System.Threading.TimerQueueTimer
-> 000001989f412e40 System.Threading.Tasks.Task+DelayPromise
-> 000001989f413de0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
...


The arguments in detail:

-mt List only those state machine objects with the MethodTable given.
-type List only those state machine objects whose type name is a
substring match of the string provided.
-waiting List only those state machines that are currently at an await point.
-roots Include GC root information for each state machine object.

"async Task<T>", "async ValueTask", and "async ValueTask<T>". It also optionally supports
any other tasks.
\\

COMMAND: dumpstackobjects.
Expand Down
62 changes: 9 additions & 53 deletions src/ToolBox/SOS/Strike/sosdocsunix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,64 +203,20 @@ The arguments in detail:
\\

COMMAND: dumpasync.
!DumpAsync [-mt <MethodTable address>]
!DumpAsync [-mt <MethodTable address>]
[-type <partial type name>]
[-waiting]
[-roots]]
[-tasks]
[-completed]
[-fields]
[-stacks]
[-roots]
[-dgmlPath <output DGML file path>]

!DumpAsync traverses the garbage collected heap, looking for objects representing
async state machines as created when an async method's state is transferred to the
heap. This command recognizes async state machines defined as "async void", "async Task",
"async Task<T>", "async ValueTask", and "async ValueTask<T>".

The output includes a block of details for each async state machine object found.
These details include:
- a line for the type of the async state machine object, including its MethodTable address,
its object address, its size, and its type name.
- a line for the state machine type name as contained in the object.
- a listing of each field on the state machine.
- a line for a continuation from this state machine object, if one or more has been registered.
- discovered GC roots for this async state machine object.

For example:

(lldb) dumpasync -roots
#0
000001989f413de0 00007ff88c506ba8 112 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
StateMachine: Program+<MethodD>d__4 (struct)
MT Field Offset Type VT Attr Value Name
00007ff8d3df4b80 400000d 0 System.Int32 1 instance 0 <>1__state
00007ff8d3e082c0 400000e 8 ...TaskMethodBuilder 1 instance 000001989f413e38 <>t__builder
00007ff8d3dfea90 400000f 10 ...vices.TaskAwaiter 1 instance 000001989f413e40 <>u__1
Continuation: 000001989f413e50 (System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodC>d__3, test]])
GC roots:
Thread 2936c:
000000071a37e050 00007ff8d3ac1657 System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken) [d:\repos\coreclr\src\System.Private.CoreLib\src\System\Threading\Tasks\Task.cs @ 2977]
rbp+10: 000000071a37e0c0
-> 000001989f413fa0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<Main>d__0, test]]
-> 000001989f413f30 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodA>d__1, test]]
-> 000001989f413ec0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodB>d__2, test]]
-> 000001989f413e50 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodC>d__3, test]]
-> 000001989f413de0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
HandleTable:
000001989d8415f8 (pinned handle)
-> 00000198af3e1038 System.Object[]
-> 000001989f413410 System.Threading.TimerQueue[]
-> 000001989f413468 System.Threading.TimerQueue
-> 000001989f413330 System.Threading.TimerQueueTimer
-> 000001989f412e40 System.Threading.Tasks.Task+DelayPromise
-> 000001989f413de0 System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[[System.Threading.Tasks.VoidTaskResult, System.Private.CoreLib],[Program+<MethodD>d__4, test]]
...


The arguments in detail:

-mt List only those state machine objects with the MethodTable given.
-type List only those state machine objects whose type name is a
substring match of the string provided.
-waiting List only those state machines that are currently at an await point.
-roots Include GC root information for each state machine object.

"async Task<T>", "async ValueTask", and "async ValueTask<T>". It also optionally supports
any other tasks.
\\

COMMAND: dumpstackobjects.
Expand Down
Loading

0 comments on commit 10da33b

Please sign in to comment.