1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBPERF_EVENT_H
3 #define __LIBPERF_EVENT_H
5 #include <linux/perf_event.h>
6 #include <linux/types.h>
7 #include <linux/limits.h>
9 #include <sys/types.h> /* pid_t */
11 #define event_contains(obj, mem) ((obj).header.size > offsetof(typeof(obj), mem))
13 struct perf_record_mmap {
14 struct perf_event_header header;
19 char filename[PATH_MAX];
22 struct perf_record_mmap2 {
23 struct perf_event_header header;
44 char filename[PATH_MAX];
47 struct perf_record_comm {
48 struct perf_event_header header;
53 struct perf_record_namespaces {
54 struct perf_event_header header;
57 struct perf_ns_link_info link_info[];
60 struct perf_record_fork {
61 struct perf_event_header header;
67 struct perf_record_lost {
68 struct perf_event_header header;
73 #define PERF_RECORD_MISC_LOST_SAMPLES_BPF (1 << 15)
75 struct perf_record_lost_samples {
76 struct perf_event_header header;
81 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID | PERF_FORMAT_LOST
83 struct perf_record_read {
84 struct perf_event_header header;
93 struct perf_record_throttle {
94 struct perf_event_header header;
100 #ifndef KSYM_NAME_LEN
101 #define KSYM_NAME_LEN 512
104 struct perf_record_ksymbol {
105 struct perf_event_header header;
110 char name[KSYM_NAME_LEN];
113 struct perf_record_bpf_event {
114 struct perf_event_header header;
119 /* for bpf_prog types */
120 __u8 tag[BPF_TAG_SIZE]; // prog tag
123 struct perf_record_cgroup {
124 struct perf_event_header header;
129 struct perf_record_text_poke_event {
130 struct perf_event_header header;
137 struct perf_record_sample {
138 struct perf_event_header header;
142 struct perf_record_switch {
143 struct perf_event_header header;
148 struct perf_record_header_attr {
149 struct perf_event_header header;
150 struct perf_event_attr attr;
155 PERF_CPU_MAP__CPUS = 0,
156 PERF_CPU_MAP__MASK = 1,
157 PERF_CPU_MAP__RANGE_CPUS = 2,
161 * Array encoding of a perf_cpu_map where nr is the number of entries in cpu[]
162 * and each entry is a value for a CPU in the map.
164 struct cpu_map_entries {
169 /* Bitmap encoding of a perf_cpu_map where bitmap entries are 32-bit. */
170 struct perf_record_mask_cpu_map32 {
171 /* Number of mask values. */
179 /* Bitmap encoding of a perf_cpu_map where bitmap entries are 64-bit. */
180 struct perf_record_mask_cpu_map64 {
181 /* Number of mask values. */
185 /* Legacy padding. */
192 * 'struct perf_record_cpu_map_data' is packed as unfortunately an earlier
193 * version had unaligned data and we wish to retain file format compatibility.
196 #pragma GCC diagnostic push
197 #pragma GCC diagnostic ignored "-Wpacked"
198 #pragma GCC diagnostic ignored "-Wattributes"
201 * An encoding of a CPU map for a range starting at start_cpu through to
202 * end_cpu. If any_cpu is 1, an any CPU (-1) value (aka dummy value) is present.
204 struct perf_record_range_cpu_map {
211 struct perf_record_cpu_map_data {
214 /* Used when type == PERF_CPU_MAP__CPUS. */
215 struct cpu_map_entries cpus_data;
216 /* Used when type == PERF_CPU_MAP__MASK and long_size == 4. */
217 struct perf_record_mask_cpu_map32 mask32_data;
218 /* Used when type == PERF_CPU_MAP__MASK and long_size == 8. */
219 struct perf_record_mask_cpu_map64 mask64_data;
220 /* Used when type == PERF_CPU_MAP__RANGE_CPUS. */
221 struct perf_record_range_cpu_map range_cpu_data;
223 } __attribute__((packed));
225 #pragma GCC diagnostic pop
227 struct perf_record_cpu_map {
228 struct perf_event_header header;
229 struct perf_record_cpu_map_data data;
233 PERF_EVENT_UPDATE__UNIT = 0,
234 PERF_EVENT_UPDATE__SCALE = 1,
235 PERF_EVENT_UPDATE__NAME = 2,
236 PERF_EVENT_UPDATE__CPUS = 3,
239 struct perf_record_event_update_cpus {
240 struct perf_record_cpu_map_data cpus;
243 struct perf_record_event_update_scale {
247 struct perf_record_event_update {
248 struct perf_event_header header;
252 /* Used when type == PERF_EVENT_UPDATE__SCALE. */
253 struct perf_record_event_update_scale scale;
254 /* Used when type == PERF_EVENT_UPDATE__UNIT. */
256 /* Used when type == PERF_EVENT_UPDATE__NAME. */
258 /* Used when type == PERF_EVENT_UPDATE__CPUS. */
259 struct perf_record_event_update_cpus cpus;
263 #define MAX_EVENT_NAME 64
265 struct perf_trace_event_type {
267 char name[MAX_EVENT_NAME];
270 struct perf_record_header_event_type {
271 struct perf_event_header header;
272 struct perf_trace_event_type event_type;
275 struct perf_record_header_tracing_data {
276 struct perf_event_header header;
280 #define PERF_RECORD_MISC_BUILD_ID_SIZE (1 << 15)
282 struct perf_record_header_build_id {
283 struct perf_event_header header;
297 struct id_index_entry {
304 struct id_index_entry_2 {
309 struct perf_record_id_index {
310 struct perf_event_header header;
312 struct id_index_entry entries[];
315 struct perf_record_auxtrace_info {
316 struct perf_event_header header;
318 __u32 reserved__; /* For alignment */
322 struct perf_record_auxtrace {
323 struct perf_event_header header;
330 __u32 reserved__; /* For alignment */
333 #define MAX_AUXTRACE_ERROR_MSG 64
335 struct perf_record_auxtrace_error {
336 struct perf_event_header header;
345 char msg[MAX_AUXTRACE_ERROR_MSG];
350 struct perf_record_aux {
351 struct perf_event_header header;
357 struct perf_record_itrace_start {
358 struct perf_event_header header;
363 struct perf_record_aux_output_hw_id {
364 struct perf_event_header header;
368 struct perf_record_thread_map_entry {
373 struct perf_record_thread_map {
374 struct perf_event_header header;
376 struct perf_record_thread_map_entry entries[];
380 PERF_STAT_CONFIG_TERM__AGGR_MODE = 0,
381 PERF_STAT_CONFIG_TERM__INTERVAL = 1,
382 PERF_STAT_CONFIG_TERM__SCALE = 2,
383 PERF_STAT_CONFIG_TERM__MAX = 3,
386 struct perf_record_stat_config_entry {
391 struct perf_record_stat_config {
392 struct perf_event_header header;
394 struct perf_record_stat_config_entry data[];
397 struct perf_record_stat {
398 struct perf_event_header header;
414 struct perf_record_stat_round {
415 struct perf_event_header header;
420 struct perf_record_time_conv {
421 struct perf_event_header header;
427 __u8 cap_user_time_zero;
428 __u8 cap_user_time_short;
429 __u8 reserved[6]; /* For alignment */
432 struct perf_record_header_feature {
433 struct perf_event_header header;
438 struct perf_record_compressed {
439 struct perf_event_header header;
443 enum perf_user_event_type { /* above any possible kernel type */
444 PERF_RECORD_USER_TYPE_START = 64,
445 PERF_RECORD_HEADER_ATTR = 64,
446 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */
447 PERF_RECORD_HEADER_TRACING_DATA = 66,
448 PERF_RECORD_HEADER_BUILD_ID = 67,
449 PERF_RECORD_FINISHED_ROUND = 68,
450 PERF_RECORD_ID_INDEX = 69,
451 PERF_RECORD_AUXTRACE_INFO = 70,
452 PERF_RECORD_AUXTRACE = 71,
453 PERF_RECORD_AUXTRACE_ERROR = 72,
454 PERF_RECORD_THREAD_MAP = 73,
455 PERF_RECORD_CPU_MAP = 74,
456 PERF_RECORD_STAT_CONFIG = 75,
457 PERF_RECORD_STAT = 76,
458 PERF_RECORD_STAT_ROUND = 77,
459 PERF_RECORD_EVENT_UPDATE = 78,
460 PERF_RECORD_TIME_CONV = 79,
461 PERF_RECORD_HEADER_FEATURE = 80,
462 PERF_RECORD_COMPRESSED = 81,
463 PERF_RECORD_FINISHED_INIT = 82,
464 PERF_RECORD_HEADER_MAX
468 struct perf_event_header header;
469 struct perf_record_mmap mmap;
470 struct perf_record_mmap2 mmap2;
471 struct perf_record_comm comm;
472 struct perf_record_namespaces namespaces;
473 struct perf_record_cgroup cgroup;
474 struct perf_record_fork fork;
475 struct perf_record_lost lost;
476 struct perf_record_lost_samples lost_samples;
477 struct perf_record_read read;
478 struct perf_record_throttle throttle;
479 struct perf_record_sample sample;
480 struct perf_record_bpf_event bpf;
481 struct perf_record_ksymbol ksymbol;
482 struct perf_record_text_poke_event text_poke;
483 struct perf_record_header_attr attr;
484 struct perf_record_event_update event_update;
485 struct perf_record_header_event_type event_type;
486 struct perf_record_header_tracing_data tracing_data;
487 struct perf_record_header_build_id build_id;
488 struct perf_record_id_index id_index;
489 struct perf_record_auxtrace_info auxtrace_info;
490 struct perf_record_auxtrace auxtrace;
491 struct perf_record_auxtrace_error auxtrace_error;
492 struct perf_record_aux aux;
493 struct perf_record_itrace_start itrace_start;
494 struct perf_record_aux_output_hw_id aux_output_hw_id;
495 struct perf_record_switch context_switch;
496 struct perf_record_thread_map thread_map;
497 struct perf_record_cpu_map cpu_map;
498 struct perf_record_stat_config stat_config;
499 struct perf_record_stat stat;
500 struct perf_record_stat_round stat_round;
501 struct perf_record_time_conv time_conv;
502 struct perf_record_header_feature feat;
503 struct perf_record_compressed pack;
506 #endif /* __LIBPERF_EVENT_H */