How to Compile Perf with all Features on?
Want perf with all the features. Here's how to compile it yourself with all features enabled.
The perf profile is included in most Linux distributions. You can find it easily in the repositories. It comes with basic features enabled, which are perfectly suitable for most scenarios.
Sometimes you need it with all the bells and whistles on. For instance, I needed to use a Python script to analyze the function execution times on a system that did not provide perf with Python support. The only way was to recompile perf from the source.
Luckily, compiling perf from the sources is fairly straightforward.
All of the examples are run within Ubuntu 22.04 (
ubuntu:22.04) docker image.
First, we need to get the source code for perf. It is distributed with the kernel so you can get it from https://mirrors.edge.kernel.org/pub/linux/kernel/.
Don't be intimated by the kernel. Unsurprisingly, it is very well-maintained and does not require any fancy tools to build.
The safest way is to match the version number to the kernel version of the system under test. If you are only after the latest features, then go with the latest version.
Extract the source package and see what is required
I opted in using the latest kernel version 6.0.9. The next task is to fetch and extract the sources.
Fetch the sources
curl -o linux-source.tar.gz https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-6.0.9.tar.gz
Extract the sources
tar xvf linux-source.tar.gz
Move to the perf tool base directory
If you have not yet installed basic tools for building C applications, then run the following minimal setup to get the tools to build perf
sudo apt install make gcc flex bison
Now, you can simply run
make to build perf
The build configuration will print out the supported features. Notice how we are missing a lot of things. This is because our minimal environment does not provide most of the libraries required for these features.
I'll go through one-by-one the features and required library to enable the support
Install everything in a single command
sudo apt install libdwarf-dev libdw-dev binutils-dev libcap-dev libelf-dev libnuma-dev libperf-dev python2 python2-dev python-setuptools libssl-dev libunwind-dev libdwarf-dev libunwindw zlib1g-dev liblzma-dev libaio-dev
make again should show you all the features enabled
Getting perf for your favorite distribution is easy. Just fetch it from the repo. Getting all the features requires some work. But as you can see it's not that hard. As long as you are not intimated by the kernel sources, rebuilding the tools is actually quite a straightforward process.