Este contenido no está disponible en el idioma seleccionado.
Chapter 19. 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.
Prerequisites
-
You have the
perfuser space tool installed as described in Installing perf.
19.1. The purpose of perf top Copiar enlaceEnlace copiado en el portapapeles!
The perf top command is used for real time system profiling and functions similarly to the top utility. However, where the top utility generally shows you how much CPU time a given process or thread is using, perf top shows you how much CPU time each specific function uses. In its default state, perf top tells 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.
19.2. Profiling CPU usage with perf top Copiar enlaceEnlace copiado en el portapapeles!
This procedure activates perf top and profiles CPU usage in real time.
Prerequisites
-
You have the
perfuser space tool installed as described in Installing perf. - You have root access
Procedure
Start the
perf topmonitoring interface:perf top
# perf topCopy to Clipboard Copied! Toggle word wrap Toggle overflow The monitoring interface looks similar to the following:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, the kernel function
do_syscall_64is using the most CPU time.
19.3. Interpretation of perf top output Copiar enlaceEnlace copiado en el portapapeles!
The perf top monitoring interface displays the data in several columns:
- The "Overhead" column
- Displays the percent of CPU a given function is using.
- The "Shared Object" column
- Displays name of the program or library which is using the function.
- The "Symbol" column
-
Displays the function name or symbol. Functions executed in the kernel-space are identified by
[k]and functions executed in the user-space are identified by[.].
19.4. Why perf displays some function names as raw function addresses Copiar enlaceEnlace copiado en el portapapeles!
For kernel functions, perf uses the information from the /proc/kallsyms file 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.
The debuginfo package of the executable must be installed or, if the executable is a locally developed application, the application must be compiled with debugging information turned on (the -g option in GCC) to display the function names or symbols in such a situation.
It is not necessary to re-run the perf record command after installing the debuginfo associated with an executable. Simply re-run the perf report command.
19.5. Enabling debug and source repositories Copiar enlaceEnlace copiado en el portapapeles!
A standard installation of Red Hat Enterprise Linux does not enable the debug and source repositories. These repositories contain information needed to debug the system components and measure their performance.
Procedure
Enable the source and debug information package channels:
subscription-manager repos --enable rhel-9-for-$(uname -i)-baseos-debug-rpms subscription-manager repos --enable rhel-9-for-$(uname -i)-baseos-source-rpms subscription-manager repos --enable rhel-9-for-$(uname -i)-appstream-debug-rpms subscription-manager repos --enable rhel-9-for-$(uname -i)-appstream-source-rpms
# subscription-manager repos --enable rhel-9-for-$(uname -i)-baseos-debug-rpms # subscription-manager repos --enable rhel-9-for-$(uname -i)-baseos-source-rpms # subscription-manager repos --enable rhel-9-for-$(uname -i)-appstream-debug-rpms # subscription-manager repos --enable rhel-9-for-$(uname -i)-appstream-source-rpmsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
$(uname -i)part is automatically replaced with a matching value for architecture of your system:Expand Architecture name Value 64-bit Intel and AMD
x86_64
64-bit ARM
aarch64
IBM POWER
ppc64le
64-bit IBM Z
s390x
19.6. Getting debuginfo packages for an application or library using GDB Copiar enlaceEnlace copiado en el portapapeles!
Debugging information is required to debug code. For code that is installed from a package, the GNU Debugger (GDB) automatically recognizes missing debug information, resolves the package name and provides concrete advice on how to get the package.
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/ls
$ gdb -q /bin/ls Reading 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-8.30-6.el8.x86_64 (gdb)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Exit GDB: type q and confirm with Enter.
(gdb) q
(gdb) qCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the command suggested by GDB to install the required
debuginfopackages:dnf debuginfo-install coreutils-8.30-6.el8.x86_64
# dnf debuginfo-install coreutils-8.30-6.el8.x86_64Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
dnfpackage 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 Getting debuginfo packages for an application or library manually.