1 #ifndef __PERF_RECORD_H
2 #define __PERF_RECORD_H
10 #include "perf_regs.h"
11 #include <asm/perf_regs.h>
14 struct perf_event_header header;
19 char filename[PATH_MAX];
23 struct perf_event_header header;
34 char filename[PATH_MAX];
38 struct perf_event_header header;
44 struct perf_event_header header;
51 struct perf_event_header header;
56 struct lost_samples_event {
57 struct perf_event_header header;
62 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
65 struct perf_event_header header;
73 struct throttle_event {
74 struct perf_event_header header;
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)
87 /* perf sample has 16 bits size limit */
88 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
91 struct perf_event_header header;
100 /* Cached values/mask filled by first register access. */
101 u64 cache_regs[PERF_REGS_MAX];
111 struct sample_read_value {
122 struct sample_read_value *values;
124 struct sample_read_value one;
128 struct ip_callchain {
133 struct branch_flags {
142 struct branch_entry {
145 struct branch_flags flags;
148 struct branch_stack {
150 struct branch_entry entries[0];
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,
167 #define PERF_IP_FLAG_CHARS "bcrosyiABEx"
169 #define PERF_BRANCH_MASK (\
170 PERF_IP_FLAG_BRANCH |\
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)
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;
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) |\
213 struct build_id_event {
214 struct perf_event_header header;
216 u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
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
241 enum auxtrace_error_type {
242 PERF_AUXTRACE_ERROR_ITRACE = 1,
243 PERF_AUXTRACE_ERROR_MAX
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.
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.
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.
264 struct events_stats {
266 u64 total_non_filtered_period;
268 u64 total_lost_samples;
270 u64 total_invalid_chains;
271 u32 nr_events[PERF_RECORD_HEADER_MAX];
272 u32 nr_non_filtered_samples;
274 u32 nr_unknown_events;
275 u32 nr_invalid_chains;
277 u32 nr_unprocessable_samples;
278 u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX];
279 u32 nr_proc_map_timeout;
283 PERF_CPU_MAP__CPUS = 0,
284 PERF_CPU_MAP__MASK = 1,
287 struct cpu_map_entries {
292 struct cpu_map_mask {
295 unsigned long mask[];
298 struct cpu_map_data {
303 struct cpu_map_event {
304 struct perf_event_header header;
305 struct cpu_map_data data;
309 struct perf_event_header header;
310 struct perf_event_attr attr;
315 PERF_EVENT_UPDATE__UNIT = 0,
316 PERF_EVENT_UPDATE__SCALE = 1,
317 PERF_EVENT_UPDATE__NAME = 2,
318 PERF_EVENT_UPDATE__CPUS = 3,
321 struct event_update_event_cpus {
322 struct cpu_map_data cpus;
325 struct event_update_event_scale {
329 struct event_update_event {
330 struct perf_event_header header;
337 #define MAX_EVENT_NAME 64
339 struct perf_trace_event_type {
341 char name[MAX_EVENT_NAME];
344 struct event_type_event {
345 struct perf_event_header header;
346 struct perf_trace_event_type event_type;
349 struct tracing_data_event {
350 struct perf_event_header header;
354 struct id_index_entry {
361 struct id_index_event {
362 struct perf_event_header header;
364 struct id_index_entry entries[0];
367 struct auxtrace_info_event {
368 struct perf_event_header header;
370 u32 reserved__; /* For alignment */
374 struct auxtrace_event {
375 struct perf_event_header header;
382 u32 reserved__; /* For alignment */
385 #define MAX_AUXTRACE_ERROR_MSG 64
387 struct auxtrace_error_event {
388 struct perf_event_header header;
394 u32 reserved__; /* For alignment */
396 char msg[MAX_AUXTRACE_ERROR_MSG];
400 struct perf_event_header header;
406 struct itrace_start_event {
407 struct perf_event_header header;
411 struct context_switch_event {
412 struct perf_event_header header;
417 struct thread_map_event_entry {
422 struct thread_map_event {
423 struct perf_event_header header;
425 struct thread_map_event_entry entries[];
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,
435 struct stat_config_event_entry {
440 struct stat_config_event {
441 struct perf_event_header header;
443 struct stat_config_event_entry data[];
447 struct perf_event_header header;
464 PERF_STAT_ROUND_TYPE__INTERVAL = 0,
465 PERF_STAT_ROUND_TYPE__FINAL = 1,
468 struct stat_round_event {
469 struct perf_event_header header;
474 struct time_conv_event {
475 struct perf_event_header header;
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;
512 void perf_event__print_totals(void);
517 struct perf_stat_config;
518 struct perf_counts_values;
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);
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,
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);
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);
609 struct addr_location;
611 int machine__resolve(struct machine *machine, struct addr_location *al,
612 struct perf_sample *sample);
614 void addr_location__put(struct addr_location *al);
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);
623 const char *perf_event__name(unsigned int id);
625 size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
627 int perf_event__synthesize_sample(union perf_event *event, u64 type,
629 const struct perf_sample *sample,
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);
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,
643 unsigned int proc_map_timeout);
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);
656 u64 kallsyms__get_function_start(const char *kallsyms_filename,
657 const char *symbol_name);
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,
662 #endif /* __PERF_RECORD_H */