Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1perf.data format
2
3Uptodate as of v4.7
4
5This document describes the on-disk perf.data format, generated by perf record
6or perf inject and consumed by the other perf tools.
7
8On a high level perf.data contains the events generated by the PMUs, plus metadata.
9
10All fields are in native-endian of the machine that generated the perf.data.
11
12When perf is writing to a pipe it uses a special version of the file
13format that does not rely on seeking to adjust data offsets. This
14format is described in "Pipe-mode data" section. The pipe data version can be
15augmented with additional events using perf inject.
16
17The file starts with a perf_header:
18
19struct 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;
26 uint64_t flags;
27 uint64_t flags1[3];
28};
29
30The magic number identifies the perf file and the version. Current perf versions
31use PERFILE2. Old perf versions generated a version 1 format (PERFFILE). Version 1
32is not described here. The magic number also identifies the endian. When the
33magic value is 64bit byte swapped compared the file is in non-native
34endian.
35
36A perf_file_section contains a pointer to another section of the perf file.
37The header contains three such pointers: for attributes, data and event types.
38
39struct perf_file_section {
40 uint64_t offset; /* offset from start of file */
41 uint64_t size; /* size of the section */
42};
43
44Flags section:
45
46For each of the optional features a perf_file_section it placed after the data
47section if the feature bit is set in the perf_header flags bitset. The
48respective perf_file_section points to the data of the additional header and
49defines its size.
50
51Some headers consist of strings, which are defined like this:
52
53struct perf_header_string {
54 uint32_t len;
55 char string[len]; /* zero terminated */
56};
57
58Some headers consist of a sequence of strings, which start with a
59
60struct perf_header_string_list {
61 uint32_t nr;
62 struct perf_header_string strings[nr]; /* variable length records */
63};
64
65The bits are the flags bits in a 256 bit bitmap starting with
66flags. These define the valid bits:
67
68 HEADER_RESERVED = 0, /* always cleared */
69 HEADER_FIRST_FEATURE = 1,
70 HEADER_TRACING_DATA = 1,
71
72Describe me.
73
74 HEADER_BUILD_ID = 2,
75
76The header consists of an sequence of build_id_event. The size of each record
77is defined by header.size (see perf_event.h). Each event defines a ELF build id
78for a executable file name for a pid. An ELF build id is a unique identifier
79assigned by the linker to an executable.
80
81struct build_id_event {
82 struct perf_event_header header;
83 pid_t pid;
84 uint8_t build_id[24];
85 char filename[header.size - offsetof(struct build_id_event, filename)];
86};
87
88 HEADER_HOSTNAME = 3,
89
90A perf_header_string with the hostname where the data was collected
91(uname -n)
92
93 HEADER_OSRELEASE = 4,
94
95A perf_header_string with the os release where the data was collected
96(uname -r)
97
98 HEADER_VERSION = 5,
99
100A perf_header_string with the perf user tool version where the
101data was collected. This is the same as the version of the source tree
102the perf tool was built from.
103
104 HEADER_ARCH = 6,
105
106A perf_header_string with the CPU architecture (uname -m)
107
108 HEADER_NRCPUS = 7,
109
110A structure defining the number of CPUs.
111
112struct nr_cpus {
113 uint32_t nr_cpus_available; /* CPUs not yet onlined */
114 uint32_t nr_cpus_online;
115};
116
117 HEADER_CPUDESC = 8,
118
119A perf_header_string with description of the CPU. On x86 this is the model name
120in /proc/cpuinfo
121
122 HEADER_CPUID = 9,
123
124A perf_header_string with the exact CPU type. On x86 this is
125vendor,family,model,stepping. For example: GenuineIntel,6,69,1
126
127 HEADER_TOTAL_MEM = 10,
128
129An uint64_t with the total memory in bytes.
130
131 HEADER_CMDLINE = 11,
132
133A perf_header_string_list with the perf arg-vector used to collect the data.
134
135 HEADER_EVENT_DESC = 12,
136
137Another description of the perf_event_attrs, more detailed than header.attrs
138including IDs and names. See perf_event.h or the man page for a description
139of a struct perf_event_attr.
140
141struct {
142 uint32_t nr; /* number of events */
143 uint32_t attr_size; /* size of each perf_event_attr */
144 struct {
145 struct perf_event_attr attr; /* size of attr_size */
146 uint32_t nr_ids;
147 struct perf_header_string event_string;
148 uint64_t ids[nr_ids];
149 } events[nr]; /* Variable length records */
150};
151
152 HEADER_CPU_TOPOLOGY = 13,
153
154String lists defining the core and CPU threads topology.
155The string lists are followed by a variable length array
156which contains core_id and socket_id of each cpu.
157The number of entries can be determined by the size of the
158section minus the sizes of both string lists.
159
160struct {
161 struct perf_header_string_list cores; /* Variable length */
162 struct perf_header_string_list threads; /* Variable length */
163 struct {
164 uint32_t core_id;
165 uint32_t socket_id;
166 } cpus[nr]; /* Variable length records */
167};
168
169Example:
170 sibling cores : 0-3
171 sibling threads : 0-1
172 sibling threads : 2-3
173
174 HEADER_NUMA_TOPOLOGY = 14,
175
176 A list of NUMA node descriptions
177
178struct {
179 uint32_t nr;
180 struct {
181 uint32_t nodenr;
182 uint64_t mem_total;
183 uint64_t mem_free;
184 struct perf_header_string cpus;
185 } nodes[nr]; /* Variable length records */
186};
187
188 HEADER_BRANCH_STACK = 15,
189
190Not implemented in perf.
191
192 HEADER_PMU_MAPPINGS = 16,
193
194 A list of PMU structures, defining the different PMUs supported by perf.
195
196struct {
197 uint32_t nr;
198 struct pmu {
199 uint32_t pmu_type;
200 struct perf_header_string pmu_name;
201 } [nr]; /* Variable length records */
202};
203
204 HEADER_GROUP_DESC = 17,
205
206 Description of counter groups ({...} in perf syntax)
207
208struct {
209 uint32_t nr;
210 struct {
211 struct perf_header_string string;
212 uint32_t leader_idx;
213 uint32_t nr_members;
214 } [nr]; /* Variable length records */
215};
216
217 HEADER_AUXTRACE = 18,
218
219Define additional auxtrace areas in the perf.data. auxtrace is used to store
220undecoded hardware tracing information, such as Intel Processor Trace data.
221
222/**
223 * struct auxtrace_index_entry - indexes a AUX area tracing event within a
224 * perf.data file.
225 * @file_offset: offset within the perf.data file
226 * @sz: size of the event
227 */
228struct auxtrace_index_entry {
229 u64 file_offset;
230 u64 sz;
231};
232
233#define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
234
235/**
236 * struct auxtrace_index - index of AUX area tracing events within a perf.data
237 * file.
238 * @list: linking a number of arrays of entries
239 * @nr: number of entries
240 * @entries: array of entries
241 */
242struct auxtrace_index {
243 struct list_head list;
244 size_t nr;
245 struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
246};
247
248 HEADER_STAT = 19,
249
250This is merely a flag signifying that the data section contains data
251recorded from perf stat record.
252
253 HEADER_CACHE = 20,
254
255Description of the cache hierarchy. Based on the Linux sysfs format
256in /sys/devices/system/cpu/cpu*/cache/
257
258 u32 version Currently always 1
259 u32 number_of_cache_levels
260
261struct {
262 u32 level;
263 u32 line_size;
264 u32 sets;
265 u32 ways;
266 struct perf_header_string type;
267 struct perf_header_string size;
268 struct perf_header_string map;
269}[number_of_cache_levels];
270
271 HEADER_SAMPLE_TIME = 21,
272
273Two uint64_t for the time of first sample and the time of last sample.
274
275 other bits are reserved and should ignored for now
276 HEADER_FEAT_BITS = 256,
277
278Attributes
279
280This is an array of perf_event_attrs, each attr_size bytes long, which defines
281each event collected. See perf_event.h or the man page for a detailed
282description.
283
284Data
285
286This section is the bulk of the file. It consist of a stream of perf_events
287describing events. This matches the format generated by the kernel.
288See perf_event.h or the manpage for a detailed description.
289
290Some notes on parsing:
291
292Ordering
293
294The events are not necessarily in time stamp order, as they can be
295collected in parallel on different CPUs. If the events should be
296processed in time order they need to be sorted first. It is possible
297to only do a partial sort using the FINISHED_ROUND event header (see
298below). perf record guarantees that there is no reordering over a
299FINISHED_ROUND.
300
301ID vs IDENTIFIER
302
303When the event stream contains multiple events each event is identified
304by an ID. This can be either through the PERF_SAMPLE_ID or the
305PERF_SAMPLE_IDENTIFIER header. The PERF_SAMPLE_IDENTIFIER header is
306at a fixed offset from the event header, which allows reliable
307parsing of the header. Relying on ID may be ambiguous.
308IDENTIFIER is only supported by newer Linux kernels.
309
310Perf record specific events:
311
312In addition to the kernel generated event types perf record adds its
313own event types (in addition it also synthesizes some kernel events,
314for example MMAP events)
315
316 PERF_RECORD_USER_TYPE_START = 64,
317 PERF_RECORD_HEADER_ATTR = 64,
318
319struct attr_event {
320 struct perf_event_header header;
321 struct perf_event_attr attr;
322 uint64_t id[];
323};
324
325 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */
326
327#define MAX_EVENT_NAME 64
328
329struct perf_trace_event_type {
330 uint64_t event_id;
331 char name[MAX_EVENT_NAME];
332};
333
334struct event_type_event {
335 struct perf_event_header header;
336 struct perf_trace_event_type event_type;
337};
338
339
340 PERF_RECORD_HEADER_TRACING_DATA = 66,
341
342Describe me
343
344struct tracing_data_event {
345 struct perf_event_header header;
346 uint32_t size;
347};
348
349 PERF_RECORD_HEADER_BUILD_ID = 67,
350
351Define a ELF build ID for a referenced executable.
352
353 struct build_id_event; /* See above */
354
355 PERF_RECORD_FINISHED_ROUND = 68,
356
357No event reordering over this header. No payload.
358
359 PERF_RECORD_ID_INDEX = 69,
360
361Map event ids to CPUs and TIDs.
362
363struct id_index_entry {
364 uint64_t id;
365 uint64_t idx;
366 uint64_t cpu;
367 uint64_t tid;
368};
369
370struct id_index_event {
371 struct perf_event_header header;
372 uint64_t nr;
373 struct id_index_entry entries[nr];
374};
375
376 PERF_RECORD_AUXTRACE_INFO = 70,
377
378Auxtrace type specific information. Describe me
379
380struct auxtrace_info_event {
381 struct perf_event_header header;
382 uint32_t type;
383 uint32_t reserved__; /* For alignment */
384 uint64_t priv[];
385};
386
387 PERF_RECORD_AUXTRACE = 71,
388
389Defines auxtrace data. Followed by the actual data. The contents of
390the auxtrace data is dependent on the event and the CPU. For example
391for Intel Processor Trace it contains Processor Trace data generated
392by the CPU.
393
394struct auxtrace_event {
395 struct perf_event_header header;
396 uint64_t size;
397 uint64_t offset;
398 uint64_t reference;
399 uint32_t idx;
400 uint32_t tid;
401 uint32_t cpu;
402 uint32_t reserved__; /* For alignment */
403};
404
405struct aux_event {
406 struct perf_event_header header;
407 uint64_t aux_offset;
408 uint64_t aux_size;
409 uint64_t flags;
410};
411
412 PERF_RECORD_AUXTRACE_ERROR = 72,
413
414Describes an error in hardware tracing
415
416enum auxtrace_error_type {
417 PERF_AUXTRACE_ERROR_ITRACE = 1,
418 PERF_AUXTRACE_ERROR_MAX
419};
420
421#define MAX_AUXTRACE_ERROR_MSG 64
422
423struct auxtrace_error_event {
424 struct perf_event_header header;
425 uint32_t type;
426 uint32_t code;
427 uint32_t cpu;
428 uint32_t pid;
429 uint32_t tid;
430 uint32_t reserved__; /* For alignment */
431 uint64_t ip;
432 char msg[MAX_AUXTRACE_ERROR_MSG];
433};
434
435 PERF_RECORD_HEADER_FEATURE = 80,
436
437Describes a header feature. These are records used in pipe-mode that
438contain information that otherwise would be in perf.data file's header.
439
440Event types
441
442Define the event attributes with their IDs.
443
444An array bound by the perf_file_section size.
445
446 struct {
447 struct perf_event_attr attr; /* Size defined by header.attr_size */
448 struct perf_file_section ids;
449 }
450
451ids points to a array of uint64_t defining the ids for event attr attr.
452
453Pipe-mode data
454
455Pipe-mode avoid seeks in the file by removing the perf_file_section and flags
456from the struct perf_header. The trimmed header is:
457
458struct perf_pipe_file_header {
459 u64 magic;
460 u64 size;
461};
462
463The information about attrs, data, and event_types is instead in the
464synthesized events PERF_RECORD_ATTR, PERF_RECORD_HEADER_TRACING_DATA,
465PERF_RECORD_HEADER_EVENT_TYPE, and PERF_RECORD_HEADER_FEATURE
466that are generated by perf record in pipe-mode.
467
468
469References:
470
471include/uapi/linux/perf_event.h
472
473This is the canonical description of the kernel generated perf_events
474and the perf_event_attrs.
475
476perf_events manpage
477
478A manpage describing perf_event and perf_event_attr is here:
479http://web.eece.maine.edu/~vweaver/projects/perf_events/programming.html
480This tends to be slightly behind the kernel include, but has better
481descriptions. An (typically older) version of the man page may be
482included with the standard Linux man pages, available with "man
483perf_events"
484
485pmu-tools
486
487https://github.com/andikleen/pmu-tools/tree/master/parser
488
489A definition of the perf.data format in python "construct" format is available
490in pmu-tools parser. This allows to read perf.data from python and dump it.
491
492quipper
493
494The quipper C++ parser is available at
495http://github.com/google/perf_data_converter/tree/master/src/quipper
496