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