1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_RECORD_H
3 #define __PERF_RECORD_H
7 #include <linux/kernel.h>
12 #include "perf_regs.h"
15 struct perf_event_header header
;
20 char filename
[PATH_MAX
];
24 struct perf_event_header header
;
35 char filename
[PATH_MAX
];
39 struct perf_event_header header
;
44 struct namespaces_event
{
45 struct perf_event_header header
;
48 struct perf_ns_link_info link_info
[];
52 struct perf_event_header header
;
59 struct perf_event_header header
;
64 struct lost_samples_event
{
65 struct perf_event_header header
;
70 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
73 struct perf_event_header header
;
81 struct throttle_event
{
82 struct perf_event_header header
;
89 #define KSYM_NAME_LEN 256
92 struct ksymbol_event
{
93 struct perf_event_header header
;
98 char name
[KSYM_NAME_LEN
];
102 struct perf_event_header header
;
107 /* for bpf_prog types */
108 u8 tag
[BPF_TAG_SIZE
]; // prog tag
111 #define PERF_SAMPLE_MASK \
112 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
113 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
114 PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
115 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
116 PERF_SAMPLE_IDENTIFIER)
118 /* perf sample has 16 bits size limit */
119 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
121 struct sample_event
{
122 struct perf_event_header header
;
131 /* Cached values/mask filled by first register access. */
132 u64 cache_regs
[PERF_REGS_MAX
];
142 struct sample_read_value
{
153 struct sample_read_value
*values
;
155 struct sample_read_value one
;
159 struct ip_callchain
{
167 PERF_IP_FLAG_BRANCH
= 1ULL << 0,
168 PERF_IP_FLAG_CALL
= 1ULL << 1,
169 PERF_IP_FLAG_RETURN
= 1ULL << 2,
170 PERF_IP_FLAG_CONDITIONAL
= 1ULL << 3,
171 PERF_IP_FLAG_SYSCALLRET
= 1ULL << 4,
172 PERF_IP_FLAG_ASYNC
= 1ULL << 5,
173 PERF_IP_FLAG_INTERRUPT
= 1ULL << 6,
174 PERF_IP_FLAG_TX_ABORT
= 1ULL << 7,
175 PERF_IP_FLAG_TRACE_BEGIN
= 1ULL << 8,
176 PERF_IP_FLAG_TRACE_END
= 1ULL << 9,
177 PERF_IP_FLAG_IN_TX
= 1ULL << 10,
180 #define PERF_IP_FLAG_CHARS "bcrosyiABEx"
182 #define PERF_BRANCH_MASK (\
183 PERF_IP_FLAG_BRANCH |\
185 PERF_IP_FLAG_RETURN |\
186 PERF_IP_FLAG_CONDITIONAL |\
187 PERF_IP_FLAG_SYSCALLRET |\
188 PERF_IP_FLAG_ASYNC |\
189 PERF_IP_FLAG_INTERRUPT |\
190 PERF_IP_FLAG_TX_ABORT |\
191 PERF_IP_FLAG_TRACE_BEGIN |\
192 PERF_IP_FLAG_TRACE_END)
216 struct ip_callchain
*callchain
;
217 struct branch_stack
*branch_stack
;
218 struct regs_dump user_regs
;
219 struct regs_dump intr_regs
;
220 struct stack_dump user_stack
;
221 struct sample_read read
;
224 #define PERF_MEM_DATA_SRC_NONE \
225 (PERF_MEM_S(OP, NA) |\
226 PERF_MEM_S(LVL, NA) |\
227 PERF_MEM_S(SNOOP, NA) |\
228 PERF_MEM_S(LOCK, NA) |\
231 struct build_id_event
{
232 struct perf_event_header header
;
234 u8 build_id
[PERF_ALIGN(BUILD_ID_SIZE
, sizeof(u64
))];
238 enum perf_user_event_type
{ /* above any possible kernel type */
239 PERF_RECORD_USER_TYPE_START
= 64,
240 PERF_RECORD_HEADER_ATTR
= 64,
241 PERF_RECORD_HEADER_EVENT_TYPE
= 65, /* deprecated */
242 PERF_RECORD_HEADER_TRACING_DATA
= 66,
243 PERF_RECORD_HEADER_BUILD_ID
= 67,
244 PERF_RECORD_FINISHED_ROUND
= 68,
245 PERF_RECORD_ID_INDEX
= 69,
246 PERF_RECORD_AUXTRACE_INFO
= 70,
247 PERF_RECORD_AUXTRACE
= 71,
248 PERF_RECORD_AUXTRACE_ERROR
= 72,
249 PERF_RECORD_THREAD_MAP
= 73,
250 PERF_RECORD_CPU_MAP
= 74,
251 PERF_RECORD_STAT_CONFIG
= 75,
252 PERF_RECORD_STAT
= 76,
253 PERF_RECORD_STAT_ROUND
= 77,
254 PERF_RECORD_EVENT_UPDATE
= 78,
255 PERF_RECORD_TIME_CONV
= 79,
256 PERF_RECORD_HEADER_FEATURE
= 80,
257 PERF_RECORD_HEADER_MAX
260 enum auxtrace_error_type
{
261 PERF_AUXTRACE_ERROR_ITRACE
= 1,
262 PERF_AUXTRACE_ERROR_MAX
265 /* Attribute type for custom synthesized events */
266 #define PERF_TYPE_SYNTH (INT_MAX + 1U)
268 /* Attribute config for custom synthesized events */
270 PERF_SYNTH_INTEL_PTWRITE
,
271 PERF_SYNTH_INTEL_MWAIT
,
272 PERF_SYNTH_INTEL_PWRE
,
273 PERF_SYNTH_INTEL_EXSTOP
,
274 PERF_SYNTH_INTEL_PWRX
,
275 PERF_SYNTH_INTEL_CBR
,
279 * Raw data formats for synthesized events. Note that 4 bytes of padding are
280 * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
281 * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
282 * Refer perf_sample__synth_ptr() and perf_synth__raw_data(). It also means the
283 * structure sizes are 4 bytes bigger than the raw_size, refer
284 * perf_synth__raw_size().
287 struct perf_synth_intel_ptwrite
{
299 struct perf_synth_intel_mwait
{
313 struct perf_synth_intel_pwre
{
328 struct perf_synth_intel_exstop
{
339 struct perf_synth_intel_pwrx
{
344 u64 deepest_cstate
: 4,
353 struct perf_synth_intel_cbr
{
369 * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
372 static inline void *perf_sample__synth_ptr(struct perf_sample
*sample
)
374 return sample
->raw_data
- 4;
377 static inline void *perf_synth__raw_data(void *p
)
382 #define perf_synth__raw_size(d) (sizeof(d) - 4)
384 #define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
387 * The kernel collects the number of events it couldn't send in a stretch and
388 * when possible sends this number in a PERF_RECORD_LOST event. The number of
389 * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
390 * total_lost tells exactly how many events the kernel in fact lost, i.e. it is
391 * the sum of all struct lost_event.lost fields reported.
393 * The kernel discards mixed up samples and sends the number in a
394 * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored
395 * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells
396 * exactly how many samples the kernel in fact dropped, i.e. it is the sum of
397 * all struct lost_samples_event.lost fields reported.
399 * The total_period is needed because by default auto-freq is used, so
400 * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get
401 * the total number of low level events, it is necessary to to sum all struct
402 * sample_event.period and stash the result in total_period.
404 struct events_stats
{
406 u64 total_non_filtered_period
;
408 u64 total_lost_samples
;
410 u64 total_aux_partial
;
411 u64 total_invalid_chains
;
412 u32 nr_events
[PERF_RECORD_HEADER_MAX
];
413 u32 nr_non_filtered_samples
;
415 u32 nr_unknown_events
;
416 u32 nr_invalid_chains
;
418 u32 nr_unprocessable_samples
;
419 u32 nr_auxtrace_errors
[PERF_AUXTRACE_ERROR_MAX
];
420 u32 nr_proc_map_timeout
;
424 PERF_CPU_MAP__CPUS
= 0,
425 PERF_CPU_MAP__MASK
= 1,
428 struct cpu_map_entries
{
433 struct cpu_map_mask
{
436 unsigned long mask
[];
439 struct cpu_map_data
{
444 struct cpu_map_event
{
445 struct perf_event_header header
;
446 struct cpu_map_data data
;
450 struct perf_event_header header
;
451 struct perf_event_attr attr
;
456 PERF_EVENT_UPDATE__UNIT
= 0,
457 PERF_EVENT_UPDATE__SCALE
= 1,
458 PERF_EVENT_UPDATE__NAME
= 2,
459 PERF_EVENT_UPDATE__CPUS
= 3,
462 struct event_update_event_cpus
{
463 struct cpu_map_data cpus
;
466 struct event_update_event_scale
{
470 struct event_update_event
{
471 struct perf_event_header header
;
478 #define MAX_EVENT_NAME 64
480 struct perf_trace_event_type
{
482 char name
[MAX_EVENT_NAME
];
485 struct event_type_event
{
486 struct perf_event_header header
;
487 struct perf_trace_event_type event_type
;
490 struct tracing_data_event
{
491 struct perf_event_header header
;
495 struct id_index_entry
{
502 struct id_index_event
{
503 struct perf_event_header header
;
505 struct id_index_entry entries
[0];
508 struct auxtrace_info_event
{
509 struct perf_event_header header
;
511 u32 reserved__
; /* For alignment */
515 struct auxtrace_event
{
516 struct perf_event_header header
;
523 u32 reserved__
; /* For alignment */
526 #define MAX_AUXTRACE_ERROR_MSG 64
528 struct auxtrace_error_event
{
529 struct perf_event_header header
;
538 char msg
[MAX_AUXTRACE_ERROR_MSG
];
542 struct perf_event_header header
;
548 struct itrace_start_event
{
549 struct perf_event_header header
;
553 struct context_switch_event
{
554 struct perf_event_header header
;
559 struct thread_map_event_entry
{
564 struct thread_map_event
{
565 struct perf_event_header header
;
567 struct thread_map_event_entry entries
[];
571 PERF_STAT_CONFIG_TERM__AGGR_MODE
= 0,
572 PERF_STAT_CONFIG_TERM__INTERVAL
= 1,
573 PERF_STAT_CONFIG_TERM__SCALE
= 2,
574 PERF_STAT_CONFIG_TERM__MAX
= 3,
577 struct stat_config_event_entry
{
582 struct stat_config_event
{
583 struct perf_event_header header
;
585 struct stat_config_event_entry data
[];
589 struct perf_event_header header
;
606 PERF_STAT_ROUND_TYPE__INTERVAL
= 0,
607 PERF_STAT_ROUND_TYPE__FINAL
= 1,
610 struct stat_round_event
{
611 struct perf_event_header header
;
616 struct time_conv_event
{
617 struct perf_event_header header
;
623 struct feature_event
{
624 struct perf_event_header header
;
630 struct perf_event_header header
;
631 struct mmap_event mmap
;
632 struct mmap2_event mmap2
;
633 struct comm_event comm
;
634 struct namespaces_event namespaces
;
635 struct fork_event fork
;
636 struct lost_event lost
;
637 struct lost_samples_event lost_samples
;
638 struct read_event read
;
639 struct throttle_event throttle
;
640 struct sample_event sample
;
641 struct attr_event attr
;
642 struct event_update_event event_update
;
643 struct event_type_event event_type
;
644 struct tracing_data_event tracing_data
;
645 struct build_id_event build_id
;
646 struct id_index_event id_index
;
647 struct auxtrace_info_event auxtrace_info
;
648 struct auxtrace_event auxtrace
;
649 struct auxtrace_error_event auxtrace_error
;
650 struct aux_event aux
;
651 struct itrace_start_event itrace_start
;
652 struct context_switch_event context_switch
;
653 struct thread_map_event thread_map
;
654 struct cpu_map_event cpu_map
;
655 struct stat_config_event stat_config
;
656 struct stat_event stat
;
657 struct stat_round_event stat_round
;
658 struct time_conv_event time_conv
;
659 struct feature_event feat
;
660 struct ksymbol_event ksymbol_event
;
661 struct bpf_event bpf_event
;
664 void perf_event__print_totals(void);
669 struct perf_stat_config
;
670 struct perf_counts_values
;
672 typedef int (*perf_event__handler_t
)(struct perf_tool
*tool
,
673 union perf_event
*event
,
674 struct perf_sample
*sample
,
675 struct machine
*machine
);
677 int perf_event__synthesize_thread_map(struct perf_tool
*tool
,
678 struct thread_map
*threads
,
679 perf_event__handler_t process
,
680 struct machine
*machine
, bool mmap_data
);
681 int perf_event__synthesize_thread_map2(struct perf_tool
*tool
,
682 struct thread_map
*threads
,
683 perf_event__handler_t process
,
684 struct machine
*machine
);
685 int perf_event__synthesize_cpu_map(struct perf_tool
*tool
,
686 struct cpu_map
*cpus
,
687 perf_event__handler_t process
,
688 struct machine
*machine
);
689 int perf_event__synthesize_threads(struct perf_tool
*tool
,
690 perf_event__handler_t process
,
691 struct machine
*machine
, bool mmap_data
,
692 unsigned int nr_threads_synthesize
);
693 int perf_event__synthesize_kernel_mmap(struct perf_tool
*tool
,
694 perf_event__handler_t process
,
695 struct machine
*machine
);
696 int perf_event__synthesize_stat_config(struct perf_tool
*tool
,
697 struct perf_stat_config
*config
,
698 perf_event__handler_t process
,
699 struct machine
*machine
);
700 void perf_event__read_stat_config(struct perf_stat_config
*config
,
701 struct stat_config_event
*event
);
702 int perf_event__synthesize_stat(struct perf_tool
*tool
,
703 u32 cpu
, u32 thread
, u64 id
,
704 struct perf_counts_values
*count
,
705 perf_event__handler_t process
,
706 struct machine
*machine
);
707 int perf_event__synthesize_stat_round(struct perf_tool
*tool
,
709 perf_event__handler_t process
,
710 struct machine
*machine
);
711 int perf_event__synthesize_modules(struct perf_tool
*tool
,
712 perf_event__handler_t process
,
713 struct machine
*machine
);
715 int perf_event__process_comm(struct perf_tool
*tool
,
716 union perf_event
*event
,
717 struct perf_sample
*sample
,
718 struct machine
*machine
);
719 int perf_event__process_lost(struct perf_tool
*tool
,
720 union perf_event
*event
,
721 struct perf_sample
*sample
,
722 struct machine
*machine
);
723 int perf_event__process_lost_samples(struct perf_tool
*tool
,
724 union perf_event
*event
,
725 struct perf_sample
*sample
,
726 struct machine
*machine
);
727 int perf_event__process_aux(struct perf_tool
*tool
,
728 union perf_event
*event
,
729 struct perf_sample
*sample
,
730 struct machine
*machine
);
731 int perf_event__process_itrace_start(struct perf_tool
*tool
,
732 union perf_event
*event
,
733 struct perf_sample
*sample
,
734 struct machine
*machine
);
735 int perf_event__process_switch(struct perf_tool
*tool
,
736 union perf_event
*event
,
737 struct perf_sample
*sample
,
738 struct machine
*machine
);
739 int perf_event__process_namespaces(struct perf_tool
*tool
,
740 union perf_event
*event
,
741 struct perf_sample
*sample
,
742 struct machine
*machine
);
743 int perf_event__process_mmap(struct perf_tool
*tool
,
744 union perf_event
*event
,
745 struct perf_sample
*sample
,
746 struct machine
*machine
);
747 int perf_event__process_mmap2(struct perf_tool
*tool
,
748 union perf_event
*event
,
749 struct perf_sample
*sample
,
750 struct machine
*machine
);
751 int perf_event__process_fork(struct perf_tool
*tool
,
752 union perf_event
*event
,
753 struct perf_sample
*sample
,
754 struct machine
*machine
);
755 int perf_event__process_exit(struct perf_tool
*tool
,
756 union perf_event
*event
,
757 struct perf_sample
*sample
,
758 struct machine
*machine
);
759 int perf_event__process_ksymbol(struct perf_tool
*tool
,
760 union perf_event
*event
,
761 struct perf_sample
*sample
,
762 struct machine
*machine
);
763 int perf_event__process_bpf_event(struct perf_tool
*tool
,
764 union perf_event
*event
,
765 struct perf_sample
*sample
,
766 struct machine
*machine
);
767 int perf_tool__process_synth_event(struct perf_tool
*tool
,
768 union perf_event
*event
,
769 struct machine
*machine
,
770 perf_event__handler_t process
);
771 int perf_event__process(struct perf_tool
*tool
,
772 union perf_event
*event
,
773 struct perf_sample
*sample
,
774 struct machine
*machine
);
776 struct addr_location
;
778 int machine__resolve(struct machine
*machine
, struct addr_location
*al
,
779 struct perf_sample
*sample
);
781 void addr_location__put(struct addr_location
*al
);
785 bool is_bts_event(struct perf_event_attr
*attr
);
786 bool sample_addr_correlates_sym(struct perf_event_attr
*attr
);
787 void thread__resolve(struct thread
*thread
, struct addr_location
*al
,
788 struct perf_sample
*sample
);
790 const char *perf_event__name(unsigned int id
);
792 size_t perf_event__sample_event_size(const struct perf_sample
*sample
, u64 type
,
794 int perf_event__synthesize_sample(union perf_event
*event
, u64 type
,
796 const struct perf_sample
*sample
);
798 pid_t
perf_event__synthesize_comm(struct perf_tool
*tool
,
799 union perf_event
*event
, pid_t pid
,
800 perf_event__handler_t process
,
801 struct machine
*machine
);
803 int perf_event__synthesize_namespaces(struct perf_tool
*tool
,
804 union perf_event
*event
,
805 pid_t pid
, pid_t tgid
,
806 perf_event__handler_t process
,
807 struct machine
*machine
);
809 int perf_event__synthesize_mmap_events(struct perf_tool
*tool
,
810 union perf_event
*event
,
811 pid_t pid
, pid_t tgid
,
812 perf_event__handler_t process
,
813 struct machine
*machine
,
816 int perf_event__synthesize_extra_kmaps(struct perf_tool
*tool
,
817 perf_event__handler_t process
,
818 struct machine
*machine
);
820 size_t perf_event__fprintf_comm(union perf_event
*event
, FILE *fp
);
821 size_t perf_event__fprintf_mmap(union perf_event
*event
, FILE *fp
);
822 size_t perf_event__fprintf_mmap2(union perf_event
*event
, FILE *fp
);
823 size_t perf_event__fprintf_task(union perf_event
*event
, FILE *fp
);
824 size_t perf_event__fprintf_aux(union perf_event
*event
, FILE *fp
);
825 size_t perf_event__fprintf_itrace_start(union perf_event
*event
, FILE *fp
);
826 size_t perf_event__fprintf_switch(union perf_event
*event
, FILE *fp
);
827 size_t perf_event__fprintf_thread_map(union perf_event
*event
, FILE *fp
);
828 size_t perf_event__fprintf_cpu_map(union perf_event
*event
, FILE *fp
);
829 size_t perf_event__fprintf_namespaces(union perf_event
*event
, FILE *fp
);
830 size_t perf_event__fprintf_ksymbol(union perf_event
*event
, FILE *fp
);
831 size_t perf_event__fprintf_bpf_event(union perf_event
*event
, FILE *fp
);
832 size_t perf_event__fprintf(union perf_event
*event
, FILE *fp
);
834 int kallsyms__get_function_start(const char *kallsyms_filename
,
835 const char *symbol_name
, u64
*addr
);
837 void *cpu_map_data__alloc(struct cpu_map
*map
, size_t *size
, u16
*type
, int *max
);
838 void cpu_map_data__synthesize(struct cpu_map_data
*data
, struct cpu_map
*map
,
841 void event_attr_init(struct perf_event_attr
*attr
);
843 int perf_event_paranoid(void);
845 extern int sysctl_perf_event_max_stack
;
846 extern int sysctl_perf_event_max_contexts_per_stack
;
847 extern unsigned int proc_map_timeout
;
849 #endif /* __PERF_RECORD_H */