5 This document describes the on-disk perf.data format, generated by perf record
6 or perf inject and consumed by the other perf tools.
8 On a high level perf.data contains the events generated by the PMUs, plus metadata.
10 All fields are in native-endian of the machine that generated the perf.data.
12 When perf is writing to a pipe it uses a special version of the file
13 format that does not rely on seeking to adjust data offsets. This
14 format is not described here. The pipe version can be converted to
15 normal perf.data with perf inject.
17 The file starts with a perf_header:
20 char magic[8]; /* PERFILE2 */
21 uint64_t size; /* size of the header */
22 uint64_t attr_size; /* size of an attribute in attrs */
23 struct perf_file_section attrs;
24 struct perf_file_section data;
25 struct perf_file_section event_types;
30 The magic number identifies the perf file and the version. Current perf versions
31 use PERFILE2. Old perf versions generated a version 1 format (PERFFILE). Version 1
32 is not described here. The magic number also identifies the endian. When the
33 magic value is 64bit byte swapped compared the file is in non-native
36 A perf_file_section contains a pointer to another section of the perf file.
37 The header contains three such pointers: for attributes, data and event types.
39 struct perf_file_section {
40 uint64_t offset; /* offset from start of file */
41 uint64_t size; /* size of the section */
46 The header is followed by different optional headers, described by the bits set
47 in flags. Only headers for which the bit is set are included. Each header
48 consists of a perf_file_section located after the initial header.
49 The respective perf_file_section points to the data of the additional
50 header and defines its size.
52 Some headers consist of strings, which are defined like this:
54 struct perf_header_string {
56 char string[len]; /* zero terminated */
59 Some headers consist of a sequence of strings, which start with a
61 struct perf_header_string_list {
63 struct perf_header_string strings[nr]; /* variable length records */
66 The bits are the flags bits in a 256 bit bitmap starting with
67 flags. These define the valid bits:
69 HEADER_RESERVED = 0, /* always cleared */
70 HEADER_FIRST_FEATURE = 1,
71 HEADER_TRACING_DATA = 1,
77 The header consists of an sequence of build_id_event. The size of each record
78 is defined by header.size (see perf_event.h). Each event defines a ELF build id
79 for a executable file name for a pid. An ELF build id is a unique identifier
80 assigned by the linker to an executable.
82 struct build_id_event {
83 struct perf_event_header header;
86 char filename[header.size - offsetof(struct build_id_event, filename)];
91 A perf_header_string with the hostname where the data was collected
96 A perf_header_string with the os release where the data was collected
101 A perf_header_string with the perf user tool version where the
102 data was collected. This is the same as the version of the source tree
103 the perf tool was built from.
107 A perf_header_string with the CPU architecture (uname -m)
111 A structure defining the number of CPUs.
114 uint32_t nr_cpus_online;
115 uint32_t nr_cpus_available; /* CPUs not yet onlined */
120 A perf_header_string with description of the CPU. On x86 this is the model name
125 A perf_header_string with the exact CPU type. On x86 this is
126 vendor,family,model,stepping. For example: GenuineIntel,6,69,1
128 HEADER_TOTAL_MEM = 10,
130 An uint64_t with the total memory in bytes.
134 A perf_header_string with the perf command line used to collect the data.
136 HEADER_EVENT_DESC = 12,
138 Another description of the perf_event_attrs, more detailed than header.attrs
139 including IDs and names. See perf_event.h or the man page for a description
140 of a struct perf_event_attr.
143 uint32_t nr; /* number of events */
144 uint32_t attr_size; /* size of each perf_event_attr */
146 struct perf_event_attr attr; /* size of attr_size */
148 struct perf_header_string event_string;
149 uint64_t ids[nr_ids];
150 } events[nr]; /* Variable length records */
153 HEADER_CPU_TOPOLOGY = 13,
155 String lists defining the core and CPU threads topology.
158 struct perf_header_string_list cores; /* Variable length */
159 struct perf_header_string_list threads; /* Variable length */
164 sibling threads : 0-1
165 sibling threads : 2-3
167 HEADER_NUMA_TOPOLOGY = 14,
169 A list of NUMA node descriptions
177 struct perf_header_string cpus;
178 } nodes[nr]; /* Variable length records */
181 HEADER_BRANCH_STACK = 15,
183 Not implemented in perf.
185 HEADER_PMU_MAPPINGS = 16,
187 A list of PMU structures, defining the different PMUs supported by perf.
193 struct perf_header_string pmu_name;
194 } [nr]; /* Variable length records */
197 HEADER_GROUP_DESC = 17,
199 Description of counter groups ({...} in perf syntax)
204 struct perf_header_string string;
207 } [nr]; /* Variable length records */
210 HEADER_AUXTRACE = 18,
212 Define additional auxtrace areas in the perf.data. auxtrace is used to store
213 undecoded hardware tracing information, such as Intel Processor Trace data.
216 * struct auxtrace_index_entry - indexes a AUX area tracing event within a
218 * @file_offset: offset within the perf.data file
219 * @sz: size of the event
221 struct auxtrace_index_entry {
226 #define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
229 * struct auxtrace_index - index of AUX area tracing events within a perf.data
231 * @list: linking a number of arrays of entries
232 * @nr: number of entries
233 * @entries: array of entries
235 struct auxtrace_index {
236 struct list_head list;
238 struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
241 other bits are reserved and should ignored for now
242 HEADER_FEAT_BITS = 256,
246 This is an array of perf_event_attrs, each attr_size bytes long, which defines
247 each event collected. See perf_event.h or the man page for a detailed
252 This section is the bulk of the file. It consist of a stream of perf_events
253 describing events. This matches the format generated by the kernel.
254 See perf_event.h or the manpage for a detailed description.
256 Some notes on parsing:
260 The events are not necessarily in time stamp order, as they can be
261 collected in parallel on different CPUs. If the events should be
262 processed in time order they need to be sorted first. It is possible
263 to only do a partial sort using the FINISHED_ROUND event header (see
264 below). perf record guarantees that there is no reordering over a
269 When the event stream contains multiple events each event is identified
270 by an ID. This can be either through the PERF_SAMPLE_ID or the
271 PERF_SAMPLE_IDENTIFIER header. The PERF_SAMPLE_IDENTIFIER header is
272 at a fixed offset from the event header, which allows reliable
273 parsing of the header. Relying on ID may be ambigious.
274 IDENTIFIER is only supported by newer Linux kernels.
276 Perf record specific events:
278 In addition to the kernel generated event types perf record adds its
279 own event types (in addition it also synthesizes some kernel events,
280 for example MMAP events)
282 PERF_RECORD_USER_TYPE_START = 64,
283 PERF_RECORD_HEADER_ATTR = 64,
286 struct perf_event_header header;
287 struct perf_event_attr attr;
291 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
293 #define MAX_EVENT_NAME 64
295 struct perf_trace_event_type {
297 char name[MAX_EVENT_NAME];
300 struct event_type_event {
301 struct perf_event_header header;
302 struct perf_trace_event_type event_type;
306 PERF_RECORD_HEADER_TRACING_DATA = 66,
310 struct tracing_data_event {
311 struct perf_event_header header;
315 PERF_RECORD_HEADER_BUILD_ID = 67,
317 Define a ELF build ID for a referenced executable.
319 struct build_id_event; /* See above */
321 PERF_RECORD_FINISHED_ROUND = 68,
323 No event reordering over this header. No payload.
325 PERF_RECORD_ID_INDEX = 69,
327 Map event ids to CPUs and TIDs.
329 struct id_index_entry {
336 struct id_index_event {
337 struct perf_event_header header;
339 struct id_index_entry entries[nr];
342 PERF_RECORD_AUXTRACE_INFO = 70,
344 Auxtrace type specific information. Describe me
346 struct auxtrace_info_event {
347 struct perf_event_header header;
349 uint32_t reserved__; /* For alignment */
353 PERF_RECORD_AUXTRACE = 71,
355 Defines auxtrace data. Followed by the actual data. The contents of
356 the auxtrace data is dependent on the event and the CPU. For example
357 for Intel Processor Trace it contains Processor Trace data generated
360 struct auxtrace_event {
361 struct perf_event_header header;
368 uint32_t reserved__; /* For alignment */
372 struct perf_event_header header;
378 PERF_RECORD_AUXTRACE_ERROR = 72,
380 Describes an error in hardware tracing
382 enum auxtrace_error_type {
383 PERF_AUXTRACE_ERROR_ITRACE = 1,
384 PERF_AUXTRACE_ERROR_MAX
387 #define MAX_AUXTRACE_ERROR_MSG 64
389 struct auxtrace_error_event {
390 struct perf_event_header header;
396 uint32_t reserved__; /* For alignment */
398 char msg[MAX_AUXTRACE_ERROR_MSG];
403 Define the event attributes with their IDs.
405 An array bound by the perf_file_section size.
408 struct perf_event_attr attr; /* Size defined by header.attr_size */
409 struct perf_file_section ids;
412 ids points to a array of uint64_t defining the ids for event attr attr.
416 include/uapi/linux/perf_event.h
418 This is the canonical description of the kernel generated perf_events
419 and the perf_event_attrs.
423 A manpage describing perf_event and perf_event_attr is here:
424 http://web.eece.maine.edu/~vweaver/projects/perf_events/programming.html
425 This tends to be slightly behind the kernel include, but has better
426 descriptions. An (typically older) version of the man page may be
427 included with the standard Linux man pages, available with "man
432 https://github.com/andikleen/pmu-tools/tree/master/parser
434 A definition of the perf.data format in python "construct" format is available
435 in pmu-tools parser. This allows to read perf.data from python and dump it.
439 The quipper C++ parser is available at
440 https://chromium.googlesource.com/chromiumos/platform/chromiumos-wide-profiling/
441 Unfortunately this parser tends to be many versions behind and may not be able
442 to parse data files generated by recent perf.