perf.data-file-format.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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 bpf_prog_info_linear, 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. other bits are reserved and should ignored for now
  297. HEADER_FEAT_BITS = 256,
  298. Attributes
  299. This is an array of perf_event_attrs, each attr_size bytes long, which defines
  300. each event collected. See perf_event.h or the man page for a detailed
  301. description.
  302. Data
  303. This section is the bulk of the file. It consist of a stream of perf_events
  304. describing events. This matches the format generated by the kernel.
  305. See perf_event.h or the manpage for a detailed description.
  306. Some notes on parsing:
  307. Ordering
  308. The events are not necessarily in time stamp order, as they can be
  309. collected in parallel on different CPUs. If the events should be
  310. processed in time order they need to be sorted first. It is possible
  311. to only do a partial sort using the FINISHED_ROUND event header (see
  312. below). perf record guarantees that there is no reordering over a
  313. FINISHED_ROUND.
  314. ID vs IDENTIFIER
  315. When the event stream contains multiple events each event is identified
  316. by an ID. This can be either through the PERF_SAMPLE_ID or the
  317. PERF_SAMPLE_IDENTIFIER header. The PERF_SAMPLE_IDENTIFIER header is
  318. at a fixed offset from the event header, which allows reliable
  319. parsing of the header. Relying on ID may be ambiguous.
  320. IDENTIFIER is only supported by newer Linux kernels.
  321. Perf record specific events:
  322. In addition to the kernel generated event types perf record adds its
  323. own event types (in addition it also synthesizes some kernel events,
  324. for example MMAP events)
  325. PERF_RECORD_USER_TYPE_START = 64,
  326. PERF_RECORD_HEADER_ATTR = 64,
  327. struct attr_event {
  328. struct perf_event_header header;
  329. struct perf_event_attr attr;
  330. uint64_t id[];
  331. };
  332. PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */
  333. #define MAX_EVENT_NAME 64
  334. struct perf_trace_event_type {
  335. uint64_t event_id;
  336. char name[MAX_EVENT_NAME];
  337. };
  338. struct event_type_event {
  339. struct perf_event_header header;
  340. struct perf_trace_event_type event_type;
  341. };
  342. PERF_RECORD_HEADER_TRACING_DATA = 66,
  343. Describe me
  344. struct tracing_data_event {
  345. struct perf_event_header header;
  346. uint32_t size;
  347. };
  348. PERF_RECORD_HEADER_BUILD_ID = 67,
  349. Define a ELF build ID for a referenced executable.
  350. struct build_id_event; /* See above */
  351. PERF_RECORD_FINISHED_ROUND = 68,
  352. No event reordering over this header. No payload.
  353. PERF_RECORD_ID_INDEX = 69,
  354. Map event ids to CPUs and TIDs.
  355. struct id_index_entry {
  356. uint64_t id;
  357. uint64_t idx;
  358. uint64_t cpu;
  359. uint64_t tid;
  360. };
  361. struct id_index_event {
  362. struct perf_event_header header;
  363. uint64_t nr;
  364. struct id_index_entry entries[nr];
  365. };
  366. PERF_RECORD_AUXTRACE_INFO = 70,
  367. Auxtrace type specific information. Describe me
  368. struct auxtrace_info_event {
  369. struct perf_event_header header;
  370. uint32_t type;
  371. uint32_t reserved__; /* For alignment */
  372. uint64_t priv[];
  373. };
  374. PERF_RECORD_AUXTRACE = 71,
  375. Defines auxtrace data. Followed by the actual data. The contents of
  376. the auxtrace data is dependent on the event and the CPU. For example
  377. for Intel Processor Trace it contains Processor Trace data generated
  378. by the CPU.
  379. struct auxtrace_event {
  380. struct perf_event_header header;
  381. uint64_t size;
  382. uint64_t offset;
  383. uint64_t reference;
  384. uint32_t idx;
  385. uint32_t tid;
  386. uint32_t cpu;
  387. uint32_t reserved__; /* For alignment */
  388. };
  389. struct aux_event {
  390. struct perf_event_header header;
  391. uint64_t aux_offset;
  392. uint64_t aux_size;
  393. uint64_t flags;
  394. };
  395. PERF_RECORD_AUXTRACE_ERROR = 72,
  396. Describes an error in hardware tracing
  397. enum auxtrace_error_type {
  398. PERF_AUXTRACE_ERROR_ITRACE = 1,
  399. PERF_AUXTRACE_ERROR_MAX
  400. };
  401. #define MAX_AUXTRACE_ERROR_MSG 64
  402. struct auxtrace_error_event {
  403. struct perf_event_header header;
  404. uint32_t type;
  405. uint32_t code;
  406. uint32_t cpu;
  407. uint32_t pid;
  408. uint32_t tid;
  409. uint32_t reserved__; /* For alignment */
  410. uint64_t ip;
  411. char msg[MAX_AUXTRACE_ERROR_MSG];
  412. };
  413. PERF_RECORD_HEADER_FEATURE = 80,
  414. Describes a header feature. These are records used in pipe-mode that
  415. contain information that otherwise would be in perf.data file's header.
  416. PERF_RECORD_COMPRESSED = 81,
  417. struct compressed_event {
  418. struct perf_event_header header;
  419. char data[];
  420. };
  421. The header is followed by compressed data frame that can be decompressed
  422. into array of perf trace records. The size of the entire compressed event
  423. record including the header is limited by the max value of header.size.
  424. Event types
  425. Define the event attributes with their IDs.
  426. An array bound by the perf_file_section size.
  427. struct {
  428. struct perf_event_attr attr; /* Size defined by header.attr_size */
  429. struct perf_file_section ids;
  430. }
  431. ids points to a array of uint64_t defining the ids for event attr attr.
  432. Pipe-mode data
  433. Pipe-mode avoid seeks in the file by removing the perf_file_section and flags
  434. from the struct perf_header. The trimmed header is:
  435. struct perf_pipe_file_header {
  436. u64 magic;
  437. u64 size;
  438. };
  439. The information about attrs, data, and event_types is instead in the
  440. synthesized events PERF_RECORD_ATTR, PERF_RECORD_HEADER_TRACING_DATA,
  441. PERF_RECORD_HEADER_EVENT_TYPE, and PERF_RECORD_HEADER_FEATURE
  442. that are generated by perf record in pipe-mode.
  443. References:
  444. include/uapi/linux/perf_event.h
  445. This is the canonical description of the kernel generated perf_events
  446. and the perf_event_attrs.
  447. perf_events manpage
  448. A manpage describing perf_event and perf_event_attr is here:
  449. http://web.eece.maine.edu/~vweaver/projects/perf_events/programming.html
  450. This tends to be slightly behind the kernel include, but has better
  451. descriptions. An (typically older) version of the man page may be
  452. included with the standard Linux man pages, available with "man
  453. perf_events"
  454. pmu-tools
  455. https://github.com/andikleen/pmu-tools/tree/master/parser
  456. A definition of the perf.data format in python "construct" format is available
  457. in pmu-tools parser. This allows to read perf.data from python and dump it.
  458. quipper
  459. The quipper C++ parser is available at
  460. http://github.com/google/perf_data_converter/tree/master/src/quipper