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