163

How do I install the perf monitoring tool?

samarasa
  • 4,971

13 Answers13

160

On Ubuntu I had to install three packages:

apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`
notpeter
  • 1,729
109

The perf utility can be found in the linux-tools package.

abcd
  • 443
43

Make sure you are installing this tool for the right Kernel release. If you just type:

sudo apt-get install linux-tools

It will install it for the latest Linux release in your machine and in case you are booting a previous version (say for stability reason), it will err. In my case it installed for .45 instead of .43 and I had to use the following command to install it:

sudo apt-get install linux-tools-3.2.0.43

You can find your Kernel release by typing : uname -r

To make sure it's working right you can try this: perf record /bin/ls

notpeter
  • 1,729
Mona Jalal
  • 4,695
  • 21
  • 74
  • 102
43

To get the latest version of perf irrespective of the kernel version (perf version is independent of the kernel version):

git clone --depth 1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux/tools/perf
make
cp perf /usr/bin

perf --version to check the current version

bodha
  • 531
14

Ubuntu:

sudo apt install linux-tools-common

https://packages.ubuntu.com/eoan/linux-tools-common

Debian:

sudo apt install linux-perf

https://packages.debian.org/buster/linux-perf

8

In 14.04, the linux-tools package does not exist unqualified:

$ sudo apt-get install linux-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package linux-tools is a virtual package provided by:
  linux-tools-virtual 3.13.0.36.43
  linux-tools-lowlatency 3.13.0.36.43
  linux-tools-generic-lts-trusty 3.13.0.36.43
  linux-tools-generic-lts-saucy 3.13.0.36.43
  linux-tools-generic 3.13.0.36.43
You should explicitly select one to install.

E: Package 'linux-tools' has no installation candidate

Instead, you can install one of the packages listed, depending upon the kernel you have installed. Most users will want linux-tools-generic.

Drew Noakes
  • 5,878
7

On ubuntu "perf" is a shell script that calls a kernel specific perf binary.

But that's not actually needed, perf is compatible. Just remove the wrapper from /usr/bin and copy any of the perf binaries from ./lib/linux-tools* to it.

prabha101
  • 101
4

I installed Linux 3.17.2 on my machine and tried

sudo apt-get install linux-tools-3.17.2

it showed that linux-tools is not present. In this case, download the required linux kernel version, go to linux->tools->perf :

cd linux/tools/perf

and then run make command :

make

and then run make install command:

make install

and then reboot. You just installed perf manually.

muru
  • 207,228
3

Running the following two commands will do it!

sudo apt-get install linux-tools-common 
sudo apt-get install linux-tools
Aditya
  • 13,616
2

Here's how it worked for me On Ubuntu 18.04:

After Command 'perf' not found, it suggested to install with sudo apt install linux-tools-common. Doing so and trying to run perf afterward still resulted in:

WARNING: perf not found for kernel 4.15.0-39

  You may need to install the following packages for this specific kernel:
    linux-tools-4.15.0-39-generic
    linux-cloud-tools-4.15.0-39-generic

  You may also want to install one of the following packages to keep up to date:
    linux-tools-generic
    linux-cloud-tools-generic

I decided for sudo apt-get install linux-tools-generic and this was enough.

In case you run into permission-error when trying to use perf as non-root, look here:

Run perf without root-rights

Darkonaut
  • 121
1

For debian 9.11 (Stretch)

sudo apt-get install linux-perf-4.9

https://packages.debian.org/stretch/linux-perf

You might need to do an

apt-get update

before.

ximbal
  • 111
0

I tried a solution from another stackoverflow post

TLDR: You will need to checkout the repo from https://github.com/microsoft/WSL2-Linux-Kernel.git yourself with the latest commit and run make command.

This solution worked for me: Biswapriyo

Edit: I tried it for WSL2

-1
sudo apt-get install linux-tools-virtual