JIT profiling using perf

Profile Just In Time (JIT) execution by using perf on a supported JIT engine, to collect trace information when running your program. Then you can import the generated jitdump data into Streamline for analysis.

Common supported languages are: Node.js, Chrome V8 Javascript, and Java.

You can specify the jitdump file paths in the Analyze dialog box, JIT Dump Files tab, which is shown in the following figure.

Analyze dialog box (JIT Dump Files tab).

Streamline processes the files to extract the source and line information, and shows the generated machine code in the Code view.

Note

  • You must pass -k CLOCK_MONOTONIC to perf record when profiling using libperf-jvmti.so. libperf-jvmti.so uses CLOCK_MONOTONIC but, by default, perf does not use the same clock.

An example of how to profile and analyze JIT execution could be:

  1. To capture profiling data using perf record, you must use a CLOCK_MONOTONIC clock:

    sudo perf record -k CLOCK_MONOTONIC -a -c 1 -e "{sched:sched_switch, cpu-clock/period=10000000/, instructions, branch-misses}:S" java -agentpath:<path-to-libperf-jvmti.so> <java-main-class>"
    

    To include call stacks, pass --call-graph=fp to perf and pass -XX:+PreserveFramePointer to java.

  2. Copy perf.data and jitdump files, found in ~/.debug/jit/, to your host:

    scp perf.data ~/.debug/jit/<path_to_jitdump_file> hostmachine:
    
  3. Import perf.data.

  4. Analyze the imported capture by attaching the jitdump file that is transferred in step 2.

Tracing program execution

The steps that you must take to trace execution depends on the particular VM you are using:

  • Node.js and V8

    Run perf with the --perf-prof argument:

    perf record ... node --perf-prof ...
    

    See https://v8.dev/docs/linux-perf.

  • JVM

    Use the libperf-jvmti.so agent library which is provided in source form as part of the perf tools sources. See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=209045adc2bbdb2b315fa5539cec54d01cd3e7db.

    • Download kernel sources and install the JDK on your target.

    • Compile perf tools by running make, setting the JDIR flag to the location of the JDK:

      cd <KERNEL>/tools/perf
      make JDIR=<PATH_TO_JDK>
      
    • The resultant library is in <KERNEL>/tools/perf.

    • Run the java command with the -agentpath:<ABSOLUTE_PATH_TO_libperf_jvmti.so> argument:

      perf record ... java -agentpath:/home/user/linux-src/tools/perf/libperf_jvmti.so ...