Main Page

From Perf Wiki
(Difference between revisions)
Jump to: navigation, search
Line 69: Line 69:
** [[Montecito | Intel(TM) Itanium(TM) 2 PMU]]
** [[Montecito | Intel(TM) Itanium(TM) 2 PMU]]
* Performance Counters for Linux
* Performance Counters for Linux
** [[PCLstruct| PCL core kernel data structures]]
** [[PCL internals | PCL core kernel internals]]
** [[PCL internals | PCL core kernel internals]]
** [[perf internals | perf tool internals]]
** [[perf internals | perf tool internals]]

Revision as of 19:46, 24 September 2009

...More than just counters...

Performance Counters for Linux Wiki

This is the wiki page for the perfcounters subsystem in Linux.

Performance counters are special hardware registers available on most modern CPUs. These registers count the number of certain types of hw events: such as instructions executed, cache-misses suffered, or branches mispredicted - without slowing down the kernel or applications. These registers can also trigger interrupts when a threshold number of events have passed - and can thus be used to profile the code that runs on that CPU.

The Linux Performance Counter subsystem provides rich abstractions over these hardware capabilities. It provides per task, per CPU and per-workload counters, counter groups, and it provides sampling capabilities on top of those - and more.

It also provides abstraction for 'software events' - such as minor/major page faults, task migrations, task context-switches and tracepoints.

There is a new tool ('perf') that makes full use of this new kernel subsystem. It can be used to optimize, validate and measure applications, workloads or the full system.

'perf' is hosted in the upstream kernel repository and can be found under: tools/perf/


Getting Started

Once you have installed 'perf' on your system, the simplest way to start profiling an userspace program is to use the "perf record" and "perf report" command as follows:

$ perf record -f -- git gc
Counting objects: 1283571, done.
Compressing objects: 100% (206724/206724), done.
Writing objects: 100% (1283571/1283571), done.
Total 1283571 (delta 1070675), reused 1281443 (delta 1068566)
[ perf record: Captured and wrote 31.054 MB (~1356768 samples) ]
$ perf report --sort comm,dso,symbol | head -10
# Samples: 1355726
# Overhead          Command                            Shared Object  Symbol
# ........  ...............  .......................................  ......
    31.53%              git  /usr/bin/git                             [.] 0x0000000009804f
    13.41%        git-prune  /usr/bin/git-prune                       [.] 0x000000000ad06d
    10.05%              git  /lib/tls/i686/cmov/        [.] _nl_make_l10nflist
     5.36%        git-prune  /usr/lib/                 [.] 0x00000000009d51
     4.48%              git  /lib/tls/i686/cmov/        [.] memcpy

For more examples of how 'perf' can be used see perf examples.

TODO list

Perf tools

  • Factorize the multidimensional sorting between perf report and annotate (will be used by perf trace)
  • Implement a perf cmp (profile comparison between two
  • Implement a perf view (GUI)
  • Enhance perf trace:
    • Handle the cpu field
    • Handle the timestamp
    • Use the in-perf ip -> symbol resolving
    • Use the in-perf pid -> cmdline resolving
    • Implement multidimensional sorting by field name



    • in order to get the documentation installed you'll need these packages:
    • I used on RHEL5: yum install asciidoc xmlto
      • asciidoc
      • tetex-fonts
      • tetex-dvips
      • dialog
      • tetex
      • tetex-latex
      • xmltex
      • passivetex
      • w3m
      • xmlto
    • Don't forget to go into tools/perf and do 'make install-man'
    • without doing the above, you won't be able to run 'perf help <command>'
Personal tools