Perf tool

This application can be used to understand how to use the Perf tool.

Requirements

The Perf tool is currently implemented only for RISC-V and x86_64 architectures.

Usage example

  • Build and run the sample with:

    west build -b qemu_riscv64 samples/subsys/profiling/perf
    west build -t run
    
  • After the sample has started, enter the shell command:

    uart:~$ perf record <duration> <frequency>
    

    This command will start a timer for duration milliseconds at frequency Hz.

  • Wait for the completion message perf done!, or perf buf override! if the perf buffer size is smaller than required.

  • Print the samples captured by perf in the terminal with the shell command:

    uart:~$ perf printbuf
    

    The output should be similar to:

    Perf buf length 2046
    0000000000000004
    00000000001056b2
    0000000000108192
    000000000010052f
    0000000000000000
      ....
    000000000010052f
    0000000000000000
    
  • Copy the output into a file, for example perf_buf.

  • Generate graph.svg with scripts/profiling/stackcollapse.py and FlameGraph:

    python scripts/perf/stackcollapse.py perf_buf build/zephyr/zephyr.elf | <flamegraph_dir_path>/flamegraph.pl > graph.svg
    

Graph example

graph example