perf – Performance analysis tools for Linux

Please go ahead and help yourself by using your favorite os’s package manager to get it installed in the system.

I am gonna play with it bit more to show you how you can manipulate the kernel internal to get the actual picture. But why I said “actual picture“? Because many of userspace tool missed the little stuff underneath to give you a clear view what is going on inside the system.

Well, first thing first (assuming you get over the triviality of installing the tool!),we need to capture the internal state of a running command.How do we do that? But before that, look at the man pages of this tool,it is short and precise,so it won’t take you too much time go through it. It looks something like this if you do man perf on the terminal window.

perf_man_page2017-02-02-18-17-35

Then, you need to run perf –help to find out the options it provide and how to use it properly!

perf_help_2017-02-02-18-25-14

Well, now you need to do something (I mean some activity) and impose perf to get the internals for you.The easiest way,I think to run a command on one terminal and run the perf related command on others terminal window! just like below:

Running top -c on one screen window!

topc_2017-02-02-18-33-07

Another screen window I ran  sudo perf record –all-cpus and wait for few seconds and press CTRL-C to terminate the data capture. In this case, I am trying to capture the all CPU related stats, that is why I passed that argument to perf record.

ctrlctoperfrecord_2017-02-02-18-38-53

This captured data is saved in current directory with a name perf.data . Now , I am going to run other perf utility on this file to show . I ran perf script, which show traced data inside that file :

perf_script_2017-02-02-20-34-12

Okay, that’s a fragment of the output ,as I tried to capture the screenful only. But that is good enough to know what it is spitting out.

Then ,again I ran perf stat to find out the measure of any command pass along with it. The double dash (–) is for standard output.

perf_stat_good2017-02-02-21-04-55

For system profiling I ran perf top –all-cpus to get the enlisting of the current events.

perf_top_all_cpu2017-02-02-21-10-28

Fine, I need to know what is stored in previously captured perf.data file,kinda report of perf events. For that I ran perf report -i perf.data (this file sits on the directory ,where I am firing this command)

perf_report_2017-02-02-21-15-51

Now, I am gonna capture some memory events in the perf.data file and then display it in below two screenshots. For the first screenshot, I ran perf mem record

perf_mem_record2017-02-02-21-24-37

 

And now you can see below the memory get consumed or distributed.

perf_report_mem_load2017-02-02-21-28-03

Next, I ran perf annotate , which basically show the codes of the along with assembly code ,next two screenshots are for that..

perf_annotate_2017-02-03-07-54-15

And look at how firefox’s code getting disassembled!

perf_annotate2_2017-02-03-07-55-10

How to enlist the events captured by perf ? Simple, run perf evlist

perf_evlist_2017-02-03-08-02-03

Cool, now measuring the kernel memory properties, we need to run perf kmem record and perf kmem stat …..I have captured it in a single screenshot.

perf_kmem_record_stat_2017-02-03-08-06-11

 

If we want to know any specific tool system behaviour on load time with some nice stat and graph ,then perf timechart is your friend. I tried to capture it in below screenshot, I ran perf timechart record top

perf_timechar_record_2017-02-03-08-14-52

Now I ran perf timechart and it saves the captured state in a svg file ..

perf_timechart_svg2017-02-03-08-21-14

How to see it? Simply open the file in the browser and you can see something similar like this :

timechart12017-02-03-08-55-00

And this :

timechart22017-02-03-08-55-51

Well, I believe this is enough to gives you heads up about performance measurement.If you are still interested to dig deep and know more about it. Please follow  Branden Gregg of Netflix as he is maintaining and doing the bulk of  work related to it.

Hope this helps.

References:

https://perf.wiki.kernel.org/index.php/Main_Page

https://github.com/brendangregg/perf-tools

http://www.brendangregg.com/perf.html

http://lacasa.uah.edu/portal/Upload/tutorials/perf.tool/PerfTool.pdf

Advertisements