perf is often used to profile C/C++ programs but kind of falls short for JVM programs due to the dynamic nature of JIT. Fortunately, newer versions of perf do have special support for JIT in JVM via JVMTI. (One probably needs to build perf themselves, as many Linux distributions don’t enable JVMTI by default; the important file is libperf-jvmti.so.)

This note records some commands I often use while profiling JVM using perf.

  1. recording a run
1
2
3
4
5
6
7
perf record                               \
-clockid CLOCK_MONOTONIC \ # -k mono or -k 1
--call-graph lbr \
-e cycles \
java \
-agentpath:<absolute-path>/libperf-jvmti.so
...
  1. inject JIT data
1
perf inject -i perf.data --jit -o perf.data.jitted
  1. reading the report
1
perf report -Mintel -G -i perf.data.jitted

View the assembly (pressing a) and check for the hottest instructions (pressing H).

§Reference