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 ...
, 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 ope ...
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 Processor register, registers built into modern microprocessors to store the counts of hardware-related activities within computer systems. Advanced ...
s,
tracepoints, 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 have ...
and a mapped memory region.
[Roberto A. Vitillo (]LBNL
Lawrence Berkeley National Laboratory (LBNL), commonly referred to as the Berkeley Lab, is a United States national laboratory that is owned by, and conducts scientific research on behalf of, the United States Department of Energy. Located in ...
)
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
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
Lawrence Berkeley National Laboratory (LBNL), commonly referred to as the Berkeley Lab, is a United States national laboratory that is owned by, and conducts scientific research on behalf of, the United States Department of Energy. Located in ...
), 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 Intel 8086 microprocessor and its 8088 variant. The 8086 was introd ...
,
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 Tr ...
(
III and
IV),
ARM
In human anatomy, the arm refers to the upper limb in common usage, although academically the term specifically means the upper arm between the glenohumeral joint (shoulder joint) and the elbow joint. The distal part of the upper limb between th ...
(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 Cort ...
and
-A9),
Alpha
Alpha (uppercase , lowercase ; grc, ἄλφα, ''álpha'', or ell, άλφα, álfa) 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 , whic ...
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. It is the world's largest semiconductor chip manufacturer by revenue, and is one of the developers of the x86 seri ...
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 o ...
, 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 open-source Linux distribution developed by Red Hat for the commercial market. Red Hat Enterprise Linux is released in server versions for x86-64, Power ISA, ARM64, and IBM Z and a desktop version ...
(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 D ...
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
A spinning top, or simply a top, is a toy with a squat body and a sharp point at the bottom, designed to be spun on its vertical axis, balancing on the tip due to the gyroscopic effect.
Once set in motion, a top will usually wobble for a few ...
-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 determin ...
*
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 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 metri ...
*
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 fr ...
References
External links
perf's wikion
kernel.org
kernel.org is the main distribution point of source code for the Linux kernel, which is the base of the Linux operating system.
Website
The website and related infrastructure, which are operated by the Linux Kernel Organization, host the reposi ...
* 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