perf.data-file-format.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 not described here. The pipe version can be converted to
  10. normal perf.data with 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_online;
  82. uint32_t nr_cpus_available; /* CPUs not yet onlined */
  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. struct {
  111. struct perf_header_string_list cores; /* Variable length */
  112. struct perf_header_string_list threads; /* Variable length */
  113. };
  114. Example:
  115. sibling cores : 0-3
  116. sibling threads : 0-1
  117. sibling threads : 2-3
  118. HEADER_NUMA_TOPOLOGY = 14,
  119. A list of NUMA node descriptions
  120. struct {
  121. uint32_t nr;
  122. struct {
  123. uint32_t nodenr;
  124. uint64_t mem_total;
  125. uint64_t mem_free;
  126. struct perf_header_string cpus;
  127. } nodes[nr]; /* Variable length records */
  128. };
  129. HEADER_BRANCH_STACK = 15,
  130. Not implemented in perf.
  131. HEADER_PMU_MAPPINGS = 16,
  132. A list of PMU structures, defining the different PMUs supported by perf.
  133. struct {
  134. uint32_t nr;
  135. struct pmu {
  136. uint32_t pmu_type;
  137. struct perf_header_string pmu_name;
  138. } [nr]; /* Variable length records */
  139. };
  140. HEADER_GROUP_DESC = 17,
  141. Description of counter groups ({...} in perf syntax)
  142. struct {
  143. uint32_t nr;
  144. struct {
  145. struct perf_header_string string;
  146. uint32_t leader_idx;
  147. uint32_t nr_members;
  148. } [nr]; /* Variable length records */
  149. };
  150. HEADER_AUXTRACE = 18,
  151. Define additional auxtrace areas in the perf.data. auxtrace is used to store
  152. undecoded hardware tracing information, such as Intel Processor Trace data.
  153. /**
  154. * struct auxtrace_index_entry - indexes a AUX area tracing event within a
  155. * perf.data file.
  156. * @file_offset: offset within the perf.data file
  157. * @sz: size of the event
  158. */
  159. struct auxtrace_index_entry {
  160. u64 file_offset;
  161. u64 sz;
  162. };
  163. #define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
  164. /**
  165. * struct auxtrace_index - index of AUX area tracing events within a perf.data
  166. * file.
  167. * @list: linking a number of arrays of entries
  168. * @nr: number of entries
  169. * @entries: array of entries
  170. */
  171. struct auxtrace_index {
  172. struct list_head list;
  173. size_t nr;
  174. struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
  175. };
  176. other bits are reserved and should ignored for now
  177. HEADER_FEAT_BITS = 256,
  178. Attributes
  179. This is an array of perf_event_attrs, each attr_size bytes long, which defines
  180. each event collected. See perf_event.h or the man page for a detailed
  181. description.
  182. Data
  183. This section is the bulk of the file. It consist of a stream of perf_events
  184. describing events. This matches the format generated by the kernel.
  185. See perf_event.h or the manpage for a detailed description.
  186. Some notes on parsing:
  187. Ordering
  188. The events are not necessarily in time stamp order, as they can be
  189. collected in parallel on different CPUs. If the events should be
  190. processed in time order they need to be sorted first. It is possible
  191. to only do a partial sort using the FINISHED_ROUND event header (see
  192. below). perf record guarantees that there is no reordering over a
  193. FINISHED_ROUND.
  194. ID vs IDENTIFIER
  195. When the event stream contains multiple events each event is identified
  196. by an ID. This can be either through the PERF_SAMPLE_ID or the
  197. PERF_SAMPLE_IDENTIFIER header. The PERF_SAMPLE_IDENTIFIER header is
  198. at a fixed offset from the event header, which allows reliable
  199. parsing of the header. Relying on ID may be ambigious.
  200. IDENTIFIER is only supported by newer Linux kernels.
  201. Perf record specific events:
  202. In addition to the kernel generated event types perf record adds its
  203. own event types (in addition it also synthesizes some kernel events,
  204. for example MMAP events)
  205. PERF_RECORD_USER_TYPE_START = 64,
  206. PERF_RECORD_HEADER_ATTR = 64,
  207. struct attr_event {
  208. struct perf_event_header header;
  209. struct perf_event_attr attr;
  210. uint64_t id[];
  211. };
  212. PERF_RECORD_HEADER_EVENT_TYPE = 65, /* depreceated */
  213. #define MAX_EVENT_NAME 64
  214. struct perf_trace_event_type {
  215. uint64_t event_id;
  216. char name[MAX_EVENT_NAME];
  217. };
  218. struct event_type_event {
  219. struct perf_event_header header;
  220. struct perf_trace_event_type event_type;
  221. };
  222. PERF_RECORD_HEADER_TRACING_DATA = 66,
  223. Describe me
  224. struct tracing_data_event {
  225. struct perf_event_header header;
  226. uint32_t size;
  227. };
  228. PERF_RECORD_HEADER_BUILD_ID = 67,
  229. Define a ELF build ID for a referenced executable.
  230. struct build_id_event; /* See above */
  231. PERF_RECORD_FINISHED_ROUND = 68,
  232. No event reordering over this header. No payload.
  233. PERF_RECORD_ID_INDEX = 69,
  234. Map event ids to CPUs and TIDs.
  235. struct id_index_entry {
  236. uint64_t id;
  237. uint64_t idx;
  238. uint64_t cpu;
  239. uint64_t tid;
  240. };
  241. struct id_index_event {
  242. struct perf_event_header header;
  243. uint64_t nr;
  244. struct id_index_entry entries[nr];
  245. };
  246. PERF_RECORD_AUXTRACE_INFO = 70,
  247. Auxtrace type specific information. Describe me
  248. struct auxtrace_info_event {
  249. struct perf_event_header header;
  250. uint32_t type;
  251. uint32_t reserved__; /* For alignment */
  252. uint64_t priv[];
  253. };
  254. PERF_RECORD_AUXTRACE = 71,
  255. Defines auxtrace data. Followed by the actual data. The contents of
  256. the auxtrace data is dependent on the event and the CPU. For example
  257. for Intel Processor Trace it contains Processor Trace data generated
  258. by the CPU.
  259. struct auxtrace_event {
  260. struct perf_event_header header;
  261. uint64_t size;
  262. uint64_t offset;
  263. uint64_t reference;
  264. uint32_t idx;
  265. uint32_t tid;
  266. uint32_t cpu;
  267. uint32_t reserved__; /* For alignment */
  268. };
  269. struct aux_event {
  270. struct perf_event_header header;
  271. uint64_t aux_offset;
  272. uint64_t aux_size;
  273. uint64_t flags;
  274. };
  275. PERF_RECORD_AUXTRACE_ERROR = 72,
  276. Describes an error in hardware tracing
  277. enum auxtrace_error_type {
  278. PERF_AUXTRACE_ERROR_ITRACE = 1,
  279. PERF_AUXTRACE_ERROR_MAX
  280. };
  281. #define MAX_AUXTRACE_ERROR_MSG 64
  282. struct auxtrace_error_event {
  283. struct perf_event_header header;
  284. uint32_t type;
  285. uint32_t code;
  286. uint32_t cpu;
  287. uint32_t pid;
  288. uint32_t tid;
  289. uint32_t reserved__; /* For alignment */
  290. uint64_t ip;
  291. char msg[MAX_AUXTRACE_ERROR_MSG];
  292. };
  293. Event types
  294. Define the event attributes with their IDs.
  295. An array bound by the perf_file_section size.
  296. struct {
  297. struct perf_event_attr attr; /* Size defined by header.attr_size */
  298. struct perf_file_section ids;
  299. }
  300. ids points to a array of uint64_t defining the ids for event attr attr.
  301. References:
  302. include/uapi/linux/perf_event.h
  303. This is the canonical description of the kernel generated perf_events
  304. and the perf_event_attrs.
  305. perf_events manpage
  306. A manpage describing perf_event and perf_event_attr is here:
  307. http://web.eece.maine.edu/~vweaver/projects/perf_events/programming.html
  308. This tends to be slightly behind the kernel include, but has better
  309. descriptions. An (typically older) version of the man page may be
  310. included with the standard Linux man pages, available with "man
  311. perf_events"
  312. pmu-tools
  313. https://github.com/andikleen/pmu-tools/tree/master/parser
  314. A definition of the perf.data format in python "construct" format is available
  315. in pmu-tools parser. This allows to read perf.data from python and dump it.
  316. quipper
  317. The quipper C++ parser is available at
  318. https://chromium.googlesource.com/chromiumos/platform2
  319. It is under the chromiumos-wide-profiling/ subdirectory. This library can
  320. convert a perf data file to a protobuf and vice versa.
  321. Unfortunately this parser tends to be many versions behind and may not be able
  322. to parse data files generated by recent perf.