trace running dotnet app (flame graph)
finally after figuring out how to do it with nodejs
it is turn for dotnet
imagine we have an application running inside Kubernetes
it is behaves bad and we literally have no idea why
here is how it may be done
choose victim pod
kubectl get po -l app=my-awesome-app
connect to it
kubectl exec -it my-awesome-app-xxxx-yyyy -- sh
install required software if needed
apk add wget
apk add bash
install corresponding dotnet sdk
wget https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --channel 7.0
export PATH="$HOME/.dotnet:$PATH"
install dotnet trace tool
dotnet tool install --global dotnet-trace
export PATH="$PATH:/root/.dotnet/tools"
find process id (pid) of your app
dotnet-trace ps
it should output something like this:
1 dotnet share/dotnet/dotnet dotnet Api.dll
where 1
is your pid
start collecting data for pid 1
dotnet-trace collect -p 1
it will start collecting data and after pressing enter stop in logs you will see
Press <Enter> or <Ctrl+C> to exit
Output File : /app/dotnet_20250402_074040.nettrace
now you need to copy this file from pod to your local machine
kubectl cp my-awesome-app-xxxx-yyyy:/app/dotnet_20250402_074040.nettrace demo.nettrace
note: nettrace files can be opened with dotTrace if you have it
the next step will be to convert it to json
dotnet-trace convert --format speedscope --output demo.json demo.nettrace
for this to work you need to install dotnet trace tool locally as well
and finally
open https://www.speedscope.app
and upload your json file, you should see an flame graph with details of whats going on