
Optimizing system performance is crucial for server stability and responsiveness. On Linux systems like CentOS 8, one of the most powerful and versatile tools for performance analysis is perf. Built directly into the Linux kernel, perf allows you to profile application and kernel activity, trace system calls, analyze CPU performance counters, and gain deep insights into what your system is doing.
Using perf effectively requires it to be properly installed and configured, often needing specific kernel development packages to match your running kernel version.
Why Use Perf?
- Deep Insight: Provides low-level details about CPU events, cache misses, branch predictions, and more.
- Profiling: Helps identify performance bottlenecks in your applications and the kernel itself.
- Tracing: Allows tracing system calls and kernel functions to understand execution flow.
- Event Monitoring: Can monitor hardware and software events crucial for performance tuning.
Installing Perf on CentOS 8
Installing perf on CentOS 8 is straightforward but requires attention to detail, particularly regarding kernel versions. Here are the steps:
- Update Your System: Before installing new software, always ensure your system is up to date.
bash
sudo dnf update -y
- Identify Your Kernel Version: The
perftool needs to be built against the same kernel version that is currently running on your system. Find your kernel version using:
bash
uname -r
Make a note of this exact version string. For example, it might look like4.18.0-305.el8.x86_64. - Install Kernel Development Packages: The
perftool source code is distributed as part of the kernel source. To build theperfutility for your specific kernel, you need the corresponding kernel development headers and sources.
This is the most critical step. You must installkernel-develand potentiallykernel-headerspackages that precisely match the output ofuname -r.
bash
sudo dnf install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
The$(uname -r)command ensures thatdnfattempts to install the packages for your currently running kernel version. If these specific versioned packages are not available in your configured repositories, you might need to update your system fully (sudo dnf update -y) and potentially reboot to a kernel version for which thedevelandheaderspackages are available. - Install the Perf Tool: Once the matching kernel development packages are in place, you can install the
perfuser-space tool. Theperftool is typically found within theperfpackage.
bash
sudo dnf install perf
dnfshould now be able to find and install theperfutility, linking it against the correct kernel headers and sources you just installed. - Verify Installation: After the installation completes, you can verify that
perfis installed and working by checking its version or running a simple command:
bash
perf --version
Or, run a basic performance command:
bash
perf stat ls
This should execute thelscommand and provide performance statistics related to its execution, confirmingperfis operational.
Troubleshooting Common Issues
The most frequent issue during perf installation is a mismatch between the running kernel version and the available kernel-devel package versions. If sudo dnf install kernel-devel-$(uname -r) fails, it means the development package for your exact running kernel version is not available in your repositories. The best solution is often to perform a full system update (sudo dnf update -y) and then reboot your system to load a newer kernel version for which the corresponding kernel-devel package is available. After rebooting, run uname -r again and repeat step 3 and 4.
With perf successfully installed, you now have a powerful utility at your fingertips to begin diagnosing performance issues and understanding the low-level behavior of your CentOS 8 system.
Source: https://kifarunix.com/installing-perf-performance-analysis-tool-on-centos-8/


