Skip to content

Instantly share code, notes, and snippets.

@jpcrs
Created August 30, 2021 11:30
Show Gist options
  • Save jpcrs/63263f5a7bccb0a6cbe3976a480daa74 to your computer and use it in GitHub Desktop.
Save jpcrs/63263f5a7bccb0a6cbe3976a480daa74 to your computer and use it in GitHub Desktop.
Getting dumps from dotnet process inside kubernetes
### Connect to Pod
kubectl exec -it podname -- /bin/bash
# Install dotnet counters and dotnet dump
# curl -L https://aka.ms/dotnet-counters/linux-x64 alternative link to download with curl
dotnet tool install --global dotnet-counters
dotnet tool install --global dotnet-dump
# Check process id
dotnet-counters ps
# Use counters to check resource usage, thread count, heap allocation, etc
dotnet-counters monitor -p 1
# Collect dump
# https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump -> More info on parameters to choose dump type, etc.
dotnet-dump collect -p 1
# Copy dump to local machine
kubectl cp <namespace>/<pod>:/tmp/dumps/dumpremote /tmp/dumps/dumplocal
# Download symbols from this Dump using dotnet-symbols
# More info at https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-symbol
dotnet-symbol --host-only --debugging <dump file path>
# At this point we can analyze the dump on VS or dotnet-dump
# Alternatively we can also use something like windbg, lldb, etc.
# Example using dotnet-dump
# List of commands for analyze SOS: https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump
dotnet-dump analyze <dumpfile>
# Some useful analyze SOS commands
#eeheap -gc -> Look at GC heaps, see where each region is looking at, Large object heap size, etc.
#dumpheap -stat -> Shows all the objects in the heap, sorted by usage size
#dumpheap -mt -> dump heap for a specific method table
#dumparray/dumpclass -length <length> <address> -> #https://docs.microsoft.com/en-us/dotnet/framework/tools/sos-dll-sos-debugging-extension
#db -c 1024 <address> -> ASCII representation of the address
#gcroot <address> -> Info about the reference map/gcroots to this object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment