perf (sometimes called perf_events or perf tools, originally Performance Counters for Linux, PCL) is a
performance analyzing tool in
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
, available from
Linux kernel
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
version 2.6.31 in 2009.
Userspace
A modern computer operating system usually uses virtual memory to provide separate address spaces or regions of a single address space, called user space and kernel space. This separation primarily provides memory protection and hardware prote ...
controlling utility, named
perf
, is accessed from the
command line
A command-line interface (CLI) is a means of interacting with software via command (computing), commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user ...
and provides a number of
subcommands; it is capable of statistical profiling of the entire system (both kernel and
userland code).
It supports
hardware performance counters,
tracepoints, software performance counters (e.g. hrtimer), and dynamic probes (for example,
kprobes or uprobes).
In 2012, two
IBM
International Business Machines Corporation (using the trademark IBM), nicknamed Big Blue, is an American Multinational corporation, multinational technology company headquartered in Armonk, New York, and present in over 175 countries. It is ...
engineers recognized perf (along with
OProfile) as one of the two most commonly used
performance counter profiling tools on Linux.
Implementation
The interface between the perf utility and the kernel consists of only one
syscall and is done via a
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically h ...
and a mapped memory region.
[Roberto A. Vitillo ( LBNL)]
PERFORMANCE TOOLS DEVELOPMENTS
16 June 2011, presentation from "Future computing in particle physics" conference Unlike
LTTng
LTTng (Linux Trace Toolkit: next generation) is a system software package for correlated tracing of the Linux kernel, applications and libraries. The project was originated by Mathieu Desnoyers with an initial release in 2005. Its predecessor is ...
or older versions of
oprofile, no service
daemons are needed, as most functionality is integrated into the kernel. The perf utility dumps raw data from the mapped buffer to disk when the buffer becomes filled up. According to R. Vitillo (
LBNL), profiling performed by perf involves a very low overhead.
, architectures that provide support for hardware counters include
x86
x86 (also known as 80x86 or the 8086 family) is a family of complex instruction set computer (CISC) instruction set architectures initially developed by Intel, based on the 8086 microprocessor and its 8-bit-external-bus variant, the 8088. Th ...
,
PowerPC
PowerPC (with the backronym Performance Optimization With Enhanced RISC – Performance Computing, sometimes abbreviated as PPC) is a reduced instruction set computer (RISC) instruction set architecture (ISA) created by the 1991 Apple Inc., App ...
64,
UltraSPARC
The UltraSPARC is a microprocessor developed by Sun Microsystems and fabricated by Texas Instruments, introduced in mid-1995. It is the first microprocessor from Sun to implement the 64-bit SPARC V9 instruction set architecture (ISA). Marc Tre ...
(
III and
IV),
ARM (v5, v6, v7,
Cortex-A8 and
-A9),
Alpha
Alpha (uppercase , lowercase ) is the first letter of the Greek alphabet. In the system of Greek numerals, it has a value of one. Alpha is derived from the Phoenician letter ''aleph'' , whose name comes from the West Semitic word for ' ...
EV56 and
SuperH
SuperH (or SH) is a 32-bit reduced instruction set computing (RISC) instruction set architecture (ISA) developed by Hitachi and currently produced by Renesas. It is implemented by microcontrollers and microprocessors for embedded systems.
At the ...
.
[Arnaldo Carvalho de Melo]
The New Linux ’perf’ tools
presentation from Linux Kongress, September, 2010 Usage of Last Branch Records, a
branch tracing implementation available in
Intel
Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California, and Delaware General Corporation Law, incorporated in Delaware. Intel designs, manufactures, and sells computer compo ...
CPUs since
Pentium 4
Pentium 4 is a series of single-core central processing unit, CPUs for Desktop computer, desktops, laptops and entry-level Server (computing), servers manufactured by Intel. The processors were shipped from November 20, 2000 until August 8, 20 ...
, is available as a patch.
Since version 3.14 of the
Linux kernel mainline, released on 31 March 2014, perf also supports ''running average power limit'' (RAPL) for power consumption measurements, which is available as a feature of certain Intel CPUs.
Perf is natively supported in many popular Linux distributions, including
Red Hat Enterprise Linux
Red Hat Enterprise Linux (RHEL) is a commercial Linux distribution developed by Red Hat. Red Hat Enterprise Linux is released in server versions for x86-64, Power ISA, ARM64, and IBM Z and a desktop version for x86-64. Fedora Linux and ...
(since its version 6 released in 2010) and
Debian
Debian () is a free and open-source software, free and open source Linux distribution, developed by the Debian Project, which was established by Ian Murdock in August 1993. Debian is one of the oldest operating systems based on the Linux kerne ...
in the ''linux-tools-common'' package (since
Debian 6.0 (Squeeze) released in 2011).
Subcommands
perf is used with several subcommands:
*
stat
: measure total event count for single program or for system for some time
*
top
:
top
Top most commonly refers to:
* Top, a basic term of orientation, distinguished from bottom, front, back, and sides
* Spinning top, a ubiquitous traditional toy
* Top (clothing), clothing designed to be worn over the torso
* Mountain top, a moun ...
-like dynamic view of hottest functions
*
record
: measure and save sampling data for single program
[Urs Fässle]
perf file format
, CERN openlab, 2011
*
report
: analyze file generated by perf record; can generate flat, or graph profile.
*
annotate
: annotate sources or assembly
*
sched
: tracing/measuring of scheduler actions and latencies
*
list
: list available events
Criticism
The documentation of perf is not very detailed (as of 2014); for example, it does not document most events or explain their aliases (often external tools are used to get names and codes of events).
Perf tools also cannot profile based on true wall-clock time,
[Robert Haas (PostgreSQL)]
perf: the good, the bad, the ugly
// 6 June 2012 something that has been addressed by the addition of off-CPU profiling.
Security
The perf subsystem of Linux kernels from 2.6.37 up to 3.8.8 and RHEL6 kernel 2.6.32 contained a security vulnerability (), which was exploited to gain root privileges by a local user. The problem was due to an incorrect type being used (32-bit int instead of 64-bit) in the event_id verification code path.
See also
*
List of performance analysis tools
*
OProfile
*
Performance Application Programming Interface
In computer science, Performance Application Programming Interface (PAPI) is a portable interface (in the form of a library) to hardware performance counters on modern microprocessors. It is being widely used to collect low level performance met ...
*
Profiling (computer programming)
In software engineering, profiling (program profiling, software profiling) is a form of dynamic program analysis that measures, for example, the space (memory) or time complexity of a program, the usage of particular instructions, or the freque ...
References
External links
perf's wikion
kernel.org
* Arnaldo Carvalho de Melo
The New Linux ’perf’ tools presentation from Linux Kongress, September, 2010
– check perf_event column
by Brendan Gregg
{{Linux
Linux kernel features
Linux programming tools
Profilers