Este contenido no está disponible en el idioma seleccionado.
Chapter 22. Investigating busy CPUs with perf
When investigating performance issues on a system, you can use the perf tool to identify and monitor the busiest CPUs in order to focus your efforts.
22.1. Displaying which CPU events were counted on with perf stat Copiar enlaceEnlace copiado en el portapapeles!
You can use perf stat to display which CPU events were counted on by disabling CPU count aggregation. You must count events in system-wide mode by using the -a flag in order to use this functionality.
Prerequisites
-
You have the
perfuser space tool installed as described in Installing perf.
Procedure
Count the events with CPU count aggregation disabled:
perf stat -a -A sleep seconds
# perf stat -a -A sleep secondsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous example displays counts of a default set of common hardware and software events recorded over a time period of
secondsseconds, as dictated by using thesleepcommand, over each individual CPU in ascending order, starting withCPU0. As such, it may be useful to specify an event such as cycles:perf stat -a -A -e cycles sleep seconds
# perf stat -a -A -e cycles sleep secondsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
22.2. Displaying which CPU samples were taken on with perf report Copiar enlaceEnlace copiado en el portapapeles!
The perf record command samples performance data and stores this data in a perf.data file which can be read with the perf report command. The perf record command always records which CPU samples were taken on. You can configure perf report to display this information.
Prerequisites
-
You have the
perfuser space tool installed as described in Installing perf. -
There is a
perf.datafile created withperf recordin the current directory. If theperf.datafile was created with root access, you need to runperf reportwith root access too.
Procedure
Display the contents of the
perf.datafile for further analysis while sorting by CPU:perf report --sort cpu
# perf report --sort cpuCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can sort by CPU and command to display more detailed information about where CPU time is being spent:
perf report --sort cpu,comm
# perf report --sort cpu,commCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example will list commands from all monitored CPUs by total overhead in descending order of overhead usage and identify the CPU the command was executed on.
22.3. Displaying specific CPUs during profiling with perf top Copiar enlaceEnlace copiado en el portapapeles!
You can configure perf top to display specific CPUs and their relative usage while profiling your system in real time.
Prerequisites
-
You have the
perfuser space tool installed as described in Installing perf.
Procedure
Start the
perf topinterface while sorting by CPU:perf top --sort cpu
# perf top --sort cpuCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example will list CPUs and their respective overhead in descending order of overhead usage in real time.
You can sort by CPU and command for more detailed information of where CPU time is being spent:
perf top --sort cpu,comm
# perf top --sort cpu,commCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example will list commands by total overhead in descending order of overhead usage and identify the CPU the command was executed on in real time.
22.4. Monitoring specific CPUs with perf record and perf report Copiar enlaceEnlace copiado en el portapapeles!
You can configure perf record to only sample specific CPUs of interest and analyze the generated perf.data file with perf report for further analysis.
Prerequisites
-
You have the
perfuser space tool installed as described in Installing perf.
Procedure
Sample and record the performance data in the specific CPU’s, generating a
perf.datafile:Using a comma separated list of CPUs:
perf record -C 0,1 sleep seconds
# perf record -C 0,1 sleep secondsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous example samples and records data in CPUs 0 and 1 for a period of
secondsseconds as dictated by the use of thesleepcommand.Using a range of CPUs:
perf record -C 0-2 sleep seconds
# perf record -C 0-2 sleep secondsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The previous example samples and records data in all CPUs from CPU 0 to 2 for a period of
secondsseconds as dictated by the use of thesleepcommand.
Display the contents of the
perf.datafile for further analysis:perf report
# perf reportCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example will display the contents of
perf.data. If you are monitoring several CPUs and want to know which CPU data was sampled on, see Displaying which CPU samples were taken on with perf report.