Getting started with the perf command
The perf command is used as a primary interface to the Linux kernel performance monitoring capabilities and can record CPU performance counters and trace points. The perf command can report combinations of performance counters as performance metrics and can inject small scripts (BPF scripts) into the kernel to process this data in real time. The perf command is included with all major Linux distributions. For more information, see perf: Linux profiling with performance counters.
Examples
- To record the CPU cycles for a single command, run the following
command:
$ perf record <command>
- To record the CPU cycles for the entire system, for 10 seconds, run the following
command:
$ perf record -a sleep 10
- To display the results of the recording, run the following
command:
$ perf report
- To display a periodically updated snapshot of the application functions that are consuming the
CPU cycles, run the following command:
$ perf top
Migrating from OProfile to perf
OProfile is deprecated in Red Hat® Enterprise Linux® (RHEL) 8.0 in favor of the perf command. Linux perf command is similar to OProfile in features and usability.
For more information on how to migrate from OProfile to the perf command, see Migrating from OProfile to perf, and beyond.