Flame graphs for Java (super-short how to)

This is for Ubuntu!

Download async-profiler

wget https://github.com/async-profiler/async-profiler/releases/tag/v4.2.1#:~:text=async%2Dprofiler%2D4.2.1%2Dlinux%2Dx64.tar.gz
tar xvf async-profiler-4.2.1-linux-x64.tar.gz

Let user-space programs access Linux performance counters and expose kernel symbol addresses (can also make permanent)

sudo sysctl -w kernel.perf_event_paranoid=1
sudo sysctl -w kernel.kptr_restrict=0

Start Java and attach

java -jar <jar path> <params> &
echo "PID = $!"
echo "Waiting 20 seconds for the system to start up…"
sleep 20
~/async-profiler-4.2.1-linux-x64/bin/asprof -e wall -d 30 -f wall.html $!
echo "Profiling complete. Output saved to profile.html. Killing the Java process."
kill $!

The option -e wall is for wallclock time. You can also remove to have only CPU time.

Tagged with: , ,
Posted in programming

Leave a comment