perf.data-file-format.txt 17 KB

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