02 May 2020

Async-profiler is a low overhead sampling profiler for Java that produces nice flamegraphs to quickly see where CPU-cycles are eaten (event=cpu). It’s nice that it also shows where cycles are eaten in native code and is not biased twoards your application byte-code. It also allows to analyze heap allocations (event=alloc).

SwingSet2

You can either attach it to an already running Java application or use an agent to to attach it on startup.

Attach via agent on startup

java -agentpath:/home/daniel/tools/async-profiler-1.7-linux-x64/build/libasyncProfiler.so=start,event=cpu,file=/tmp/profile-cpu.svg,interval=1000000,framebuf=2000000,simple -jar target/myapp.jar

Attach to already running process

profiler.sh -e cpu -f /tmp/profile-cpu.svg  -i 1000000 -b 2000000 -s <process-id>