What is Perf?

Perf or perf-event is a Linux profiler and is part of the Linux Kernel which can help you solve advanced performance and troubleshooting functions. It covers hardware level (CPU/PMU, Performance Monitoring Unit) features and software features (software counters, tracepoints) as well.

Install on Ubuntu

If perf has not installed on the system

$ perf
WARNING: perf not found for kernel 5.4.0-109

  You may need to install the following packages for this specific kernel:
    linux-tools-5.4.0-109-generic
    linux-cloud-tools-5.4.0-109-generic

  You may also want to install one of the following packages to keep up to date:
    linux-tools-generic
    linux-cloud-tools-generic
$

The perf is part of linux-tools-generic package on Ubuntu:

$ sudo apt install linux-tools-generic
The following additional packages will be installed:
  linux-tools-5.4.0-109 linux-tools-5.4.0-109-generic
The following NEW packages will be installed:
  linux-tools-5.4.0-109 linux-tools-5.4.0-109-generic linux-tools-generic
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,597 kB of archives.
After this operation, 25.9 MB of additional disk space will be used.
Do you want to continue? [Y/n]
....

$ perf -v
perf version 5.4.178
$

There was a warning when running the perf on the terminal

“Cannot load tips.txt file, please install perf!”

To solve this warning: copy tips.txt from https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/tips.txt to /usr/share/doc/perf-tip/tips.txt

Perf with GUI

hotspot: a standalone GUI for performance data

Other profilers

References

https://www.brendangregg.com/perf.html

http://wiki.csie.ncku.edu.tw/embedded/perf-tutorial

https://blog.csdn.net/z1026544682/article/details/115329534

https://xiaoyanzhuo.github.io/2019/01/18/Perf-Tool.html