perf.data-file-format.txt 13 KB

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