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