Loading...
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 kilobytes.
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
154struct {
155 /*
156 * First revision of HEADER_CPU_TOPOLOGY
157 *
158 * See 'struct perf_header_string_list' definition earlier
159 * in this file.
160 */
161
162 struct perf_header_string_list cores; /* Variable length */
163 struct perf_header_string_list threads; /* Variable length */
164
165 /*
166 * Second revision of HEADER_CPU_TOPOLOGY, older tools
167 * will not consider what comes next
168 */
169
170 struct {
171 uint32_t core_id;
172 uint32_t socket_id;
173 } cpus[nr]; /* Variable length records */
174 /* 'nr' comes from previously processed HEADER_NRCPUS's nr_cpu_avail */
175
176 /*
177 * Third revision of HEADER_CPU_TOPOLOGY, older tools
178 * will not consider what comes next
179 */
180
181 struct perf_header_string_list dies; /* Variable length */
182 uint32_t die_id[nr_cpus_avail]; /* from previously processed HEADER_NR_CPUS, VLA */
183};
184
185Example:
186 sibling sockets : 0-8
187 sibling dies : 0-3
188 sibling dies : 4-7
189 sibling threads : 0-1
190 sibling threads : 2-3
191 sibling threads : 4-5
192 sibling threads : 6-7
193
194 HEADER_NUMA_TOPOLOGY = 14,
195
196 A list of NUMA node descriptions
197
198struct {
199 uint32_t nr;
200 struct {
201 uint32_t nodenr;
202 uint64_t mem_total;
203 uint64_t mem_free;
204 struct perf_header_string cpus;
205 } nodes[nr]; /* Variable length records */
206};
207
208 HEADER_BRANCH_STACK = 15,
209
210Not implemented in perf.
211
212 HEADER_PMU_MAPPINGS = 16,
213
214 A list of PMU structures, defining the different PMUs supported by perf.
215
216struct {
217 uint32_t nr;
218 struct pmu {
219 uint32_t pmu_type;
220 struct perf_header_string pmu_name;
221 } [nr]; /* Variable length records */
222};
223
224 HEADER_GROUP_DESC = 17,
225
226 Description of counter groups ({...} in perf syntax)
227
228struct {
229 uint32_t nr;
230 struct {
231 struct perf_header_string string;
232 uint32_t leader_idx;
233 uint32_t nr_members;
234 } [nr]; /* Variable length records */
235};
236
237 HEADER_AUXTRACE = 18,
238
239Define additional auxtrace areas in the perf.data. auxtrace is used to store
240undecoded hardware tracing information, such as Intel Processor Trace data.
241
242/**
243 * struct auxtrace_index_entry - indexes a AUX area tracing event within a
244 * perf.data file.
245 * @file_offset: offset within the perf.data file
246 * @sz: size of the event
247 */
248struct auxtrace_index_entry {
249 u64 file_offset;
250 u64 sz;
251};
252
253#define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
254
255/**
256 * struct auxtrace_index - index of AUX area tracing events within a perf.data
257 * file.
258 * @list: linking a number of arrays of entries
259 * @nr: number of entries
260 * @entries: array of entries
261 */
262struct auxtrace_index {
263 struct list_head list;
264 size_t nr;
265 struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
266};
267
268 HEADER_STAT = 19,
269
270This is merely a flag signifying that the data section contains data
271recorded from perf stat record.
272
273 HEADER_CACHE = 20,
274
275Description of the cache hierarchy. Based on the Linux sysfs format
276in /sys/devices/system/cpu/cpu*/cache/
277
278 u32 version Currently always 1
279 u32 number_of_cache_levels
280
281struct {
282 u32 level;
283 u32 line_size;
284 u32 sets;
285 u32 ways;
286 struct perf_header_string type;
287 struct perf_header_string size;
288 struct perf_header_string map;
289}[number_of_cache_levels];
290
291 HEADER_SAMPLE_TIME = 21,
292
293Two uint64_t for the time of first sample and the time of last sample.
294
295 HEADER_SAMPLE_TOPOLOGY = 22,
296
297Physical memory map and its node assignments.
298
299The format of data in MEM_TOPOLOGY is as follows:
300
301 u64 version; // Currently 1
302 u64 block_size_bytes; // /sys/devices/system/memory/block_size_bytes
303 u64 count; // number of nodes
304
305struct memory_node {
306 u64 node_id; // node index
307 u64 size; // size of bitmap
308 struct bitmap {
309 /* size of bitmap again */
310 u64 bitmapsize;
311 /* bitmap of memory indexes that belongs to node */
312 /* /sys/devices/system/node/node<NODE>/memory<INDEX> */
313 u64 entries[(bitmapsize/64)+1];
314 }
315}[count];
316
317The MEM_TOPOLOGY can be displayed with following command:
318
319$ perf report --header-only -I
320...
321# memory nodes (nr 1, block size 0x8000000):
322# 0 [7G]: 0-23,32-69
323
324 HEADER_CLOCKID = 23,
325
326One uint64_t for the clockid frequency, specified, for instance, via 'perf
327record -k' (see clock_gettime()), to enable timestamps derived metrics
328conversion into wall clock time on the reporting stage.
329
330 HEADER_DIR_FORMAT = 24,
331
332The data files layout is described by HEADER_DIR_FORMAT feature. Currently it
333holds only version number (1):
334
335 uint64_t version;
336
337The current version holds only version value (1) means that data files:
338
339- Follow the 'data.*' name format.
340
341- Contain raw events data in standard perf format as read from kernel (and need
342 to be sorted)
343
344Future versions are expected to describe different data files layout according
345to special needs.
346
347 HEADER_BPF_PROG_INFO = 25,
348
349struct perf_bpil, which contains detailed information about
350a BPF program, including type, id, tag, jited/xlated instructions, etc.
351
352 HEADER_BPF_BTF = 26,
353
354Contains BPF Type Format (BTF). For more information about BTF, please
355refer to Documentation/bpf/btf.rst.
356
357struct {
358 u32 id;
359 u32 data_size;
360 char data[];
361};
362
363 HEADER_COMPRESSED = 27,
364
365struct {
366 u32 version;
367 u32 type;
368 u32 level;
369 u32 ratio;
370 u32 mmap_len;
371};
372
373Indicates that trace contains records of PERF_RECORD_COMPRESSED type
374that have perf_events records in compressed form.
375
376 HEADER_CPU_PMU_CAPS = 28,
377
378 A list of cpu PMU capabilities. The format of data is as below.
379
380struct {
381 u32 nr_cpu_pmu_caps;
382 {
383 char name[];
384 char value[];
385 } [nr_cpu_pmu_caps]
386};
387
388
389Example:
390 cpu pmu capabilities: branches=32, max_precise=3, pmu_name=icelake
391
392 HEADER_CLOCK_DATA = 29,
393
394 Contains clock id and its reference time together with wall clock
395 time taken at the 'same time', both values are in nanoseconds.
396 The format of data is as below.
397
398struct {
399 u32 version; /* version = 1 */
400 u32 clockid;
401 u64 wall_clock_ns;
402 u64 clockid_time_ns;
403};
404
405 HEADER_HYBRID_TOPOLOGY = 30,
406
407Indicate the hybrid CPUs. The format of data is as below.
408
409struct {
410 u32 nr;
411 struct {
412 char pmu_name[];
413 char cpus[];
414 } [nr]; /* Variable length records */
415};
416
417Example:
418 hybrid cpu system:
419 cpu_core cpu list : 0-15
420 cpu_atom cpu list : 16-23
421
422 HEADER_PMU_CAPS = 31,
423
424 List of pmu capabilities (except cpu pmu which is already
425 covered by HEADER_CPU_PMU_CAPS). Note that hybrid cpu pmu
426 capabilities are also stored here.
427
428struct {
429 u32 nr_pmu;
430 struct {
431 u32 nr_caps;
432 {
433 char name[];
434 char value[];
435 } [nr_caps];
436 char pmu_name[];
437 } [nr_pmu];
438};
439
440 other bits are reserved and should ignored for now
441 HEADER_FEAT_BITS = 256,
442
443Attributes
444
445This is an array of perf_event_attrs, each attr_size bytes long, which defines
446each event collected. See perf_event.h or the man page for a detailed
447description.
448
449Data
450
451This section is the bulk of the file. It consist of a stream of perf_events
452describing events. This matches the format generated by the kernel.
453See perf_event.h or the manpage for a detailed description.
454
455Some notes on parsing:
456
457Ordering
458
459The events are not necessarily in time stamp order, as they can be
460collected in parallel on different CPUs. If the events should be
461processed in time order they need to be sorted first. It is possible
462to only do a partial sort using the FINISHED_ROUND event header (see
463below). perf record guarantees that there is no reordering over a
464FINISHED_ROUND.
465
466ID vs IDENTIFIER
467
468When the event stream contains multiple events each event is identified
469by an ID. This can be either through the PERF_SAMPLE_ID or the
470PERF_SAMPLE_IDENTIFIER header. The PERF_SAMPLE_IDENTIFIER header is
471at a fixed offset from the event header, which allows reliable
472parsing of the header. Relying on ID may be ambiguous.
473IDENTIFIER is only supported by newer Linux kernels.
474
475Perf record specific events:
476
477In addition to the kernel generated event types perf record adds its
478own event types (in addition it also synthesizes some kernel events,
479for example MMAP events)
480
481 PERF_RECORD_USER_TYPE_START = 64,
482 PERF_RECORD_HEADER_ATTR = 64,
483
484struct attr_event {
485 struct perf_event_header header;
486 struct perf_event_attr attr;
487 uint64_t id[];
488};
489
490 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */
491
492#define MAX_EVENT_NAME 64
493
494struct perf_trace_event_type {
495 uint64_t event_id;
496 char name[MAX_EVENT_NAME];
497};
498
499struct event_type_event {
500 struct perf_event_header header;
501 struct perf_trace_event_type event_type;
502};
503
504
505 PERF_RECORD_HEADER_TRACING_DATA = 66,
506
507Describe me
508
509struct tracing_data_event {
510 struct perf_event_header header;
511 uint32_t size;
512};
513
514 PERF_RECORD_HEADER_BUILD_ID = 67,
515
516Define a ELF build ID for a referenced executable.
517
518 struct build_id_event; /* See above */
519
520 PERF_RECORD_FINISHED_ROUND = 68,
521
522No event reordering over this header. No payload.
523
524 PERF_RECORD_ID_INDEX = 69,
525
526Map event ids to CPUs and TIDs.
527
528struct id_index_entry {
529 uint64_t id;
530 uint64_t idx;
531 uint64_t cpu;
532 uint64_t tid;
533};
534
535struct id_index_event {
536 struct perf_event_header header;
537 uint64_t nr;
538 struct id_index_entry entries[nr];
539};
540
541 PERF_RECORD_AUXTRACE_INFO = 70,
542
543Auxtrace type specific information. Describe me
544
545struct auxtrace_info_event {
546 struct perf_event_header header;
547 uint32_t type;
548 uint32_t reserved__; /* For alignment */
549 uint64_t priv[];
550};
551
552 PERF_RECORD_AUXTRACE = 71,
553
554Defines auxtrace data. Followed by the actual data. The contents of
555the auxtrace data is dependent on the event and the CPU. For example
556for Intel Processor Trace it contains Processor Trace data generated
557by the CPU.
558
559struct auxtrace_event {
560 struct perf_event_header header;
561 uint64_t size;
562 uint64_t offset;
563 uint64_t reference;
564 uint32_t idx;
565 uint32_t tid;
566 uint32_t cpu;
567 uint32_t reserved__; /* For alignment */
568};
569
570struct aux_event {
571 struct perf_event_header header;
572 uint64_t aux_offset;
573 uint64_t aux_size;
574 uint64_t flags;
575};
576
577 PERF_RECORD_AUXTRACE_ERROR = 72,
578
579Describes an error in hardware tracing
580
581enum auxtrace_error_type {
582 PERF_AUXTRACE_ERROR_ITRACE = 1,
583 PERF_AUXTRACE_ERROR_MAX
584};
585
586#define MAX_AUXTRACE_ERROR_MSG 64
587
588struct auxtrace_error_event {
589 struct perf_event_header header;
590 uint32_t type;
591 uint32_t code;
592 uint32_t cpu;
593 uint32_t pid;
594 uint32_t tid;
595 uint32_t reserved__; /* For alignment */
596 uint64_t ip;
597 char msg[MAX_AUXTRACE_ERROR_MSG];
598};
599
600 PERF_RECORD_HEADER_FEATURE = 80,
601
602Describes a header feature. These are records used in pipe-mode that
603contain information that otherwise would be in perf.data file's header.
604
605 PERF_RECORD_COMPRESSED = 81,
606
607struct compressed_event {
608 struct perf_event_header header;
609 char data[];
610};
611
612 PERF_RECORD_FINISHED_INIT = 82,
613
614Marks the end of records for the system, pre-existing threads in system wide
615sessions, etc. Those are the ones prefixed PERF_RECORD_USER_*.
616
617This is used, for instance, to 'perf inject' events after init and before
618regular events, those emitted by the kernel, to support combining guest and
619host records.
620
621
622The header is followed by compressed data frame that can be decompressed
623into array of perf trace records. The size of the entire compressed event
624record including the header is limited by the max value of header.size.
625
626Event types
627
628Define the event attributes with their IDs.
629
630An array bound by the perf_file_section size.
631
632 struct {
633 struct perf_event_attr attr; /* Size defined by header.attr_size */
634 struct perf_file_section ids;
635 }
636
637ids points to a array of uint64_t defining the ids for event attr attr.
638
639Pipe-mode data
640
641Pipe-mode avoid seeks in the file by removing the perf_file_section and flags
642from the struct perf_header. The trimmed header is:
643
644struct perf_pipe_file_header {
645 u64 magic;
646 u64 size;
647};
648
649The information about attrs, data, and event_types is instead in the
650synthesized events PERF_RECORD_ATTR, PERF_RECORD_HEADER_TRACING_DATA,
651PERF_RECORD_HEADER_EVENT_TYPE, and PERF_RECORD_HEADER_FEATURE
652that are generated by perf record in pipe-mode.
653
654
655References:
656
657include/uapi/linux/perf_event.h
658
659This is the canonical description of the kernel generated perf_events
660and the perf_event_attrs.
661
662perf_events manpage
663
664A manpage describing perf_event and perf_event_attr is here:
665http://web.eece.maine.edu/~vweaver/projects/perf_events/programming.html
666This tends to be slightly behind the kernel include, but has better
667descriptions. An (typically older) version of the man page may be
668included with the standard Linux man pages, available with "man
669perf_events"
670
671pmu-tools
672
673https://github.com/andikleen/pmu-tools/tree/master/parser
674
675A definition of the perf.data format in python "construct" format is available
676in pmu-tools parser. This allows to read perf.data from python and dump it.
677
678quipper
679
680The quipper C++ parser is available at
681http://github.com/google/perf_data_converter/tree/master/src/quipper
682
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 not described here. The pipe version can be converted to
15normal perf.data with 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
46The header is followed by different optional headers, described by the bits set
47in flags. Only headers for which the bit is set are included. Each header
48consists of a perf_file_section located after the initial header.
49The respective perf_file_section points to the data of the additional
50header and defines its size.
51
52Some headers consist of strings, which are defined like this:
53
54struct perf_header_string {
55 uint32_t len;
56 char string[len]; /* zero terminated */
57};
58
59Some headers consist of a sequence of strings, which start with a
60
61struct perf_header_string_list {
62 uint32_t nr;
63 struct perf_header_string strings[nr]; /* variable length records */
64};
65
66The bits are the flags bits in a 256 bit bitmap starting with
67flags. These define the valid bits:
68
69 HEADER_RESERVED = 0, /* always cleared */
70 HEADER_FIRST_FEATURE = 1,
71 HEADER_TRACING_DATA = 1,
72
73Describe me.
74
75 HEADER_BUILD_ID = 2,
76
77The header consists of an sequence of build_id_event. The size of each record
78is defined by header.size (see perf_event.h). Each event defines a ELF build id
79for a executable file name for a pid. An ELF build id is a unique identifier
80assigned by the linker to an executable.
81
82struct build_id_event {
83 struct perf_event_header header;
84 pid_t pid;
85 uint8_t build_id[24];
86 char filename[header.size - offsetof(struct build_id_event, filename)];
87};
88
89 HEADER_HOSTNAME = 3,
90
91A perf_header_string with the hostname where the data was collected
92(uname -n)
93
94 HEADER_OSRELEASE = 4,
95
96A perf_header_string with the os release where the data was collected
97(uname -r)
98
99 HEADER_VERSION = 5,
100
101A perf_header_string with the perf user tool version where the
102data was collected. This is the same as the version of the source tree
103the perf tool was built from.
104
105 HEADER_ARCH = 6,
106
107A perf_header_string with the CPU architecture (uname -m)
108
109 HEADER_NRCPUS = 7,
110
111A structure defining the number of CPUs.
112
113struct nr_cpus {
114 uint32_t nr_cpus_online;
115 uint32_t nr_cpus_available; /* CPUs not yet onlined */
116};
117
118 HEADER_CPUDESC = 8,
119
120A perf_header_string with description of the CPU. On x86 this is the model name
121in /proc/cpuinfo
122
123 HEADER_CPUID = 9,
124
125A perf_header_string with the exact CPU type. On x86 this is
126vendor,family,model,stepping. For example: GenuineIntel,6,69,1
127
128 HEADER_TOTAL_MEM = 10,
129
130An uint64_t with the total memory in bytes.
131
132 HEADER_CMDLINE = 11,
133
134A perf_header_string with the perf command line used to collect the data.
135
136 HEADER_EVENT_DESC = 12,
137
138Another description of the perf_event_attrs, more detailed than header.attrs
139including IDs and names. See perf_event.h or the man page for a description
140of a struct perf_event_attr.
141
142struct {
143 uint32_t nr; /* number of events */
144 uint32_t attr_size; /* size of each perf_event_attr */
145 struct {
146 struct perf_event_attr attr; /* size of attr_size */
147 uint32_t nr_ids;
148 struct perf_header_string event_string;
149 uint64_t ids[nr_ids];
150 } events[nr]; /* Variable length records */
151};
152
153 HEADER_CPU_TOPOLOGY = 13,
154
155String lists defining the core and CPU threads topology.
156
157struct {
158 struct perf_header_string_list cores; /* Variable length */
159 struct perf_header_string_list threads; /* Variable length */
160};
161
162Example:
163 sibling cores : 0-3
164 sibling threads : 0-1
165 sibling threads : 2-3
166
167 HEADER_NUMA_TOPOLOGY = 14,
168
169 A list of NUMA node descriptions
170
171struct {
172 uint32_t nr;
173 struct {
174 uint32_t nodenr;
175 uint64_t mem_total;
176 uint64_t mem_free;
177 struct perf_header_string cpus;
178 } nodes[nr]; /* Variable length records */
179};
180
181 HEADER_BRANCH_STACK = 15,
182
183Not implemented in perf.
184
185 HEADER_PMU_MAPPINGS = 16,
186
187 A list of PMU structures, defining the different PMUs supported by perf.
188
189struct {
190 uint32_t nr;
191 struct pmu {
192 uint32_t pmu_type;
193 struct perf_header_string pmu_name;
194 } [nr]; /* Variable length records */
195};
196
197 HEADER_GROUP_DESC = 17,
198
199 Description of counter groups ({...} in perf syntax)
200
201struct {
202 uint32_t nr;
203 struct {
204 struct perf_header_string string;
205 uint32_t leader_idx;
206 uint32_t nr_members;
207 } [nr]; /* Variable length records */
208};
209
210 HEADER_AUXTRACE = 18,
211
212Define additional auxtrace areas in the perf.data. auxtrace is used to store
213undecoded hardware tracing information, such as Intel Processor Trace data.
214
215/**
216 * struct auxtrace_index_entry - indexes a AUX area tracing event within a
217 * perf.data file.
218 * @file_offset: offset within the perf.data file
219 * @sz: size of the event
220 */
221struct auxtrace_index_entry {
222 u64 file_offset;
223 u64 sz;
224};
225
226#define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
227
228/**
229 * struct auxtrace_index - index of AUX area tracing events within a perf.data
230 * file.
231 * @list: linking a number of arrays of entries
232 * @nr: number of entries
233 * @entries: array of entries
234 */
235struct auxtrace_index {
236 struct list_head list;
237 size_t nr;
238 struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
239};
240
241 other bits are reserved and should ignored for now
242 HEADER_FEAT_BITS = 256,
243
244Attributes
245
246This is an array of perf_event_attrs, each attr_size bytes long, which defines
247each event collected. See perf_event.h or the man page for a detailed
248description.
249
250Data
251
252This section is the bulk of the file. It consist of a stream of perf_events
253describing events. This matches the format generated by the kernel.
254See perf_event.h or the manpage for a detailed description.
255
256Some notes on parsing:
257
258Ordering
259
260The events are not necessarily in time stamp order, as they can be
261collected in parallel on different CPUs. If the events should be
262processed in time order they need to be sorted first. It is possible
263to only do a partial sort using the FINISHED_ROUND event header (see
264below). perf record guarantees that there is no reordering over a
265FINISHED_ROUND.
266
267ID vs IDENTIFIER
268
269When the event stream contains multiple events each event is identified
270by an ID. This can be either through the PERF_SAMPLE_ID or the
271PERF_SAMPLE_IDENTIFIER header. The PERF_SAMPLE_IDENTIFIER header is
272at a fixed offset from the event header, which allows reliable
273parsing of the header. Relying on ID may be ambigious.
274IDENTIFIER is only supported by newer Linux kernels.
275
276Perf record specific events:
277
278In addition to the kernel generated event types perf record adds its
279own event types (in addition it also synthesizes some kernel events,
280for example MMAP events)
281
282 PERF_RECORD_USER_TYPE_START = 64,
283 PERF_RECORD_HEADER_ATTR = 64,
284
285struct attr_event {
286 struct perf_event_header header;
287 struct perf_event_attr attr;
288 uint64_t id[];
289};
290
291 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
292
293#define MAX_EVENT_NAME 64
294
295struct perf_trace_event_type {
296 uint64_t event_id;
297 char name[MAX_EVENT_NAME];
298};
299
300struct event_type_event {
301 struct perf_event_header header;
302 struct perf_trace_event_type event_type;
303};
304
305
306 PERF_RECORD_HEADER_TRACING_DATA = 66,
307
308Describe me
309
310struct tracing_data_event {
311 struct perf_event_header header;
312 uint32_t size;
313};
314
315 PERF_RECORD_HEADER_BUILD_ID = 67,
316
317Define a ELF build ID for a referenced executable.
318
319 struct build_id_event; /* See above */
320
321 PERF_RECORD_FINISHED_ROUND = 68,
322
323No event reordering over this header. No payload.
324
325 PERF_RECORD_ID_INDEX = 69,
326
327Map event ids to CPUs and TIDs.
328
329struct id_index_entry {
330 uint64_t id;
331 uint64_t idx;
332 uint64_t cpu;
333 uint64_t tid;
334};
335
336struct id_index_event {
337 struct perf_event_header header;
338 uint64_t nr;
339 struct id_index_entry entries[nr];
340};
341
342 PERF_RECORD_AUXTRACE_INFO = 70,
343
344Auxtrace type specific information. Describe me
345
346struct auxtrace_info_event {
347 struct perf_event_header header;
348 uint32_t type;
349 uint32_t reserved__; /* For alignment */
350 uint64_t priv[];
351};
352
353 PERF_RECORD_AUXTRACE = 71,
354
355Defines auxtrace data. Followed by the actual data. The contents of
356the auxtrace data is dependent on the event and the CPU. For example
357for Intel Processor Trace it contains Processor Trace data generated
358by the CPU.
359
360struct auxtrace_event {
361 struct perf_event_header header;
362 uint64_t size;
363 uint64_t offset;
364 uint64_t reference;
365 uint32_t idx;
366 uint32_t tid;
367 uint32_t cpu;
368 uint32_t reserved__; /* For alignment */
369};
370
371struct aux_event {
372 struct perf_event_header header;
373 uint64_t aux_offset;
374 uint64_t aux_size;
375 uint64_t flags;
376};
377
378 PERF_RECORD_AUXTRACE_ERROR = 72,
379
380Describes an error in hardware tracing
381
382enum auxtrace_error_type {
383 PERF_AUXTRACE_ERROR_ITRACE = 1,
384 PERF_AUXTRACE_ERROR_MAX
385};
386
387#define MAX_AUXTRACE_ERROR_MSG 64
388
389struct auxtrace_error_event {
390 struct perf_event_header header;
391 uint32_t type;
392 uint32_t code;
393 uint32_t cpu;
394 uint32_t pid;
395 uint32_t tid;
396 uint32_t reserved__; /* For alignment */
397 uint64_t ip;
398 char msg[MAX_AUXTRACE_ERROR_MSG];
399};
400
401Event types
402
403Define the event attributes with their IDs.
404
405An array bound by the perf_file_section size.
406
407 struct {
408 struct perf_event_attr attr; /* Size defined by header.attr_size */
409 struct perf_file_section ids;
410 }
411
412ids points to a array of uint64_t defining the ids for event attr attr.
413
414References:
415
416include/uapi/linux/perf_event.h
417
418This is the canonical description of the kernel generated perf_events
419and the perf_event_attrs.
420
421perf_events manpage
422
423A manpage describing perf_event and perf_event_attr is here:
424http://web.eece.maine.edu/~vweaver/projects/perf_events/programming.html
425This tends to be slightly behind the kernel include, but has better
426descriptions. An (typically older) version of the man page may be
427included with the standard Linux man pages, available with "man
428perf_events"
429
430pmu-tools
431
432https://github.com/andikleen/pmu-tools/tree/master/parser
433
434A definition of the perf.data format in python "construct" format is available
435in pmu-tools parser. This allows to read perf.data from python and dump it.
436
437quipper
438
439The quipper C++ parser is available at
440https://chromium.googlesource.com/chromiumos/platform2
441
442It is under the chromiumos-wide-profiling/ subdirectory. This library can
443convert a perf data file to a protobuf and vice versa.
444
445Unfortunately this parser tends to be many versions behind and may not be able
446to parse data files generated by recent perf.