To install, use:
sudo apt-get install linux-tools
and this installs the perf, perf-stat, perf-top, perf-record, perf-report and perf-list tools.
The author of perf, Ingo Molnar has written some basic instructions on driving perf in the tools/perf/Documentation/example.txt file. They should give one a feel of how to drive these tools.
For example, to examine google-chrome:
perf record google-chrome
... run a test and then exit, and then generate a summary of activity:
One can examine specific events in the system too. To get a list of available events use:
For example, to measure CPU cycles, number of instructions, context switches and kmallocs on google-chrome one uses:
perf stat -e cpu-cycles -e instructions -e context-switches -e kmem:kmalloc google-chrome
Performance counter stats for 'google-chrome':
15576472832 cycles # 0.000 M/sec
13466330277 instructions # 0.865 IPC
40791 context-switches # 0.000 M/sec
38602 kmem:kmalloc # 0.000 M/sec
18.062301718 seconds time elapsed
One more quick example, this time we record a call-graph (stack chain/backtrace) of the dd command:
perf record -g dd if=/dev/zero of=/dev/null bs=1M count=4096
and get the call graph using:
# Samples: 12584 # # Overhead Command Shared Object Symbol # ........ ............... ............................... ...... # 95.96% dd [kernel] [k] __clear_user | |--99.69%-- read_zero | vfs_read | sys_read | system_call_fastpath | __read --0.31%-- [...]
1.37% dd [kernel] [k] read_zero 0.87% dd [kernel] [k] _cond_resched | |--50.91%-- read_zero | vfs_read | sys_read | system_call_fastpath | __read
I recommend reading Ingo's example.txt and playing around with this tool. It is very powerful and allows one to drill down and examine system performance right down to the instruction level.