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_cgroup { 109 struct perf_event_header header; 110 __u64 id; 111 char path[PATH_MAX]; 112 }; 113 114 struct perf_record_sample { 115 struct perf_event_header header; 116 __u64 array[]; 117 }; 118 119 struct perf_record_switch { 120 struct perf_event_header header; 121 __u32 next_prev_pid; 122 __u32 next_prev_tid; 123 }; 124 125 struct perf_record_header_attr { 126 struct perf_event_header header; 127 struct perf_event_attr attr; 128 __u64 id[]; 129 }; 130 131 enum { 132 PERF_CPU_MAP__CPUS = 0, 133 PERF_CPU_MAP__MASK = 1, 134 }; 135 136 struct cpu_map_entries { 137 __u16 nr; 138 __u16 cpu[]; 139 }; 140 141 struct perf_record_record_cpu_map { 142 __u16 nr; 143 __u16 long_size; 144 unsigned long mask[]; 145 }; 146 147 struct perf_record_cpu_map_data { 148 __u16 type; 149 char data[]; 150 }; 151 152 struct perf_record_cpu_map { 153 struct perf_event_header header; 154 struct perf_record_cpu_map_data data; 155 }; 156 157 enum { 158 PERF_EVENT_UPDATE__UNIT = 0, 159 PERF_EVENT_UPDATE__SCALE = 1, 160 PERF_EVENT_UPDATE__NAME = 2, 161 PERF_EVENT_UPDATE__CPUS = 3, 162 }; 163 164 struct perf_record_event_update_cpus { 165 struct perf_record_cpu_map_data cpus; 166 }; 167 168 struct perf_record_event_update_scale { 169 double scale; 170 }; 171 172 struct perf_record_event_update { 173 struct perf_event_header header; 174 __u64 type; 175 __u64 id; 176 char data[]; 177 }; 178 179 #define MAX_EVENT_NAME 64 180 181 struct perf_trace_event_type { 182 __u64 event_id; 183 char name[MAX_EVENT_NAME]; 184 }; 185 186 struct perf_record_header_event_type { 187 struct perf_event_header header; 188 struct perf_trace_event_type event_type; 189 }; 190 191 struct perf_record_header_tracing_data { 192 struct perf_event_header header; 193 __u32 size; 194 }; 195 196 struct perf_record_header_build_id { 197 struct perf_event_header header; 198 pid_t pid; 199 __u8 build_id[24]; 200 char filename[]; 201 }; 202 203 struct id_index_entry { 204 __u64 id; 205 __u64 idx; 206 __u64 cpu; 207 __u64 tid; 208 }; 209 210 struct perf_record_id_index { 211 struct perf_event_header header; 212 __u64 nr; 213 struct id_index_entry entries[0]; 214 }; 215 216 struct perf_record_auxtrace_info { 217 struct perf_event_header header; 218 __u32 type; 219 __u32 reserved__; /* For alignment */ 220 __u64 priv[]; 221 }; 222 223 struct perf_record_auxtrace { 224 struct perf_event_header header; 225 __u64 size; 226 __u64 offset; 227 __u64 reference; 228 __u32 idx; 229 __u32 tid; 230 __u32 cpu; 231 __u32 reserved__; /* For alignment */ 232 }; 233 234 #define MAX_AUXTRACE_ERROR_MSG 64 235 236 struct perf_record_auxtrace_error { 237 struct perf_event_header header; 238 __u32 type; 239 __u32 code; 240 __u32 cpu; 241 __u32 pid; 242 __u32 tid; 243 __u32 fmt; 244 __u64 ip; 245 __u64 time; 246 char msg[MAX_AUXTRACE_ERROR_MSG]; 247 }; 248 249 struct perf_record_aux { 250 struct perf_event_header header; 251 __u64 aux_offset; 252 __u64 aux_size; 253 __u64 flags; 254 }; 255 256 struct perf_record_itrace_start { 257 struct perf_event_header header; 258 __u32 pid; 259 __u32 tid; 260 }; 261 262 struct perf_record_thread_map_entry { 263 __u64 pid; 264 char comm[16]; 265 }; 266 267 struct perf_record_thread_map { 268 struct perf_event_header header; 269 __u64 nr; 270 struct perf_record_thread_map_entry entries[]; 271 }; 272 273 enum { 274 PERF_STAT_CONFIG_TERM__AGGR_MODE = 0, 275 PERF_STAT_CONFIG_TERM__INTERVAL = 1, 276 PERF_STAT_CONFIG_TERM__SCALE = 2, 277 PERF_STAT_CONFIG_TERM__MAX = 3, 278 }; 279 280 struct perf_record_stat_config_entry { 281 __u64 tag; 282 __u64 val; 283 }; 284 285 struct perf_record_stat_config { 286 struct perf_event_header header; 287 __u64 nr; 288 struct perf_record_stat_config_entry data[]; 289 }; 290 291 struct perf_record_stat { 292 struct perf_event_header header; 293 294 __u64 id; 295 __u32 cpu; 296 __u32 thread; 297 298 union { 299 struct { 300 __u64 val; 301 __u64 ena; 302 __u64 run; 303 }; 304 __u64 values[3]; 305 }; 306 }; 307 308 struct perf_record_stat_round { 309 struct perf_event_header header; 310 __u64 type; 311 __u64 time; 312 }; 313 314 struct perf_record_time_conv { 315 struct perf_event_header header; 316 __u64 time_shift; 317 __u64 time_mult; 318 __u64 time_zero; 319 }; 320 321 struct perf_record_header_feature { 322 struct perf_event_header header; 323 __u64 feat_id; 324 char data[]; 325 }; 326 327 struct perf_record_compressed { 328 struct perf_event_header header; 329 char data[]; 330 }; 331 332 enum perf_user_event_type { /* above any possible kernel type */ 333 PERF_RECORD_USER_TYPE_START = 64, 334 PERF_RECORD_HEADER_ATTR = 64, 335 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */ 336 PERF_RECORD_HEADER_TRACING_DATA = 66, 337 PERF_RECORD_HEADER_BUILD_ID = 67, 338 PERF_RECORD_FINISHED_ROUND = 68, 339 PERF_RECORD_ID_INDEX = 69, 340 PERF_RECORD_AUXTRACE_INFO = 70, 341 PERF_RECORD_AUXTRACE = 71, 342 PERF_RECORD_AUXTRACE_ERROR = 72, 343 PERF_RECORD_THREAD_MAP = 73, 344 PERF_RECORD_CPU_MAP = 74, 345 PERF_RECORD_STAT_CONFIG = 75, 346 PERF_RECORD_STAT = 76, 347 PERF_RECORD_STAT_ROUND = 77, 348 PERF_RECORD_EVENT_UPDATE = 78, 349 PERF_RECORD_TIME_CONV = 79, 350 PERF_RECORD_HEADER_FEATURE = 80, 351 PERF_RECORD_COMPRESSED = 81, 352 PERF_RECORD_HEADER_MAX 353 }; 354 355 union perf_event { 356 struct perf_event_header header; 357 struct perf_record_mmap mmap; 358 struct perf_record_mmap2 mmap2; 359 struct perf_record_comm comm; 360 struct perf_record_namespaces namespaces; 361 struct perf_record_cgroup cgroup; 362 struct perf_record_fork fork; 363 struct perf_record_lost lost; 364 struct perf_record_lost_samples lost_samples; 365 struct perf_record_read read; 366 struct perf_record_throttle throttle; 367 struct perf_record_sample sample; 368 struct perf_record_bpf_event bpf; 369 struct perf_record_ksymbol ksymbol; 370 struct perf_record_header_attr attr; 371 struct perf_record_event_update event_update; 372 struct perf_record_header_event_type event_type; 373 struct perf_record_header_tracing_data tracing_data; 374 struct perf_record_header_build_id build_id; 375 struct perf_record_id_index id_index; 376 struct perf_record_auxtrace_info auxtrace_info; 377 struct perf_record_auxtrace auxtrace; 378 struct perf_record_auxtrace_error auxtrace_error; 379 struct perf_record_aux aux; 380 struct perf_record_itrace_start itrace_start; 381 struct perf_record_switch context_switch; 382 struct perf_record_thread_map thread_map; 383 struct perf_record_cpu_map cpu_map; 384 struct perf_record_stat_config stat_config; 385 struct perf_record_stat stat; 386 struct perf_record_stat_round stat_round; 387 struct perf_record_time_conv time_conv; 388 struct perf_record_header_feature feat; 389 struct perf_record_compressed pack; 390 }; 391 392 #endif /* __LIBPERF_EVENT_H */ 393