perf is a Linux tool that measures performance-related data in a variety of ways, including hardware performance counters and tracepoints. It provides an interface for analyzing the performance of the operating system, applications, and other system components.
The perf tool is built into the Linux kernel, and it can be used to collect and analyze performance data in a number of ways. For example, it can be used to count the number of CPU cycles consumed by a particular process, or to monitor memory accesses and cache misses. It can also be used to trace events in the system, such as function calls and context switches.
One of the main advantages of perf is that it provides a unified interface for accessing performance data, making it easier for developers and performance engineers to work with performance-related data. Additionally, perf is extensible, meaning that it can be extended to support new performance counters and tracepoints as they become available.
If you encounter the below error while running the command perf:
perf: command not found
you may try installing the below package as per your choice of distribution:
|Debian||apt-get install perf|
|Ubuntu||apt-get install perf|
|Arch Linux||pacman -S perf|
|Kali Linux||apt-get install perf|
|CentOS||yum install perf|
|Fedora||dnf install perf|
|Raspbian||apt-get install perf|
perf Command Examples
1. Display basic performance counter stats for a command:
# perf stat gcc hello.c
2. Display system-wide real-time performance counter profile:
# sudo perf top
3. Run a command and record its profile into `perf.data`:
# sudo perf record command
4. Record the profile of an existing process into `perf.data`:
# sudo perf record -p pid
5. Read `perf.data` (created by `perf record`) and display the profile:
# sudo perf report
Overall, perf is a valuable tool for performance analysis and optimization on Linux systems, and it is widely used by developers and performance engineers to understand the behavior of their systems and to identify performance bottlenecks.