Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 11. Profiling CPU usage in real time with perf top
You can use the perf top command to measure CPU usage of different functions in real time.
11.1. The purpose of perf top Copier lienLien copié sur presse-papiers!
The perf top command performs real-time system profiling and functions similarly to the top utility. While top monitors process CPU usage, perf top displays CPU time by specific function. In its default state, perf top informs you about functions being used across all CPUs in both the user-space and the kernel-space. To use perf top, you need root access.
11.2. Profiling CPU usage with perf top Copier lienLien copié sur presse-papiers!
You can use perf top to monitor real-time CPU usage and identify functions consuming the most processing time.
Prerequisites
-
You have the
perfuser space tool installed. For more information, see Installing perf. - You have root access.
Procedure
Start the perf top monitoring interface:
# perf topThe monitoring interface looks similar to the following: Samples: 8K of event 'cycles', 2000 Hz, Event count (approx.): 4579432780 lost: 0/0 drop: 0/0 Overhead Shared Object Symbol 2.20% [kernel] [k] do_syscall_64 2.17% [kernel] [k] module_get_kallsym 1.49% [kernel] [k] copy_user_enhanced_fast_string 1.37% libpthread-2.29.so [.] pthread_mutex_lock 1.31% [unknown] [.] 0000000000000000 1.07% [kernel] [k] psi_task_change 1.04% [kernel] [k] switch_mm_irqs_off 0.94% [kernel] [k] fget 0.74% [kernel] [k] entry_SYSCALL_64 0.69% [kernel] [k] syscall_return_via_sysret 0.69% libxul.so [.] 0x000000000113f9b0 0.67% [kernel] [k] kallsyms_expand_symbol.constprop.0 0.65% firefox [.] moz_xmalloc 0.65% libpthread-2.29.so [.] __pthread_mutex_unlock_usercnt 0.60% firefox [.] free 0.60% libxul.so [.] 0x000000000241d1cd 0.60% [kernel] [k] do_sys_poll 0.58% [kernel] [k] menu_select 0.56% [kernel] [k] _raw_spin_lock_irqsave 0.55% perf [.] 0x00000000002ae0f3In this example, the kernel function
do_syscall_64is using the most CPU time.
11.3. Perf output and symbol resolution Copier lienLien copié sur presse-papiers!
The perf top monitoring interface provides a real-time view of CPU usage and function activity. Understanding its output helps identify performance bottlenecks and optimizes system behavior.
- Key columns in perf top output
- The interface displays several following columns:
- Overhead
-
Shows the percentage of CPU time consumed by a given function. This helps pinpoint the most
resource-intensiveoperations. - Shared Object
- Indicates the name of the program or library where the function resides.
- Symbol
Displays the name of the function or symbol.
- Functions running in kernel space are marked with [k].
- Functions running in user space are marked with [.].
- Causes of unresolved symbols in perf output
For kernel functions,
perfuses the information from the/proc/kallsymsfile to map the samples to their respective function names or symbols. For functions executed in the user space, however, you might see raw function addresses because the binary is stripped.This information can be included by installing the corresponding debuginfo package or by compiling the application with debugging enabled, such as using the
-goption ingcc. Once the necessary debug information is available,perfcan accurately map sampled addresses to human-readable function names during reporting.NoteAfter making debug information available, it is not necessary to re-run the
perf recordcommand. Running theperf reportcommand again will reflect the resolved symbols.
11.4. Enabling debug and source repositories Copier lienLien copié sur presse-papiers!
To access essential debugging data for system components, enable debug and source repositories. RHEL disables these by default to save space. Enable them to install debuginfo packages required for performance measurement and deep system troubleshooting.
Procedure
Enable the source and debug information package channels:
# subscription-manager repos --enable rhel-10-for-$(uname -m)-baseos-debug-rpms# subscription-manager repos --enable rhel-10-for-$(uname -m)-baseos-source-rpms# subscription-manager repos --enable rhel-10-for-$(uname -m)-appstream-debug-rpms# subscription-manager repos --enable rhel-10-for-$(uname -m)-appstream-source-rpmsThe
$(uname -m)part is automatically replaced with a matching value for architecture of your system:Expand Table 11.1. Architecture name mappings Architecture name Value 64-bit Intel and AMD
x86_64
64-bit ARM
aarch64
IBM POWER
ppc64le
64-bit IBM Z
s390x
11.5. Getting debuginfo packages for an application or library by using GDB Copier lienLien copié sur presse-papiers!
When you debug an issue and the installed package lacks the required debugging information, the GNU Debugger detects the missing information. It then suggests commands to install the corresponding debug packages.
Prerequisites
- The application or library you want to debug must be installed on the system.
-
GDB and the
debuginfo-installtool must be installed on the system. For details, see Setting up to debug applications. -
Repositories providing
debuginfoanddebugsourcepackages must be configured and enabled on the system. For details, see Enabling debug and source repositories.
Procedure
Start GDB attached to the application or library you want to debug. GDB automatically recognizes missing debugging information and suggests a command to run.
$ gdb -q /bin/lsReading symbols from /bin/ls...Reading symbols from .gnu_debugdata for /usr/bin/ls...(no debugging symbols found)...done. (no debugging symbols found)...done. Missing separate debuginfos, use: dnf debuginfo-install coreutils-9.5-6.el10.x86_64 (gdb)To exit GDB, type q and confirm with Enter.
(gdb) qRun the command suggested by GDB to install the required
debuginfopackages:# dnf debuginfo-install coreutils-9.5-6.el10.x86_64The dnf package management tool provides a summary of the changes, asks for confirmation and once you confirm, downloads and installs all the necessary files. In case GDB is not able to suggest the
debuginfopackage, follow the procedure described in Gettingdebuginfopackages for an application or library manually.