Support for printing thread stack traces and heaps composition in dotnet-monitor
See original GitHub issueWe wrote a much simpler version of dotnet monitor that uses Microsoft.Diagnostics.Runtime
to help with high level debugging of remote processes running in Kubernetes. Our implementation returns a stack trace of all threads in a given process, as well as the type composition of all heaps, ordered by object size. This is very convenient to get a feel for what a process is doing without having to download a dump and load it in dotnet analyze
.
e.g. In our implementation, http://localhost:52323/dump
returns something that looks like
--------------------------------------------------------------------
STACK TRACE
--------------------------------------------------------------------
Thread - OS 00015910 - Managed 1:
25aaf7e070 7ffb6af86278 [GCFrame]
25aaf7e1b8 7ffb6af86278 [HelperMethodFrame_1OBJ]
25aaf7e2e0 7ffbc9a43725 System.Threading.ManualResetEventSlim.Wait(Int32, System.Threading.CancellationToken)
25aaf7e380 7ffbc9a43052 System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken)
25aaf7e3f0 7ffbc9a42dcf System.Threading.Tasks.Task.InternalWaitCore(Int32, System.Threading.CancellationToken)
25aaf7e470 7ffbc9a61604 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
25aaf7e4a0 7ffbc9a4432d System.Runtime.CompilerServices.TaskAwaiter.GetResult()
25aaf7e4d0 7ffc275d6585 Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(Microsoft.Extensions.Hosting.IHost)
25aaf7e500 7ffb6a5a1790 WebApplication2.Program.Main(System.String[])
25aaf7e788 7ffbca0c6103 [GCFrame]
25aaf7ed30 7ffbca0c6103 [GCFrame]
Thread - OS 00002a90 - Managed 2:
25abbffa00 7ffb6af86278 [DebuggerU2MCatchHandlerFrame]
Thread - OS 00008898 - Managed 4:
25ac37ed18 7ffb6af86278 [HelperMethodFrame]
25ac37ee10 7ffbc9b2b91b System.Threading.Thread.Sleep(Int32)
25ac37ee40 7ffb6a5a4535 WebApplication2.Program.DoWork()
25ac37eeb0 7ffb6a5a40d1 WebApplication2.Program+<>c.<Main>b__0_0()
25ac37eee0 7ffbc9a47bd3 System.Threading.Tasks.Task.InnerInvoke()
25ac37ef20 7ffbc9a47b82 System.Threading.Tasks.Task+<>c.<.cctor>b__274_0(System.Object)
25ac37ef50 7ffbc9a47b02 System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
25ac37efa0 7ffbc9a477d7 System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
25ac37f040 7ffbc9a476b3 System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread)
25ac37f080 7ffbc9a4764b System.Threading.Tasks.Task.ExecuteFromThreadPool(System.Threading.Thread)
25ac37f0b0 7ffbc9a4723c System.Threading.ThreadPoolWorkQueue.Dispatch()
25ac37f160 7ffbc9a4706b System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
25ac37f570 7ffbca0c6103 [DebuggerU2MCatchHandlerFrame]
[...]
--------------------------------------------------------------------
HEAPS
--------------------------------------------------------------------
--------------------------------------------------------------------
GENERATION 0
System.String - 764954
System.Byte[] - 735445
System.Security.Cryptography.Oid - 735360
System.Char[] - 419616
System.Security.Cryptography.X509Certificates.X509Extension[] - 201128
System.Security.Cryptography.X509Certificates.X509Extension - 193440
[...]
--------------------------------------------------------------------
GENERATION 1
Free - 288
--------------------------------------------------------------------
GENERATION 2
Free - 768
Would it be feasible or would you be interested in supporting a similar feature? Maybe in two different endpoints /stacktrace
and /heap
?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Support for printing thread stack traces and heaps composition in ...
Our implementation returns a stack trace of all threads in a given process, as well as the type composition of all heaps, ordered...
Read more >dotnet-stack diagnostic tool - .NET CLI
Learn how to install and use the dotnet-stack CLI tool which captures and prints the managed stacks for all threads in the target...
Read more >JEP 444: Virtual Threads
The system property jdk.tracePinnedThreads triggers a stack trace when a thread blocks while pinned. Running with -Djdk.tracePinnedThreads=full ...
Read more >https://raw.githubusercontent.com/dotnet/samples/m...
Threading.AsyncLazy`1.<>c__DisplayClass13_1.<<GetValueAsync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown ...
Read more >Tim Misiak (@timmisiak) / X
New blog post: There are lots of reasons the debugger might be lying to you. One (very annoying) reason is stack corruption. In...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I like this feature but I’d like to return a JSON representation of the stacks not a textual one so that we could build a nice UI on top (someday) 😄
Accept
ftw