perf (sometimes called perf_events or perf tools, originally Performance Counters for Linux, PCL) is a
performance analyzing tool in
Linux
Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which i ...
, available from
Linux kernel
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ...
version 2.6.31 in 2009.
Userspace
A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour.
Kernel ...
controlling utility, named
perf
, is accessed from the
command line
A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
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 counter In computers, hardware performance counters (HPC), or hardware counters are a set of special-purpose registers built into modern microprocessors to store the counts of hardware-related activities within computer systems. Advanced users often rely on ...
s,
tracepoint
ftrace (Function Tracer) is a tracing framework for the Linux kernel. Although its original name, Function Tracer, came from ftrace's ability to record information related to various function calls performed while the kernel is running, ftrace ...
s, software performance counters (e.g. hrtimer), and dynamic probes (for example, kprobes or uprobes).
In 2012, two
IBM engineers recognized perf (along with
OProfile
In computing, OProfile is a system-wide statistical profiling tool for Linux. John Levon wrote it in 2001 for Linux kernel version 2.4 after his M.Sc. project; it consists of a kernel module, a user-space daemon and several user-space tools.
De ...
) 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
In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
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 ...
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 or older versions of
oprofile
In computing, OProfile is a system-wide statistical profiling tool for Linux. John Levon wrote it in 2001 for Linux kernel version 2.4 after his M.Sc. project; it consists of a kernel module, a user-space daemon and several user-space tools.
De ...
, 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,
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– IBM ...
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 Tremb ...
(
III and
IV),
ARM (v5, v6, v7,
Cortex-A8
The ARM Cortex-A8 is a 32-bit processor core licensed by ARM Holdings implementing the ARMv7-A architecture.
Compared to the ARM11, the Cortex-A8 is a dual-issue superscalar design, achieving roughly twice the instructions per cycle. The Corte ...
and
-A9),
Alpha 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 t ...
.
[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, Santa Clara, California. It is the world's largest semiconductor chip manufacturer by revenue, and is one of the devel ...
CPUs since
Pentium 4
Pentium 4 is a series of single-core CPUs for desktops, laptops and entry-level servers manufactured by Intel. The processors were shipped from November 20, 2000 until August 8, 2008. The production of Netburst processors was active from 2000 ...
, is available as a patch.
Since version 3.14 of the
Linux kernel mainline
The Linux kernel is a free and open-source, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU oper ...
, released on March 31, 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 software, commercial Open-source software, open-source Linux distribution developed by Red Hat for the commerce, commercial market. Red Hat Enterprise Linux is released in server versions for x86-6 ...
(since its version 6 released in 2010) and
Debian
Debian (), also known as Debian GNU/Linux, is a Linux distribution composed of free and open-source software, developed by the community-supported Debian Project, which was established by Ian Murdock on August 16, 1993. The first version of De ...
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-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
// June 06, 2012
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
This is a list of performance analysis tools for use in software development.
General purpose, language independent
The following tools work based on log files that can be generated from various systems.
* time (Unix) - can be used to determi ...
*
OProfile
In computing, OProfile is a system-wide statistical profiling tool for Linux. John Levon wrote it in 2001 for Linux kernel version 2.4 after his M.Sc. project; it consists of a kernel module, a user-space daemon and several user-space tools.
De ...
*
Performance Application Programming Interface
*
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 f ...
References
External links
perf's wikion
kernel.org
* Arnaldo Carvalho de Melo
The New Linux ’perf’ tools presentation from Linux Kongress, September, 2010
Linux kernel profiling with perftutorial
- check perf_event column
by Brendan Gregg
{{Linux
Linux kernel features
Linux programming tools
Profilers