Merge branch 'x86-timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / tools / perf / util / event.h
1 #ifndef __PERF_RECORD_H
2 #define __PERF_RECORD_H
3
4 #include <limits.h>
5 #include <stdio.h>
6
7 #include "../perf.h"
8 #include "map.h"
9 #include "build-id.h"
10 #include "perf_regs.h"
11 #include <asm/perf_regs.h>
12
13 struct mmap_event {
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 mmap2_event {
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 comm_event {
38         struct perf_event_header header;
39         u32 pid, tid;
40         char comm[16];
41 };
42
43 struct fork_event {
44         struct perf_event_header header;
45         u32 pid, ppid;
46         u32 tid, ptid;
47         u64 time;
48 };
49
50 struct lost_event {
51         struct perf_event_header header;
52         u64 id;
53         u64 lost;
54 };
55
56 struct lost_samples_event {
57         struct perf_event_header header;
58         u64 lost;
59 };
60
61 /*
62  * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
63  */
64 struct read_event {
65         struct perf_event_header header;
66         u32 pid, tid;
67         u64 value;
68         u64 time_enabled;
69         u64 time_running;
70         u64 id;
71 };
72
73 struct throttle_event {
74         struct perf_event_header header;
75         u64 time;
76         u64 id;
77         u64 stream_id;
78 };
79
80 #define PERF_SAMPLE_MASK                                \
81         (PERF_SAMPLE_IP | PERF_SAMPLE_TID |             \
82          PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |          \
83         PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID |        \
84          PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD |         \
85          PERF_SAMPLE_IDENTIFIER)
86
87 /* perf sample has 16 bits size limit */
88 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
89
90 struct sample_event {
91         struct perf_event_header        header;
92         u64 array[];
93 };
94
95 struct regs_dump {
96         u64 abi;
97         u64 mask;
98         u64 *regs;
99
100         /* Cached values/mask filled by first register access. */
101         u64 cache_regs[PERF_REGS_MAX];
102         u64 cache_mask;
103 };
104
105 struct stack_dump {
106         u16 offset;
107         u64 size;
108         char *data;
109 };
110
111 struct sample_read_value {
112         u64 value;
113         u64 id;
114 };
115
116 struct sample_read {
117         u64 time_enabled;
118         u64 time_running;
119         union {
120                 struct {
121                         u64 nr;
122                         struct sample_read_value *values;
123                 } group;
124                 struct sample_read_value one;
125         };
126 };
127
128 struct ip_callchain {
129         u64 nr;
130         u64 ips[0];
131 };
132
133 struct branch_flags {
134         u64 mispred:1;
135         u64 predicted:1;
136         u64 in_tx:1;
137         u64 abort:1;
138         u64 cycles:16;
139         u64 reserved:44;
140 };
141
142 struct branch_entry {
143         u64                     from;
144         u64                     to;
145         struct branch_flags     flags;
146 };
147
148 struct branch_stack {
149         u64                     nr;
150         struct branch_entry     entries[0];
151 };
152
153 enum {
154         PERF_IP_FLAG_BRANCH             = 1ULL << 0,
155         PERF_IP_FLAG_CALL               = 1ULL << 1,
156         PERF_IP_FLAG_RETURN             = 1ULL << 2,
157         PERF_IP_FLAG_CONDITIONAL        = 1ULL << 3,
158         PERF_IP_FLAG_SYSCALLRET         = 1ULL << 4,
159         PERF_IP_FLAG_ASYNC              = 1ULL << 5,
160         PERF_IP_FLAG_INTERRUPT          = 1ULL << 6,
161         PERF_IP_FLAG_TX_ABORT           = 1ULL << 7,
162         PERF_IP_FLAG_TRACE_BEGIN        = 1ULL << 8,
163         PERF_IP_FLAG_TRACE_END          = 1ULL << 9,
164         PERF_IP_FLAG_IN_TX              = 1ULL << 10,
165 };
166
167 #define PERF_IP_FLAG_CHARS "bcrosyiABEx"
168
169 #define PERF_BRANCH_MASK                (\
170         PERF_IP_FLAG_BRANCH             |\
171         PERF_IP_FLAG_CALL               |\
172         PERF_IP_FLAG_RETURN             |\
173         PERF_IP_FLAG_CONDITIONAL        |\
174         PERF_IP_FLAG_SYSCALLRET         |\
175         PERF_IP_FLAG_ASYNC              |\
176         PERF_IP_FLAG_INTERRUPT          |\
177         PERF_IP_FLAG_TX_ABORT           |\
178         PERF_IP_FLAG_TRACE_BEGIN        |\
179         PERF_IP_FLAG_TRACE_END)
180
181 struct perf_sample {
182         u64 ip;
183         u32 pid, tid;
184         u64 time;
185         u64 addr;
186         u64 id;
187         u64 stream_id;
188         u64 period;
189         u64 weight;
190         u64 transaction;
191         u32 cpu;
192         u32 raw_size;
193         u64 data_src;
194         u32 flags;
195         u16 insn_len;
196         u8  cpumode;
197         void *raw_data;
198         struct ip_callchain *callchain;
199         struct branch_stack *branch_stack;
200         struct regs_dump  user_regs;
201         struct regs_dump  intr_regs;
202         struct stack_dump user_stack;
203         struct sample_read read;
204 };
205
206 #define PERF_MEM_DATA_SRC_NONE \
207         (PERF_MEM_S(OP, NA) |\
208          PERF_MEM_S(LVL, NA) |\
209          PERF_MEM_S(SNOOP, NA) |\
210          PERF_MEM_S(LOCK, NA) |\
211          PERF_MEM_S(TLB, NA))
212
213 struct build_id_event {
214         struct perf_event_header header;
215         pid_t                    pid;
216         u8                       build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
217         char                     filename[];
218 };
219
220 enum perf_user_event_type { /* above any possible kernel type */
221         PERF_RECORD_USER_TYPE_START             = 64,
222         PERF_RECORD_HEADER_ATTR                 = 64,
223         PERF_RECORD_HEADER_EVENT_TYPE           = 65, /* depreceated */
224         PERF_RECORD_HEADER_TRACING_DATA         = 66,
225         PERF_RECORD_HEADER_BUILD_ID             = 67,
226         PERF_RECORD_FINISHED_ROUND              = 68,
227         PERF_RECORD_ID_INDEX                    = 69,
228         PERF_RECORD_AUXTRACE_INFO               = 70,
229         PERF_RECORD_AUXTRACE                    = 71,
230         PERF_RECORD_AUXTRACE_ERROR              = 72,
231         PERF_RECORD_THREAD_MAP                  = 73,
232         PERF_RECORD_CPU_MAP                     = 74,
233         PERF_RECORD_STAT_CONFIG                 = 75,
234         PERF_RECORD_STAT                        = 76,
235         PERF_RECORD_STAT_ROUND                  = 77,
236         PERF_RECORD_EVENT_UPDATE                = 78,
237         PERF_RECORD_TIME_CONV                   = 79,
238         PERF_RECORD_HEADER_MAX
239 };
240
241 enum auxtrace_error_type {
242         PERF_AUXTRACE_ERROR_ITRACE  = 1,
243         PERF_AUXTRACE_ERROR_MAX
244 };
245
246 /*
247  * The kernel collects the number of events it couldn't send in a stretch and
248  * when possible sends this number in a PERF_RECORD_LOST event. The number of
249  * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
250  * total_lost tells exactly how many events the kernel in fact lost, i.e. it is
251  * the sum of all struct lost_event.lost fields reported.
252  *
253  * The kernel discards mixed up samples and sends the number in a
254  * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored
255  * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells
256  * exactly how many samples the kernel in fact dropped, i.e. it is the sum of
257  * all struct lost_samples_event.lost fields reported.
258  *
259  * The total_period is needed because by default auto-freq is used, so
260  * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get
261  * the total number of low level events, it is necessary to to sum all struct
262  * sample_event.period and stash the result in total_period.
263  */
264 struct events_stats {
265         u64 total_period;
266         u64 total_non_filtered_period;
267         u64 total_lost;
268         u64 total_lost_samples;
269         u64 total_aux_lost;
270         u64 total_invalid_chains;
271         u32 nr_events[PERF_RECORD_HEADER_MAX];
272         u32 nr_non_filtered_samples;
273         u32 nr_lost_warned;
274         u32 nr_unknown_events;
275         u32 nr_invalid_chains;
276         u32 nr_unknown_id;
277         u32 nr_unprocessable_samples;
278         u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX];
279         u32 nr_proc_map_timeout;
280 };
281
282 enum {
283         PERF_CPU_MAP__CPUS = 0,
284         PERF_CPU_MAP__MASK = 1,
285 };
286
287 struct cpu_map_entries {
288         u16     nr;
289         u16     cpu[];
290 };
291
292 struct cpu_map_mask {
293         u16     nr;
294         u16     long_size;
295         unsigned long mask[];
296 };
297
298 struct cpu_map_data {
299         u16     type;
300         char    data[];
301 };
302
303 struct cpu_map_event {
304         struct perf_event_header        header;
305         struct cpu_map_data             data;
306 };
307
308 struct attr_event {
309         struct perf_event_header header;
310         struct perf_event_attr attr;
311         u64 id[];
312 };
313
314 enum {
315         PERF_EVENT_UPDATE__UNIT  = 0,
316         PERF_EVENT_UPDATE__SCALE = 1,
317         PERF_EVENT_UPDATE__NAME  = 2,
318         PERF_EVENT_UPDATE__CPUS  = 3,
319 };
320
321 struct event_update_event_cpus {
322         struct cpu_map_data cpus;
323 };
324
325 struct event_update_event_scale {
326         double scale;
327 };
328
329 struct event_update_event {
330         struct perf_event_header header;
331         u64 type;
332         u64 id;
333
334         char data[];
335 };
336
337 #define MAX_EVENT_NAME 64
338
339 struct perf_trace_event_type {
340         u64     event_id;
341         char    name[MAX_EVENT_NAME];
342 };
343
344 struct event_type_event {
345         struct perf_event_header header;
346         struct perf_trace_event_type event_type;
347 };
348
349 struct tracing_data_event {
350         struct perf_event_header header;
351         u32 size;
352 };
353
354 struct id_index_entry {
355         u64 id;
356         u64 idx;
357         u64 cpu;
358         u64 tid;
359 };
360
361 struct id_index_event {
362         struct perf_event_header header;
363         u64 nr;
364         struct id_index_entry entries[0];
365 };
366
367 struct auxtrace_info_event {
368         struct perf_event_header header;
369         u32 type;
370         u32 reserved__; /* For alignment */
371         u64 priv[];
372 };
373
374 struct auxtrace_event {
375         struct perf_event_header header;
376         u64 size;
377         u64 offset;
378         u64 reference;
379         u32 idx;
380         u32 tid;
381         u32 cpu;
382         u32 reserved__; /* For alignment */
383 };
384
385 #define MAX_AUXTRACE_ERROR_MSG 64
386
387 struct auxtrace_error_event {
388         struct perf_event_header header;
389         u32 type;
390         u32 code;
391         u32 cpu;
392         u32 pid;
393         u32 tid;
394         u32 reserved__; /* For alignment */
395         u64 ip;
396         char msg[MAX_AUXTRACE_ERROR_MSG];
397 };
398
399 struct aux_event {
400         struct perf_event_header header;
401         u64     aux_offset;
402         u64     aux_size;
403         u64     flags;
404 };
405
406 struct itrace_start_event {
407         struct perf_event_header header;
408         u32 pid, tid;
409 };
410
411 struct context_switch_event {
412         struct perf_event_header header;
413         u32 next_prev_pid;
414         u32 next_prev_tid;
415 };
416
417 struct thread_map_event_entry {
418         u64     pid;
419         char    comm[16];
420 };
421
422 struct thread_map_event {
423         struct perf_event_header        header;
424         u64                             nr;
425         struct thread_map_event_entry   entries[];
426 };
427
428 enum {
429         PERF_STAT_CONFIG_TERM__AGGR_MODE        = 0,
430         PERF_STAT_CONFIG_TERM__INTERVAL         = 1,
431         PERF_STAT_CONFIG_TERM__SCALE            = 2,
432         PERF_STAT_CONFIG_TERM__MAX              = 3,
433 };
434
435 struct stat_config_event_entry {
436         u64     tag;
437         u64     val;
438 };
439
440 struct stat_config_event {
441         struct perf_event_header        header;
442         u64                             nr;
443         struct stat_config_event_entry  data[];
444 };
445
446 struct stat_event {
447         struct perf_event_header        header;
448
449         u64     id;
450         u32     cpu;
451         u32     thread;
452
453         union {
454                 struct {
455                         u64 val;
456                         u64 ena;
457                         u64 run;
458                 };
459                 u64 values[3];
460         };
461 };
462
463 enum {
464         PERF_STAT_ROUND_TYPE__INTERVAL  = 0,
465         PERF_STAT_ROUND_TYPE__FINAL     = 1,
466 };
467
468 struct stat_round_event {
469         struct perf_event_header        header;
470         u64                             type;
471         u64                             time;
472 };
473
474 struct time_conv_event {
475         struct perf_event_header header;
476         u64 time_shift;
477         u64 time_mult;
478         u64 time_zero;
479 };
480
481 union perf_event {
482         struct perf_event_header        header;
483         struct mmap_event               mmap;
484         struct mmap2_event              mmap2;
485         struct comm_event               comm;
486         struct fork_event               fork;
487         struct lost_event               lost;
488         struct lost_samples_event       lost_samples;
489         struct read_event               read;
490         struct throttle_event           throttle;
491         struct sample_event             sample;
492         struct attr_event               attr;
493         struct event_update_event       event_update;
494         struct event_type_event         event_type;
495         struct tracing_data_event       tracing_data;
496         struct build_id_event           build_id;
497         struct id_index_event           id_index;
498         struct auxtrace_info_event      auxtrace_info;
499         struct auxtrace_event           auxtrace;
500         struct auxtrace_error_event     auxtrace_error;
501         struct aux_event                aux;
502         struct itrace_start_event       itrace_start;
503         struct context_switch_event     context_switch;
504         struct thread_map_event         thread_map;
505         struct cpu_map_event            cpu_map;
506         struct stat_config_event        stat_config;
507         struct stat_event               stat;
508         struct stat_round_event         stat_round;
509         struct time_conv_event          time_conv;
510 };
511
512 void perf_event__print_totals(void);
513
514 struct perf_tool;
515 struct thread_map;
516 struct cpu_map;
517 struct perf_stat_config;
518 struct perf_counts_values;
519
520 typedef int (*perf_event__handler_t)(struct perf_tool *tool,
521                                      union perf_event *event,
522                                      struct perf_sample *sample,
523                                      struct machine *machine);
524
525 int perf_event__synthesize_thread_map(struct perf_tool *tool,
526                                       struct thread_map *threads,
527                                       perf_event__handler_t process,
528                                       struct machine *machine, bool mmap_data,
529                                       unsigned int proc_map_timeout);
530 int perf_event__synthesize_thread_map2(struct perf_tool *tool,
531                                       struct thread_map *threads,
532                                       perf_event__handler_t process,
533                                       struct machine *machine);
534 int perf_event__synthesize_cpu_map(struct perf_tool *tool,
535                                    struct cpu_map *cpus,
536                                    perf_event__handler_t process,
537                                    struct machine *machine);
538 int perf_event__synthesize_threads(struct perf_tool *tool,
539                                    perf_event__handler_t process,
540                                    struct machine *machine, bool mmap_data,
541                                    unsigned int proc_map_timeout);
542 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
543                                        perf_event__handler_t process,
544                                        struct machine *machine);
545 int perf_event__synthesize_stat_config(struct perf_tool *tool,
546                                        struct perf_stat_config *config,
547                                        perf_event__handler_t process,
548                                        struct machine *machine);
549 void perf_event__read_stat_config(struct perf_stat_config *config,
550                                   struct stat_config_event *event);
551 int perf_event__synthesize_stat(struct perf_tool *tool,
552                                 u32 cpu, u32 thread, u64 id,
553                                 struct perf_counts_values *count,
554                                 perf_event__handler_t process,
555                                 struct machine *machine);
556 int perf_event__synthesize_stat_round(struct perf_tool *tool,
557                                       u64 time, u64 type,
558                                       perf_event__handler_t process,
559                                       struct machine *machine);
560 int perf_event__synthesize_modules(struct perf_tool *tool,
561                                    perf_event__handler_t process,
562                                    struct machine *machine);
563
564 int perf_event__process_comm(struct perf_tool *tool,
565                              union perf_event *event,
566                              struct perf_sample *sample,
567                              struct machine *machine);
568 int perf_event__process_lost(struct perf_tool *tool,
569                              union perf_event *event,
570                              struct perf_sample *sample,
571                              struct machine *machine);
572 int perf_event__process_lost_samples(struct perf_tool *tool,
573                                      union perf_event *event,
574                                      struct perf_sample *sample,
575                                      struct machine *machine);
576 int perf_event__process_aux(struct perf_tool *tool,
577                             union perf_event *event,
578                             struct perf_sample *sample,
579                             struct machine *machine);
580 int perf_event__process_itrace_start(struct perf_tool *tool,
581                                      union perf_event *event,
582                                      struct perf_sample *sample,
583                                      struct machine *machine);
584 int perf_event__process_switch(struct perf_tool *tool,
585                                union perf_event *event,
586                                struct perf_sample *sample,
587                                struct machine *machine);
588 int perf_event__process_mmap(struct perf_tool *tool,
589                              union perf_event *event,
590                              struct perf_sample *sample,
591                              struct machine *machine);
592 int perf_event__process_mmap2(struct perf_tool *tool,
593                              union perf_event *event,
594                              struct perf_sample *sample,
595                              struct machine *machine);
596 int perf_event__process_fork(struct perf_tool *tool,
597                              union perf_event *event,
598                              struct perf_sample *sample,
599                              struct machine *machine);
600 int perf_event__process_exit(struct perf_tool *tool,
601                              union perf_event *event,
602                              struct perf_sample *sample,
603                              struct machine *machine);
604 int perf_event__process(struct perf_tool *tool,
605                         union perf_event *event,
606                         struct perf_sample *sample,
607                         struct machine *machine);
608
609 struct addr_location;
610
611 int machine__resolve(struct machine *machine, struct addr_location *al,
612                      struct perf_sample *sample);
613
614 void addr_location__put(struct addr_location *al);
615
616 struct thread;
617
618 bool is_bts_event(struct perf_event_attr *attr);
619 bool sample_addr_correlates_sym(struct perf_event_attr *attr);
620 void thread__resolve(struct thread *thread, struct addr_location *al,
621                      struct perf_sample *sample);
622
623 const char *perf_event__name(unsigned int id);
624
625 size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
626                                      u64 read_format);
627 int perf_event__synthesize_sample(union perf_event *event, u64 type,
628                                   u64 read_format,
629                                   const struct perf_sample *sample,
630                                   bool swapped);
631
632 pid_t perf_event__synthesize_comm(struct perf_tool *tool,
633                                   union perf_event *event, pid_t pid,
634                                   perf_event__handler_t process,
635                                   struct machine *machine);
636
637 int perf_event__synthesize_mmap_events(struct perf_tool *tool,
638                                        union perf_event *event,
639                                        pid_t pid, pid_t tgid,
640                                        perf_event__handler_t process,
641                                        struct machine *machine,
642                                        bool mmap_data,
643                                        unsigned int proc_map_timeout);
644
645 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
646 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
647 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
648 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
649 size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
650 size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
651 size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
652 size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
653 size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
654 size_t perf_event__fprintf(union perf_event *event, FILE *fp);
655
656 u64 kallsyms__get_function_start(const char *kallsyms_filename,
657                                  const char *symbol_name);
658
659 void *cpu_map_data__alloc(struct cpu_map *map, size_t *size, u16 *type, int *max);
660 void  cpu_map_data__synthesize(struct cpu_map_data *data, struct cpu_map *map,
661                                u16 type, int max);
662 #endif /* __PERF_RECORD_H */