1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LIBPERF_EVENT_H 3 #define __LIBPERF_EVENT_H 4 5 #include <linux/perf_event.h> 6 #include <linux/types.h> 7 #include <linux/limits.h> 8 #include <linux/bpf.h> 9 #include <sys/types.h> /* pid_t */ 10 11 struct perf_record_mmap { 12 struct perf_event_header header; 13 __u32 pid, tid; 14 __u64 start; 15 __u64 len; 16 __u64 pgoff; 17 char filename[PATH_MAX]; 18 }; 19 20 struct perf_record_mmap2 { 21 struct perf_event_header header; 22 __u32 pid, tid; 23 __u64 start; 24 __u64 len; 25 __u64 pgoff; 26 __u32 maj; 27 __u32 min; 28 __u64 ino; 29 __u64 ino_generation; 30 __u32 prot; 31 __u32 flags; 32 char filename[PATH_MAX]; 33 }; 34 35 struct perf_record_comm { 36 struct perf_event_header header; 37 __u32 pid, tid; 38 char comm[16]; 39 }; 40 41 struct perf_record_namespaces { 42 struct perf_event_header header; 43 __u32 pid, tid; 44 __u64 nr_namespaces; 45 struct perf_ns_link_info link_info[]; 46 }; 47 48 struct perf_record_fork { 49 struct perf_event_header header; 50 __u32 pid, ppid; 51 __u32 tid, ptid; 52 __u64 time; 53 }; 54 55 struct perf_record_lost { 56 struct perf_event_header header; 57 __u64 id; 58 __u64 lost; 59 }; 60 61 struct perf_record_lost_samples { 62 struct perf_event_header header; 63 __u64 lost; 64 }; 65 66 /* 67 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID 68 */ 69 struct perf_record_read { 70 struct perf_event_header header; 71 __u32 pid, tid; 72 __u64 value; 73 __u64 time_enabled; 74 __u64 time_running; 75 __u64 id; 76 }; 77 78 struct perf_record_throttle { 79 struct perf_event_header header; 80 __u64 time; 81 __u64 id; 82 __u64 stream_id; 83 }; 84 85 #ifndef KSYM_NAME_LEN 86 #define KSYM_NAME_LEN 256 87 #endif 88 89 struct perf_record_ksymbol { 90 struct perf_event_header header; 91 __u64 addr; 92 __u32 len; 93 __u16 ksym_type; 94 __u16 flags; 95 char name[KSYM_NAME_LEN]; 96 }; 97 98 struct perf_record_bpf_event { 99 struct perf_event_header header; 100 __u16 type; 101 __u16 flags; 102 __u32 id; 103 104 /* for bpf_prog types */ 105 __u8 tag[BPF_TAG_SIZE]; // prog tag 106 }; 107 108 struct perf_record_sample { 109 struct perf_event_header header; 110 __u64 array[]; 111 }; 112 113 struct perf_record_switch { 114 struct perf_event_header header; 115 __u32 next_prev_pid; 116 __u32 next_prev_tid; 117 }; 118 119 struct perf_record_header_attr { 120 struct perf_event_header header; 121 struct perf_event_attr attr; 122 __u64 id[]; 123 }; 124 125 enum { 126 PERF_CPU_MAP__CPUS = 0, 127 PERF_CPU_MAP__MASK = 1, 128 }; 129 130 struct cpu_map_entries { 131 __u16 nr; 132 __u16 cpu[]; 133 }; 134 135 struct perf_record_record_cpu_map { 136 __u16 nr; 137 __u16 long_size; 138 unsigned long mask[]; 139 }; 140 141 struct perf_record_cpu_map_data { 142 __u16 type; 143 char data[]; 144 }; 145 146 struct perf_record_cpu_map { 147 struct perf_event_header header; 148 struct perf_record_cpu_map_data data; 149 }; 150 151 enum { 152 PERF_EVENT_UPDATE__UNIT = 0, 153 PERF_EVENT_UPDATE__SCALE = 1, 154 PERF_EVENT_UPDATE__NAME = 2, 155 PERF_EVENT_UPDATE__CPUS = 3, 156 }; 157 158 struct perf_record_event_update_cpus { 159 struct perf_record_cpu_map_data cpus; 160 }; 161 162 struct perf_record_event_update_scale { 163 double scale; 164 }; 165 166 struct perf_record_event_update { 167 struct perf_event_header header; 168 __u64 type; 169 __u64 id; 170 char data[]; 171 }; 172 173 #define MAX_EVENT_NAME 64 174 175 struct perf_trace_event_type { 176 __u64 event_id; 177 char name[MAX_EVENT_NAME]; 178 }; 179 180 struct perf_record_header_event_type { 181 struct perf_event_header header; 182 struct perf_trace_event_type event_type; 183 }; 184 185 struct perf_record_header_tracing_data { 186 struct perf_event_header header; 187 __u32 size; 188 }; 189 190 struct perf_record_header_build_id { 191 struct perf_event_header header; 192 pid_t pid; 193 __u8 build_id[24]; 194 char filename[]; 195 }; 196 197 struct id_index_entry { 198 __u64 id; 199 __u64 idx; 200 __u64 cpu; 201 __u64 tid; 202 }; 203 204 struct perf_record_id_index { 205 struct perf_event_header header; 206 __u64 nr; 207 struct id_index_entry entries[0]; 208 }; 209 210 struct perf_record_auxtrace_info { 211 struct perf_event_header header; 212 __u32 type; 213 __u32 reserved__; /* For alignment */ 214 __u64 priv[]; 215 }; 216 217 struct perf_record_auxtrace { 218 struct perf_event_header header; 219 __u64 size; 220 __u64 offset; 221 __u64 reference; 222 __u32 idx; 223 __u32 tid; 224 __u32 cpu; 225 __u32 reserved__; /* For alignment */ 226 }; 227 228 #define MAX_AUXTRACE_ERROR_MSG 64 229 230 struct perf_record_auxtrace_error { 231 struct perf_event_header header; 232 __u32 type; 233 __u32 code; 234 __u32 cpu; 235 __u32 pid; 236 __u32 tid; 237 __u32 fmt; 238 __u64 ip; 239 __u64 time; 240 char msg[MAX_AUXTRACE_ERROR_MSG]; 241 }; 242 243 struct perf_record_aux { 244 struct perf_event_header header; 245 __u64 aux_offset; 246 __u64 aux_size; 247 __u64 flags; 248 }; 249 250 struct perf_record_itrace_start { 251 struct perf_event_header header; 252 __u32 pid; 253 __u32 tid; 254 }; 255 256 struct perf_record_thread_map_entry { 257 __u64 pid; 258 char comm[16]; 259 }; 260 261 struct perf_record_thread_map { 262 struct perf_event_header header; 263 __u64 nr; 264 struct perf_record_thread_map_entry entries[]; 265 }; 266 267 enum { 268 PERF_STAT_CONFIG_TERM__AGGR_MODE = 0, 269 PERF_STAT_CONFIG_TERM__INTERVAL = 1, 270 PERF_STAT_CONFIG_TERM__SCALE = 2, 271 PERF_STAT_CONFIG_TERM__MAX = 3, 272 }; 273 274 struct perf_record_stat_config_entry { 275 __u64 tag; 276 __u64 val; 277 }; 278 279 struct perf_record_stat_config { 280 struct perf_event_header header; 281 __u64 nr; 282 struct perf_record_stat_config_entry data[]; 283 }; 284 285 struct perf_record_stat { 286 struct perf_event_header header; 287 288 __u64 id; 289 __u32 cpu; 290 __u32 thread; 291 292 union { 293 struct { 294 __u64 val; 295 __u64 ena; 296 __u64 run; 297 }; 298 __u64 values[3]; 299 }; 300 }; 301 302 struct perf_record_stat_round { 303 struct perf_event_header header; 304 __u64 type; 305 __u64 time; 306 }; 307 308 struct perf_record_time_conv { 309 struct perf_event_header header; 310 __u64 time_shift; 311 __u64 time_mult; 312 __u64 time_zero; 313 }; 314 315 struct perf_record_header_feature { 316 struct perf_event_header header; 317 __u64 feat_id; 318 char data[]; 319 }; 320 321 struct perf_record_compressed { 322 struct perf_event_header header; 323 char data[]; 324 }; 325 326 enum perf_user_event_type { /* above any possible kernel type */ 327 PERF_RECORD_USER_TYPE_START = 64, 328 PERF_RECORD_HEADER_ATTR = 64, 329 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */ 330 PERF_RECORD_HEADER_TRACING_DATA = 66, 331 PERF_RECORD_HEADER_BUILD_ID = 67, 332 PERF_RECORD_FINISHED_ROUND = 68, 333 PERF_RECORD_ID_INDEX = 69, 334 PERF_RECORD_AUXTRACE_INFO = 70, 335 PERF_RECORD_AUXTRACE = 71, 336 PERF_RECORD_AUXTRACE_ERROR = 72, 337 PERF_RECORD_THREAD_MAP = 73, 338 PERF_RECORD_CPU_MAP = 74, 339 PERF_RECORD_STAT_CONFIG = 75, 340 PERF_RECORD_STAT = 76, 341 PERF_RECORD_STAT_ROUND = 77, 342 PERF_RECORD_EVENT_UPDATE = 78, 343 PERF_RECORD_TIME_CONV = 79, 344 PERF_RECORD_HEADER_FEATURE = 80, 345 PERF_RECORD_COMPRESSED = 81, 346 PERF_RECORD_HEADER_MAX 347 }; 348 349 union perf_event { 350 struct perf_event_header header; 351 struct perf_record_mmap mmap; 352 struct perf_record_mmap2 mmap2; 353 struct perf_record_comm comm; 354 struct perf_record_namespaces namespaces; 355 struct perf_record_fork fork; 356 struct perf_record_lost lost; 357 struct perf_record_lost_samples lost_samples; 358 struct perf_record_read read; 359 struct perf_record_throttle throttle; 360 struct perf_record_sample sample; 361 struct perf_record_bpf_event bpf; 362 struct perf_record_ksymbol ksymbol; 363 struct perf_record_header_attr attr; 364 struct perf_record_event_update event_update; 365 struct perf_record_header_event_type event_type; 366 struct perf_record_header_tracing_data tracing_data; 367 struct perf_record_header_build_id build_id; 368 struct perf_record_id_index id_index; 369 struct perf_record_auxtrace_info auxtrace_info; 370 struct perf_record_auxtrace auxtrace; 371 struct perf_record_auxtrace_error auxtrace_error; 372 struct perf_record_aux aux; 373 struct perf_record_itrace_start itrace_start; 374 struct perf_record_switch context_switch; 375 struct perf_record_thread_map thread_map; 376 struct perf_record_cpu_map cpu_map; 377 struct perf_record_stat_config stat_config; 378 struct perf_record_stat stat; 379 struct perf_record_stat_round stat_round; 380 struct perf_record_time_conv time_conv; 381 struct perf_record_header_feature feat; 382 struct perf_record_compressed pack; 383 }; 384 385 #endif /* __LIBPERF_EVENT_H */ 386