dotnet profile app running in kubernetes

find application

kubectl top po --sort-by=cpu | grep chatapi

connect to it

kubectl exec -it chatapi-6d57d67769-vvzj2 -- bash

update packages and install required soft

apt update
apt install -y wget procps

install profiler

mkdir -p /root/dotTrace && cd /root/dotTrace
wget "https://download.jetbrains.com/resharper/dotUltimate.2020.3.4/JetBrains.dotTrace.CommandLineTools.linux-x64.2020.3.4.tar.gz"
tar -xzf JetBrains.dotTrace.CommandLineTools.linux-x64.2020.3.4.tar.gz
chmod +x dotTrace.sh

find our process pid

ps aux

in my case output was (our app has pid - 1)

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1 24.8  2.4 9623436 397544 ?      Ssl  10:56  12:59 dotnet RUA.ChatAPI.dll
root         263  0.0  0.0   4148  3404 pts/0    Ss   11:44   0:00 bash
root         659  0.0  0.0   7652  2692 pts/0    R+   11:48   0:00 ps aux

knowing the pid, run profiler

./dotTrace.sh attach 1  --timeout=60s --save-to=/root/snapshot.dtp

after profiler done its work, disconnect from pod, and from local machine run

kubectl cp chatapi-6d57d67769-vvzj2:/root/snapshot.dtp  ~/Downloads/trace/snapshot.dtp
kubectl cp chatapi-6d57d67769-vvzj2:/root/snapshot.dtp.0000 ~/Downloads/trace/snapshot.dtp.0000
kubectl cp chatapi-6d57d67769-vvzj2:/root/snapshot.dtp.0001 ~/Downloads/trace/snapshot.dtp.0001
kubectl cp chatapi-6d57d67769-vvzj2:/root/snapshot.dtp.0002 ~/Downloads/trace/snapshot.dtp.0002
kubectl cp chatapi-6d57d67769-vvzj2:/root/snapshot.dtp.0003 ~/Downloads/trace/snapshot.dtp.0003

now open project in rider, switch to the same branch as in production (in my case it was simply master)

next choose dotTrace Profiler menu and lick on icon with folder to open snapshot and open downloaded snapshot.dtp (he will open rest of the files on its own)