1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_RECORD_H
3 #define __PERF_RECORD_H
7 #include <linux/kernel.h>
9 #include <linux/perf_event.h>
13 #include "perf_regs.h"
16 struct perf_event_header header;
21 char filename[PATH_MAX];
25 struct perf_event_header header;
36 char filename[PATH_MAX];
40 struct perf_event_header header;
45 struct namespaces_event {
46 struct perf_event_header header;
49 struct perf_ns_link_info link_info[];
53 struct perf_event_header header;
60 struct perf_event_header header;
65 struct lost_samples_event {
66 struct perf_event_header header;
71 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
74 struct perf_event_header header;
82 struct throttle_event {
83 struct perf_event_header header;
90 #define KSYM_NAME_LEN 256
93 struct ksymbol_event {
94 struct perf_event_header header;
99 char name[KSYM_NAME_LEN];
103 struct perf_event_header header;
108 /* for bpf_prog types */
109 u8 tag[BPF_TAG_SIZE]; // prog tag
112 #define PERF_SAMPLE_MASK \
113 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
114 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
115 PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
116 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
117 PERF_SAMPLE_IDENTIFIER)
119 /* perf sample has 16 bits size limit */
120 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
122 struct sample_event {
123 struct perf_event_header header;
132 /* Cached values/mask filled by first register access. */
133 u64 cache_regs[PERF_REGS_MAX];
143 struct sample_read_value {
154 struct sample_read_value *values;
156 struct sample_read_value one;
160 struct ip_callchain {
168 PERF_IP_FLAG_BRANCH = 1ULL << 0,
169 PERF_IP_FLAG_CALL = 1ULL << 1,
170 PERF_IP_FLAG_RETURN = 1ULL << 2,
171 PERF_IP_FLAG_CONDITIONAL = 1ULL << 3,
172 PERF_IP_FLAG_SYSCALLRET = 1ULL << 4,
173 PERF_IP_FLAG_ASYNC = 1ULL << 5,
174 PERF_IP_FLAG_INTERRUPT = 1ULL << 6,
175 PERF_IP_FLAG_TX_ABORT = 1ULL << 7,
176 PERF_IP_FLAG_TRACE_BEGIN = 1ULL << 8,
177 PERF_IP_FLAG_TRACE_END = 1ULL << 9,
178 PERF_IP_FLAG_IN_TX = 1ULL << 10,
181 #define PERF_IP_FLAG_CHARS "bcrosyiABEx"
183 #define PERF_BRANCH_MASK (\
184 PERF_IP_FLAG_BRANCH |\
186 PERF_IP_FLAG_RETURN |\
187 PERF_IP_FLAG_CONDITIONAL |\
188 PERF_IP_FLAG_SYSCALLRET |\
189 PERF_IP_FLAG_ASYNC |\
190 PERF_IP_FLAG_INTERRUPT |\
191 PERF_IP_FLAG_TX_ABORT |\
192 PERF_IP_FLAG_TRACE_BEGIN |\
193 PERF_IP_FLAG_TRACE_END)
217 struct ip_callchain *callchain;
218 struct branch_stack *branch_stack;
219 struct regs_dump user_regs;
220 struct regs_dump intr_regs;
221 struct stack_dump user_stack;
222 struct sample_read read;
225 #define PERF_MEM_DATA_SRC_NONE \
226 (PERF_MEM_S(OP, NA) |\
227 PERF_MEM_S(LVL, NA) |\
228 PERF_MEM_S(SNOOP, NA) |\
229 PERF_MEM_S(LOCK, NA) |\
232 struct build_id_event {
233 struct perf_event_header header;
235 u8 build_id[PERF_ALIGN(BUILD_ID_SIZE, sizeof(u64))];
239 enum perf_user_event_type { /* above any possible kernel type */
240 PERF_RECORD_USER_TYPE_START = 64,
241 PERF_RECORD_HEADER_ATTR = 64,
242 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */
243 PERF_RECORD_HEADER_TRACING_DATA = 66,
244 PERF_RECORD_HEADER_BUILD_ID = 67,
245 PERF_RECORD_FINISHED_ROUND = 68,
246 PERF_RECORD_ID_INDEX = 69,
247 PERF_RECORD_AUXTRACE_INFO = 70,
248 PERF_RECORD_AUXTRACE = 71,
249 PERF_RECORD_AUXTRACE_ERROR = 72,
250 PERF_RECORD_THREAD_MAP = 73,
251 PERF_RECORD_CPU_MAP = 74,
252 PERF_RECORD_STAT_CONFIG = 75,
253 PERF_RECORD_STAT = 76,
254 PERF_RECORD_STAT_ROUND = 77,
255 PERF_RECORD_EVENT_UPDATE = 78,
256 PERF_RECORD_TIME_CONV = 79,
257 PERF_RECORD_HEADER_FEATURE = 80,
258 PERF_RECORD_HEADER_MAX
261 enum auxtrace_error_type {
262 PERF_AUXTRACE_ERROR_ITRACE = 1,
263 PERF_AUXTRACE_ERROR_MAX
266 /* Attribute type for custom synthesized events */
267 #define PERF_TYPE_SYNTH (INT_MAX + 1U)
269 /* Attribute config for custom synthesized events */
271 PERF_SYNTH_INTEL_PTWRITE,
272 PERF_SYNTH_INTEL_MWAIT,
273 PERF_SYNTH_INTEL_PWRE,
274 PERF_SYNTH_INTEL_EXSTOP,
275 PERF_SYNTH_INTEL_PWRX,
276 PERF_SYNTH_INTEL_CBR,
280 * Raw data formats for synthesized events. Note that 4 bytes of padding are
281 * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
282 * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
283 * Refer perf_sample__synth_ptr() and perf_synth__raw_data(). It also means the
284 * structure sizes are 4 bytes bigger than the raw_size, refer
285 * perf_synth__raw_size().
288 struct perf_synth_intel_ptwrite {
300 struct perf_synth_intel_mwait {
314 struct perf_synth_intel_pwre {
329 struct perf_synth_intel_exstop {
340 struct perf_synth_intel_pwrx {
345 u64 deepest_cstate : 4,
354 struct perf_synth_intel_cbr {
370 * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
373 static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
375 return sample->raw_data - 4;
378 static inline void *perf_synth__raw_data(void *p)
383 #define perf_synth__raw_size(d) (sizeof(d) - 4)
385 #define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
388 * The kernel collects the number of events it couldn't send in a stretch and
389 * when possible sends this number in a PERF_RECORD_LOST event. The number of
390 * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
391 * total_lost tells exactly how many events the kernel in fact lost, i.e. it is
392 * the sum of all struct lost_event.lost fields reported.
394 * The kernel discards mixed up samples and sends the number in a
395 * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored
396 * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells
397 * exactly how many samples the kernel in fact dropped, i.e. it is the sum of
398 * all struct lost_samples_event.lost fields reported.
400 * The total_period is needed because by default auto-freq is used, so
401 * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get
402 * the total number of low level events, it is necessary to to sum all struct
403 * sample_event.period and stash the result in total_period.
405 struct events_stats {
407 u64 total_non_filtered_period;
409 u64 total_lost_samples;
411 u64 total_aux_partial;
412 u64 total_invalid_chains;
413 u32 nr_events[PERF_RECORD_HEADER_MAX];
414 u32 nr_non_filtered_samples;
416 u32 nr_unknown_events;
417 u32 nr_invalid_chains;
419 u32 nr_unprocessable_samples;
420 u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX];
421 u32 nr_proc_map_timeout;
425 PERF_CPU_MAP__CPUS = 0,
426 PERF_CPU_MAP__MASK = 1,
429 struct cpu_map_entries {
434 struct cpu_map_mask {
437 unsigned long mask[];
440 struct cpu_map_data {
445 struct cpu_map_event {
446 struct perf_event_header header;
447 struct cpu_map_data data;
451 struct perf_event_header header;
452 struct perf_event_attr attr;
457 PERF_EVENT_UPDATE__UNIT = 0,
458 PERF_EVENT_UPDATE__SCALE = 1,
459 PERF_EVENT_UPDATE__NAME = 2,
460 PERF_EVENT_UPDATE__CPUS = 3,
463 struct event_update_event_cpus {
464 struct cpu_map_data cpus;
467 struct event_update_event_scale {
471 struct event_update_event {
472 struct perf_event_header header;
479 #define MAX_EVENT_NAME 64
481 struct perf_trace_event_type {
483 char name[MAX_EVENT_NAME];
486 struct event_type_event {
487 struct perf_event_header header;
488 struct perf_trace_event_type event_type;
491 struct tracing_data_event {
492 struct perf_event_header header;
496 struct id_index_entry {
503 struct id_index_event {
504 struct perf_event_header header;
506 struct id_index_entry entries[0];
509 struct auxtrace_info_event {
510 struct perf_event_header header;
512 u32 reserved__; /* For alignment */
516 struct auxtrace_event {
517 struct perf_event_header header;
524 u32 reserved__; /* For alignment */
527 #define MAX_AUXTRACE_ERROR_MSG 64
529 struct auxtrace_error_event {
530 struct perf_event_header header;
539 char msg[MAX_AUXTRACE_ERROR_MSG];
543 struct perf_event_header header;
549 struct itrace_start_event {
550 struct perf_event_header header;
554 struct context_switch_event {
555 struct perf_event_header header;
560 struct thread_map_event_entry {
565 struct thread_map_event {
566 struct perf_event_header header;
568 struct thread_map_event_entry entries[];
572 PERF_STAT_CONFIG_TERM__AGGR_MODE = 0,
573 PERF_STAT_CONFIG_TERM__INTERVAL = 1,
574 PERF_STAT_CONFIG_TERM__SCALE = 2,
575 PERF_STAT_CONFIG_TERM__MAX = 3,
578 struct stat_config_event_entry {
583 struct stat_config_event {
584 struct perf_event_header header;
586 struct stat_config_event_entry data[];
590 struct perf_event_header header;
607 PERF_STAT_ROUND_TYPE__INTERVAL = 0,
608 PERF_STAT_ROUND_TYPE__FINAL = 1,
611 struct stat_round_event {
612 struct perf_event_header header;
617 struct time_conv_event {
618 struct perf_event_header header;
624 struct feature_event {
625 struct perf_event_header header;
631 struct perf_event_header header;
632 struct mmap_event mmap;
633 struct mmap2_event mmap2;
634 struct comm_event comm;
635 struct namespaces_event namespaces;
636 struct fork_event fork;
637 struct lost_event lost;
638 struct lost_samples_event lost_samples;
639 struct read_event read;
640 struct throttle_event throttle;
641 struct sample_event sample;
642 struct attr_event attr;
643 struct event_update_event event_update;
644 struct event_type_event event_type;
645 struct tracing_data_event tracing_data;
646 struct build_id_event build_id;
647 struct id_index_event id_index;
648 struct auxtrace_info_event auxtrace_info;
649 struct auxtrace_event auxtrace;
650 struct auxtrace_error_event auxtrace_error;
651 struct aux_event aux;
652 struct itrace_start_event itrace_start;
653 struct context_switch_event context_switch;
654 struct thread_map_event thread_map;
655 struct cpu_map_event cpu_map;
656 struct stat_config_event stat_config;
657 struct stat_event stat;
658 struct stat_round_event stat_round;
659 struct time_conv_event time_conv;
660 struct feature_event feat;
661 struct ksymbol_event ksymbol_event;
662 struct bpf_event bpf_event;
665 void perf_event__print_totals(void);
670 struct perf_stat_config;
671 struct perf_counts_values;
673 typedef int (*perf_event__handler_t)(struct perf_tool *tool,
674 union perf_event *event,
675 struct perf_sample *sample,
676 struct machine *machine);
678 int perf_event__synthesize_thread_map(struct perf_tool *tool,
679 struct thread_map *threads,
680 perf_event__handler_t process,
681 struct machine *machine, bool mmap_data);
682 int perf_event__synthesize_thread_map2(struct perf_tool *tool,
683 struct thread_map *threads,
684 perf_event__handler_t process,
685 struct machine *machine);
686 int perf_event__synthesize_cpu_map(struct perf_tool *tool,
687 struct cpu_map *cpus,
688 perf_event__handler_t process,
689 struct machine *machine);
690 int perf_event__synthesize_threads(struct perf_tool *tool,
691 perf_event__handler_t process,
692 struct machine *machine, bool mmap_data,
693 unsigned int nr_threads_synthesize);
694 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
695 perf_event__handler_t process,
696 struct machine *machine);
697 int perf_event__synthesize_stat_config(struct perf_tool *tool,
698 struct perf_stat_config *config,
699 perf_event__handler_t process,
700 struct machine *machine);
701 void perf_event__read_stat_config(struct perf_stat_config *config,
702 struct stat_config_event *event);
703 int perf_event__synthesize_stat(struct perf_tool *tool,
704 u32 cpu, u32 thread, u64 id,
705 struct perf_counts_values *count,
706 perf_event__handler_t process,
707 struct machine *machine);
708 int perf_event__synthesize_stat_round(struct perf_tool *tool,
710 perf_event__handler_t process,
711 struct machine *machine);
712 int perf_event__synthesize_modules(struct perf_tool *tool,
713 perf_event__handler_t process,
714 struct machine *machine);
716 int perf_event__process_comm(struct perf_tool *tool,
717 union perf_event *event,
718 struct perf_sample *sample,
719 struct machine *machine);
720 int perf_event__process_lost(struct perf_tool *tool,
721 union perf_event *event,
722 struct perf_sample *sample,
723 struct machine *machine);
724 int perf_event__process_lost_samples(struct perf_tool *tool,
725 union perf_event *event,
726 struct perf_sample *sample,
727 struct machine *machine);
728 int perf_event__process_aux(struct perf_tool *tool,
729 union perf_event *event,
730 struct perf_sample *sample,
731 struct machine *machine);
732 int perf_event__process_itrace_start(struct perf_tool *tool,
733 union perf_event *event,
734 struct perf_sample *sample,
735 struct machine *machine);
736 int perf_event__process_switch(struct perf_tool *tool,
737 union perf_event *event,
738 struct perf_sample *sample,
739 struct machine *machine);
740 int perf_event__process_namespaces(struct perf_tool *tool,
741 union perf_event *event,
742 struct perf_sample *sample,
743 struct machine *machine);
744 int perf_event__process_mmap(struct perf_tool *tool,
745 union perf_event *event,
746 struct perf_sample *sample,
747 struct machine *machine);
748 int perf_event__process_mmap2(struct perf_tool *tool,
749 union perf_event *event,
750 struct perf_sample *sample,
751 struct machine *machine);
752 int perf_event__process_fork(struct perf_tool *tool,
753 union perf_event *event,
754 struct perf_sample *sample,
755 struct machine *machine);
756 int perf_event__process_exit(struct perf_tool *tool,
757 union perf_event *event,
758 struct perf_sample *sample,
759 struct machine *machine);
760 int perf_event__process_ksymbol(struct perf_tool *tool,
761 union perf_event *event,
762 struct perf_sample *sample,
763 struct machine *machine);
764 int perf_event__process_bpf_event(struct perf_tool *tool,
765 union perf_event *event,
766 struct perf_sample *sample,
767 struct machine *machine);
768 int perf_tool__process_synth_event(struct perf_tool *tool,
769 union perf_event *event,
770 struct machine *machine,
771 perf_event__handler_t process);
772 int perf_event__process(struct perf_tool *tool,
773 union perf_event *event,
774 struct perf_sample *sample,
775 struct machine *machine);
777 struct addr_location;
779 int machine__resolve(struct machine *machine, struct addr_location *al,
780 struct perf_sample *sample);
782 void addr_location__put(struct addr_location *al);
786 bool is_bts_event(struct perf_event_attr *attr);
787 bool sample_addr_correlates_sym(struct perf_event_attr *attr);
788 void thread__resolve(struct thread *thread, struct addr_location *al,
789 struct perf_sample *sample);
791 const char *perf_event__name(unsigned int id);
793 size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
795 int perf_event__synthesize_sample(union perf_event *event, u64 type,
797 const struct perf_sample *sample);
799 pid_t perf_event__synthesize_comm(struct perf_tool *tool,
800 union perf_event *event, pid_t pid,
801 perf_event__handler_t process,
802 struct machine *machine);
804 int perf_event__synthesize_namespaces(struct perf_tool *tool,
805 union perf_event *event,
806 pid_t pid, pid_t tgid,
807 perf_event__handler_t process,
808 struct machine *machine);
810 int perf_event__synthesize_mmap_events(struct perf_tool *tool,
811 union perf_event *event,
812 pid_t pid, pid_t tgid,
813 perf_event__handler_t process,
814 struct machine *machine,
817 int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
818 perf_event__handler_t process,
819 struct machine *machine);
821 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
822 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
823 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
824 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
825 size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
826 size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
827 size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
828 size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
829 size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
830 size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
831 size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
832 size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp);
833 size_t perf_event__fprintf(union perf_event *event, FILE *fp);
835 int kallsyms__get_function_start(const char *kallsyms_filename,
836 const char *symbol_name, u64 *addr);
838 void *cpu_map_data__alloc(struct cpu_map *map, size_t *size, u16 *type, int *max);
839 void cpu_map_data__synthesize(struct cpu_map_data *data, struct cpu_map *map,
842 void event_attr_init(struct perf_event_attr *attr);
844 int perf_event_paranoid(void);
846 extern int sysctl_perf_event_max_stack;
847 extern int sysctl_perf_event_max_contexts_per_stack;
848 extern unsigned int proc_map_timeout;
850 #endif /* __PERF_RECORD_H */