Posted on

Install Perf

On newer kernels

If you are using container, making sure that you have kernel relative new, for example, 5.4. It is tested that installing on kernel 3.10 may not work.

apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`

For older kernels

You can compile the perf binary directly from the linux kernel source code and it should be universally available on all Linux distros so long as the kernel version supports it.

git clone --depth=1 https://github.com/torvalds/linux.git
cd linux/tools/perf
apt-get install flex bison
make
cp perf /usr/bin/
perf -v       # verify the installation

Flame Graph

1. Capture Stacks

The sleep 60 can be replaced by your own commands.

$ perf record -F 99 -a -g -- sleep 60
$ perf script > out.perf

2. Fold stacks

To fold the call stacks, we have to clone the brendangregg/FlameGraph in advance and use one of the tools in side it.

$ ./stackcollapse-perf.pl out.perf > out.folded

3. Render a svg with flamegraph.pl

$ ./flamegraph.pl out.folded > out.svg

References

  1. Linux perf Examples
  2. brendangregg/FlameGraph

Leave a Reply

Your email address will not be published. Required fields are marked *