1080*80 ad

How to Install Perf on CentOS 8

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:

  1. Update Your System: Before installing new software, always ensure your system is up to date.
    bash
    sudo dnf update -y
  2. Identify Your Kernel Version: The perf tool 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 like 4.18.0-305.el8.x86_64.
  3. Install Kernel Development Packages: The perf tool source code is distributed as part of the kernel source. To build the perf utility for your specific kernel, you need the corresponding kernel development headers and sources.
    This is the most critical step. You must install kernel-devel and potentially kernel-headers packages that precisely match the output of uname -r.
    bash
    sudo dnf install kernel-devel-$(uname -r) kernel-headers-$(uname -r)

    The $(uname -r) command ensures that dnf attempts 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 the devel and headers packages are available.
  4. Install the Perf Tool: Once the matching kernel development packages are in place, you can install the perf user-space tool. The perf tool is typically found within the perf package.
    bash
    sudo dnf install perf

    dnf should now be able to find and install the perf utility, linking it against the correct kernel headers and sources you just installed.
  5. Verify Installation: After the installation completes, you can verify that perf is 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 the ls command and provide performance statistics related to its execution, confirming perf is 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/

900*80 ad

      1080*80 ad