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