How to install Perf Tool on Cent OS

If you are interested in knowing the secret behind your OS like performance counter then Perf is the best choice to deal with. It will help you analyse the activity of your disk, why L2  cache misses are happening and many other things.

You will learn basics of Perf and how it can be used to get various data about performance of your system.

Installing Perf

Yum install perf gawk

We can test the usage of Perf by simply executing the command below to check the disk i/o with its report as given below:

sudo perf record -e block:block_rq_issue -ag

It will record all your data,

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.908 MB (4 samples) ]

Just press ctrl-C to stop it after couple of seconds. then execute the command given below

sudo perf report

and you will get the report like given below




You can see the + sing to expand the see it in detail.

Another example would be to check cache misses.

The command below will record cup level 1 data cache misses.

sudo perf record -e L1-dcache-load-misses -c 10000 -ag — sleep 5

gives output like below
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.953 MB ]

Similarly, we can see the report executing the command

sudo perf report -f


So far we have recorded and analyzed the record and it can also be used in real time to record and see output immediately which is covered below.

Real time Scripts

Perf is very powerful tool however there isn’t the best documented tool as there is frequent changes to underlying framework. So we will be using suite of scrupts from github for easier performance counting in real time.

Execute the command given below to clone them

cd git clone –depth 1

cd perf-tools

Now we can run simple scripts to check the hidden status of our linux system.

sudo ./iolatency


The above script gave us latency of the disk as histogram . You can run as long as you want to check the result.


The above script uses perf to get cache misses every second and prints it to a line.


Some non-realtime scripts


It isn’t real time like above, You have to press ctrl-C to stop counting and you get output.

If you want to track call of specific process you first need to get its PID with command


./syscount -cp 5184
Tracing PID 5184… Ctrl-C to end.
poll 1
read 1
write 1
times 2
nanosleep 3
rt_sigaction 3
semop 4
rt_sigprocmask 6



Rajkishor Maharjan has written 17 articles