perf record: Record dropped sample count
[platform/kernel/linux-starfive.git] / tools / lib / perf / include / perf / event.h
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         union {
29                 struct {
30                         __u32    maj;
31                         __u32    min;
32                         __u64    ino;
33                         __u64    ino_generation;
34                 };
35                 struct {
36                         __u8     build_id_size;
37                         __u8     __reserved_1;
38                         __u16    __reserved_2;
39                         __u8     build_id[20];
40                 };
41         };
42         __u32                    prot;
43         __u32                    flags;
44         char                     filename[PATH_MAX];
45 };
46
47 struct perf_record_comm {
48         struct perf_event_header header;
49         __u32                    pid, tid;
50         char                     comm[16];
51 };
52
53 struct perf_record_namespaces {
54         struct perf_event_header header;
55         __u32                    pid, tid;
56         __u64                    nr_namespaces;
57         struct perf_ns_link_info link_info[];
58 };
59
60 struct perf_record_fork {
61         struct perf_event_header header;
62         __u32                    pid, ppid;
63         __u32                    tid, ptid;
64         __u64                    time;
65 };
66
67 struct perf_record_lost {
68         struct perf_event_header header;
69         __u64                    id;
70         __u64                    lost;
71 };
72
73 #define PERF_RECORD_MISC_LOST_SAMPLES_BPF (1 << 15)
74
75 struct perf_record_lost_samples {
76         struct perf_event_header header;
77         __u64                    lost;
78 };
79
80 /*
81  * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID | PERF_FORMAT_LOST
82  */
83 struct perf_record_read {
84         struct perf_event_header header;
85         __u32                    pid, tid;
86         __u64                    value;
87         __u64                    time_enabled;
88         __u64                    time_running;
89         __u64                    id;
90         __u64                    lost;
91 };
92
93 struct perf_record_throttle {
94         struct perf_event_header header;
95         __u64                    time;
96         __u64                    id;
97         __u64                    stream_id;
98 };
99
100 #ifndef KSYM_NAME_LEN
101 #define KSYM_NAME_LEN 512
102 #endif
103
104 struct perf_record_ksymbol {
105         struct perf_event_header header;
106         __u64                    addr;
107         __u32                    len;
108         __u16                    ksym_type;
109         __u16                    flags;
110         char                     name[KSYM_NAME_LEN];
111 };
112
113 struct perf_record_bpf_event {
114         struct perf_event_header header;
115         __u16                    type;
116         __u16                    flags;
117         __u32                    id;
118
119         /* for bpf_prog types */
120         __u8                     tag[BPF_TAG_SIZE];  // prog tag
121 };
122
123 struct perf_record_cgroup {
124         struct perf_event_header header;
125         __u64                    id;
126         char                     path[PATH_MAX];
127 };
128
129 struct perf_record_text_poke_event {
130         struct perf_event_header header;
131         __u64                   addr;
132         __u16                   old_len;
133         __u16                   new_len;
134         __u8                    bytes[];
135 };
136
137 struct perf_record_sample {
138         struct perf_event_header header;
139         __u64                    array[];
140 };
141
142 struct perf_record_switch {
143         struct perf_event_header header;
144         __u32                    next_prev_pid;
145         __u32                    next_prev_tid;
146 };
147
148 struct perf_record_header_attr {
149         struct perf_event_header header;
150         struct perf_event_attr   attr;
151         __u64                    id[];
152 };
153
154 enum {
155         PERF_CPU_MAP__CPUS = 0,
156         PERF_CPU_MAP__MASK = 1,
157         PERF_CPU_MAP__RANGE_CPUS = 2,
158 };
159
160 /*
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.
163  */
164 struct cpu_map_entries {
165         __u16                    nr;
166         __u16                    cpu[];
167 };
168
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. */
172         __u16                    nr;
173         /* Constant 4. */
174         __u16                    long_size;
175         /* Bitmap data. */
176         __u32                    mask[];
177 };
178
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. */
182         __u16                    nr;
183         /* Constant 8. */
184         __u16                    long_size;
185         /* Legacy padding. */
186         char                     __pad[4];
187         /* Bitmap data. */
188         __u64                    mask[];
189 };
190
191 /*
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.
194  * -irogers
195  */
196 #pragma GCC diagnostic push
197 #pragma GCC diagnostic ignored "-Wpacked"
198 #pragma GCC diagnostic ignored "-Wattributes"
199
200 /*
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.
203  */
204 struct perf_record_range_cpu_map {
205         __u8 any_cpu;
206         __u8 __pad;
207         __u16 start_cpu;
208         __u16 end_cpu;
209 };
210
211 struct perf_record_cpu_map_data {
212         __u16                    type;
213         union {
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;
222         };
223 } __attribute__((packed));
224
225 #pragma GCC diagnostic pop
226
227 struct perf_record_cpu_map {
228         struct perf_event_header         header;
229         struct perf_record_cpu_map_data  data;
230 };
231
232 enum {
233         PERF_EVENT_UPDATE__UNIT  = 0,
234         PERF_EVENT_UPDATE__SCALE = 1,
235         PERF_EVENT_UPDATE__NAME  = 2,
236         PERF_EVENT_UPDATE__CPUS  = 3,
237 };
238
239 struct perf_record_event_update_cpus {
240         struct perf_record_cpu_map_data  cpus;
241 };
242
243 struct perf_record_event_update_scale {
244         double                   scale;
245 };
246
247 struct perf_record_event_update {
248         struct perf_event_header header;
249         __u64                    type;
250         __u64                    id;
251         union {
252                 /* Used when type == PERF_EVENT_UPDATE__SCALE. */
253                 struct perf_record_event_update_scale scale;
254                 /* Used when type == PERF_EVENT_UPDATE__UNIT. */
255                 char unit[0];
256                 /* Used when type == PERF_EVENT_UPDATE__NAME. */
257                 char name[0];
258                 /* Used when type == PERF_EVENT_UPDATE__CPUS. */
259                 struct perf_record_event_update_cpus cpus;
260         };
261 };
262
263 #define MAX_EVENT_NAME 64
264
265 struct perf_trace_event_type {
266         __u64                    event_id;
267         char                     name[MAX_EVENT_NAME];
268 };
269
270 struct perf_record_header_event_type {
271         struct perf_event_header         header;
272         struct perf_trace_event_type     event_type;
273 };
274
275 struct perf_record_header_tracing_data {
276         struct perf_event_header header;
277         __u32                    size;
278 };
279
280 #define PERF_RECORD_MISC_BUILD_ID_SIZE (1 << 15)
281
282 struct perf_record_header_build_id {
283         struct perf_event_header header;
284         pid_t                    pid;
285         union {
286                 __u8             build_id[24];
287                 struct {
288                         __u8     data[20];
289                         __u8     size;
290                         __u8     reserved1__;
291                         __u16    reserved2__;
292                 };
293         };
294         char                     filename[];
295 };
296
297 struct id_index_entry {
298         __u64                    id;
299         __u64                    idx;
300         __u64                    cpu;
301         __u64                    tid;
302 };
303
304 struct id_index_entry_2 {
305         __u64                    machine_pid;
306         __u64                    vcpu;
307 };
308
309 struct perf_record_id_index {
310         struct perf_event_header header;
311         __u64                    nr;
312         struct id_index_entry    entries[];
313 };
314
315 struct perf_record_auxtrace_info {
316         struct perf_event_header header;
317         __u32                    type;
318         __u32                    reserved__; /* For alignment */
319         __u64                    priv[];
320 };
321
322 struct perf_record_auxtrace {
323         struct perf_event_header header;
324         __u64                    size;
325         __u64                    offset;
326         __u64                    reference;
327         __u32                    idx;
328         __u32                    tid;
329         __u32                    cpu;
330         __u32                    reserved__; /* For alignment */
331 };
332
333 #define MAX_AUXTRACE_ERROR_MSG 64
334
335 struct perf_record_auxtrace_error {
336         struct perf_event_header header;
337         __u32                    type;
338         __u32                    code;
339         __u32                    cpu;
340         __u32                    pid;
341         __u32                    tid;
342         __u32                    fmt;
343         __u64                    ip;
344         __u64                    time;
345         char                     msg[MAX_AUXTRACE_ERROR_MSG];
346         __u32                    machine_pid;
347         __u32                    vcpu;
348 };
349
350 struct perf_record_aux {
351         struct perf_event_header header;
352         __u64                    aux_offset;
353         __u64                    aux_size;
354         __u64                    flags;
355 };
356
357 struct perf_record_itrace_start {
358         struct perf_event_header header;
359         __u32                    pid;
360         __u32                    tid;
361 };
362
363 struct perf_record_aux_output_hw_id {
364         struct perf_event_header header;
365         __u64                   hw_id;
366 };
367
368 struct perf_record_thread_map_entry {
369         __u64                    pid;
370         char                     comm[16];
371 };
372
373 struct perf_record_thread_map {
374         struct perf_event_header                 header;
375         __u64                                    nr;
376         struct perf_record_thread_map_entry      entries[];
377 };
378
379 enum {
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,
384 };
385
386 struct perf_record_stat_config_entry {
387         __u64                    tag;
388         __u64                    val;
389 };
390
391 struct perf_record_stat_config {
392         struct perf_event_header                 header;
393         __u64                                    nr;
394         struct perf_record_stat_config_entry     data[];
395 };
396
397 struct perf_record_stat {
398         struct perf_event_header header;
399
400         __u64                    id;
401         __u32                    cpu;
402         __u32                    thread;
403
404         union {
405                 struct {
406                         __u64    val;
407                         __u64    ena;
408                         __u64    run;
409                 };
410                 __u64            values[3];
411         };
412 };
413
414 struct perf_record_stat_round {
415         struct perf_event_header header;
416         __u64                    type;
417         __u64                    time;
418 };
419
420 struct perf_record_time_conv {
421         struct perf_event_header header;
422         __u64                    time_shift;
423         __u64                    time_mult;
424         __u64                    time_zero;
425         __u64                    time_cycles;
426         __u64                    time_mask;
427         __u8                     cap_user_time_zero;
428         __u8                     cap_user_time_short;
429         __u8                     reserved[6];   /* For alignment */
430 };
431
432 struct perf_record_header_feature {
433         struct perf_event_header header;
434         __u64                    feat_id;
435         char                     data[];
436 };
437
438 struct perf_record_compressed {
439         struct perf_event_header header;
440         char                     data[];
441 };
442
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
465 };
466
467 union perf_event {
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;
504 };
505
506 #endif /* __LIBPERF_EVENT_H */