Blame src/libpfm4/docs/man3/libpfm.3

Packit Service a1973e
.TH LIBPFM 3  "May, 2010" "" "Linux Programmer's Manual"
Packit Service a1973e
.SH NAME
Packit Service a1973e
libpfm \- a helper library to develop monitoring tools 
Packit Service a1973e
.SH SYNOPSIS
Packit Service a1973e
.nf
Packit Service a1973e
.B #include <perfmon/pfmlib.h>
Packit Service a1973e
Packit Service a1973e
.SH DESCRIPTION
Packit Service a1973e
This is a helper library used by applications to program
Packit Service a1973e
specific performance monitoring events. Those events are typically
Packit Service a1973e
provided by the hardware or the OS kernel. The most common hardware events
Packit Service a1973e
are provided by the Performance Monitoring Unit (PMU) of modern processors.
Packit Service a1973e
They can measure elapsed cycles or the number of cache misses. Software events
Packit Service a1973e
usually count kernel events  such as the number of context switches, or pages faults.
Packit Service a1973e
Packit Service a1973e
The library groups events based on which source is providing them.
Packit Service a1973e
The term PMU is generalized to any event source, not just hardware sources.
Packit Service a1973e
The library supports hardware performance events from most common processors,
Packit Service a1973e
each group under a specific PMU name, such as Intel Core, IBM Power 6.
Packit Service a1973e
Packit Service a1973e
Programming events is usually done through a kernel API, such as Oprofile,
Packit Service a1973e
perfmon, perfctr, or perf_events on Linux. The library provides support for
Packit Service a1973e
perf_events which is available in the Linux kernel as of v2.6.31. Perf_events
Packit Service a1973e
supports selected PMU models and several software events.
Packit Service a1973e
Packit Service a1973e
At its core, the library provides a simple translation service, whereby
Packit Service a1973e
a user specifies an event to measure as a string and the library returns
Packit Service a1973e
the parameters needed to invoke the kernel API. It is important to realize
Packit Service a1973e
that the library does \fBnot\fR make the system call to program the event.
Packit Service a1973e
Packit Service a1973e
\fBNote:\fR You must first call \fBpfm_initialize()\fR in order to use any of the other
Packit Service a1973e
provided functions in the library.
Packit Service a1973e
Packit Service a1973e
A first part of the library provides an event listing and query
Packit Service a1973e
interface. This can be used to discover the events available on a specific hardware 
Packit Service a1973e
platform.
Packit Service a1973e
Packit Service a1973e
The second part of the library provides a set of functions to obtain event
Packit Service a1973e
encodings form event strings. Event encoding depends primarily on the underlying
Packit Service a1973e
hardware but also on the kernel API. The library offers a generic API to address
Packit Service a1973e
the first situation but it also provides entry points for specific kernel APIs such
Packit Service a1973e
as perf_events. In that case, it is able to prepare the data structure which
Packit Service a1973e
must be passed to the kernel to program a specific event.
Packit Service a1973e
Packit Service a1973e
.SH EVENT DETECTION
Packit Service a1973e
Packit Service a1973e
When the library is initialized via \fBpfm_initialize()\fR, it first detects the
Packit Service a1973e
underlying hardware and software configuration.  Based on this information
Packit Service a1973e
it enables certain PMU support.  Multiple events tables may be activated.
Packit Service a1973e
Packit Service a1973e
It is possible to force activation of a specific PMU (group of events)
Packit Service a1973e
using an environment variable.
Packit Service a1973e
Packit Service a1973e
.SH EVENT STRINGS
Packit Service a1973e
Events are expressed as strings. Those string are structured and may contain
Packit Service a1973e
several components depending on the type of event and the underlying hardware.
Packit Service a1973e
Packit Service a1973e
String parsing is always case insensitive.
Packit Service a1973e
Packit Service a1973e
The string structure is defined as follows:
Packit Service a1973e
.sp
Packit Service a1973e
.ce
Packit Service a1973e
.B [pmu::][event_name][:unit_mask][:modifier|:modifier=val]
Packit Service a1973e
Packit Service a1973e
or
Packit Service a1973e
.ce
Packit Service a1973e
.B [pmu::][event_name][.unit_mask][.modifier|.modifier=val]
Packit Service a1973e
Packit Service a1973e
The components are defined as follows:
Packit Service a1973e
.TP
Packit Service a1973e
.B pmu
Packit Service a1973e
Optional name of the PMU (group of events) to which the event belongs to. This is
Packit Service a1973e
useful to disambiguate events in case events from difference sources have the same
Packit Service a1973e
name. If not specified, the first match is used.
Packit Service a1973e
.TP
Packit Service a1973e
.B event_name
Packit Service a1973e
The name of the event. It must be the complete name, partial matches are not accepted.
Packit Service a1973e
This component is required.
Packit Service a1973e
.TP
Packit Service a1973e
.B unit_mask
Packit Service a1973e
This designate an optional sub-events. Some events can be refined using sub-events.
Packit Service a1973e
Event may have multiple unit masks and it may or may be possible to combine them.
Packit Service a1973e
If more than one unit masks needs to be passed, then the [:unit_mask] pattern can
Packit Service a1973e
be repeated.
Packit Service a1973e
.TP
Packit Service a1973e
.B modifier
Packit Service a1973e
A modifier is an optional filter which modifies how the event counts. Modifiers
Packit Service a1973e
have a type and a value. The value is specified after the equal sign. No space is
Packit Service a1973e
allowed. In case of boolean modifiers, it is possible to omit the value true (1).
Packit Service a1973e
The presence of the modifier is interpreted as meaning true. Events may support
Packit Service a1973e
multiple modifiers, in which case the [:modifier|:modifier=val] pattern can be
Packit Service a1973e
repeated. The is no ordering constraint between modifier and unit masks. Modifiers
Packit Service a1973e
may be specified before unit masks and vice-versa.
Packit Service a1973e
Packit Service a1973e
.SH ENVIRONMENT VARIABLES
Packit Service a1973e
It is possible to enable certain debug features of the library using environment
Packit Service a1973e
variables. The following variables are defined:
Packit Service a1973e
.TP
Packit Service a1973e
.B LIBPFM_VERBOSE
Packit Service a1973e
Enable verbose output. Value must be 0 or 1. 
Packit Service a1973e
.TP
Packit Service a1973e
.B LIBPFM_DEBUG
Packit Service a1973e
Enable debug  output. Value must be 0 or 1
Packit Service a1973e
.TP
Packit Service a1973e
.B LIBPFM_DEBUG_STDOUT
Packit Service a1973e
Redirect verbose and debug output to the standard output file descriptor (stdout).
Packit Service a1973e
By default, the output is directed to the standard error file descriptor (stderr).
Packit Service a1973e
.TP
Packit Service a1973e
.B LIBPFM_FORCE_PMU
Packit Service a1973e
Force a specific PMU model to be activated. In this mode, only that one model
Packit Service a1973e
is activated. The value of the variable must be the PMU name as returned by the
Packit Service a1973e
\fBpfm_get_pmu_name()\fR function. Note for some PMU models, it may be possible
Packit Service a1973e
to specify additional options, such as specific processor models or stepping.
Packit Service a1973e
Additional parameters necessarily appears after a comma. For instance,
Packit Service a1973e
LIBPFM_FORCE_PMU=amd64,16,2,1.
Packit Service a1973e
.TP
Packit Service a1973e
.B LIBPFM_ENCODE_INACTIVE
Packit Service a1973e
Set this variable to 1 to enable encoding of events for non detected, but supported,
Packit Service a1973e
PMUs models.
Packit Service a1973e
.TP
Packit Service a1973e
.B LIBPFM_DISABLED_PMUS
Packit Service a1973e
Provides a list of PMU models to disable. This is a comma separated list of PMU
Packit Service a1973e
models. The PMU model is the string in \fBname\fR field of the \fBpfm_pmu_info_t\fR
Packit Service a1973e
structure. For instance: LIBPFM_DISABLE_PMUS=core,snb, will disable both the Intel
Packit Service a1973e
Core and SandyBridge core PMU support.
Packit Service a1973e
Packit Service a1973e
.SH AUTHORS
Packit Service a1973e
.nf
Packit Service a1973e
Stephane Eranian <eranian@gmail.com>
Packit Service a1973e
Robert Richter <robert.richter@amd.com>
Packit Service a1973e
.fi
Packit Service a1973e
.SH SEE ALSO
Packit Service a1973e
libpfm_amd64_k7(3), libpfm_amd64_k8(3), libpfm_amd64_fam10h(3), libpfm_intel_core(3),
Packit Service a1973e
libpfm_intel_atom(3), libpfm_intel_p6(3), libpfm_intel_nhm(3), libpfm_intel_nhm_unc(3),
Packit Service a1973e
pfm_get_perf_event_encoding(3), pfm_initialize(3)
Packit Service a1973e
.sp
Packit Service a1973e
Some examples are shipped with the library