1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __PERF_SYNTHETIC_EVENTS_H 3 #define __PERF_SYNTHETIC_EVENTS_H 4 5 #include <stdbool.h> 6 #include <sys/types.h> // pid_t 7 #include <linux/compiler.h> 8 #include <linux/types.h> 9 #include <perf/cpumap.h> 10 11 struct auxtrace_record; 12 struct dso; 13 struct evlist; 14 struct evsel; 15 struct machine; 16 struct perf_counts_values; 17 struct perf_cpu_map; 18 struct perf_data; 19 struct perf_event_attr; 20 struct perf_event_mmap_page; 21 struct perf_sample; 22 struct perf_session; 23 struct perf_stat_config; 24 struct perf_thread_map; 25 struct perf_tool; 26 struct record_opts; 27 struct target; 28 29 union perf_event; 30 31 enum perf_record_synth { 32 PERF_SYNTH_TASK = 1 << 0, 33 PERF_SYNTH_MMAP = 1 << 1, 34 PERF_SYNTH_CGROUP = 1 << 2, 35 36 /* last element */ 37 PERF_SYNTH_MAX = 1 << 3, 38 }; 39 #define PERF_SYNTH_ALL (PERF_SYNTH_MAX - 1) 40 41 int parse_synth_opt(char *str); 42 43 typedef int (*perf_event__handler_t)(struct perf_tool *tool, union perf_event *event, 44 struct perf_sample *sample, struct machine *machine); 45 46 int perf_event__synthesize_attrs(struct perf_tool *tool, struct evlist *evlist, perf_event__handler_t process); 47 int perf_event__synthesize_attr(struct perf_tool *tool, struct perf_event_attr *attr, u32 ids, u64 *id, perf_event__handler_t process); 48 int perf_event__synthesize_build_id(struct perf_tool *tool, struct dso *pos, u16 misc, perf_event__handler_t process, struct machine *machine); 49 int perf_event__synthesize_cpu_map(struct perf_tool *tool, const struct perf_cpu_map *cpus, perf_event__handler_t process, struct machine *machine); 50 int perf_event__synthesize_event_update_cpus(struct perf_tool *tool, struct evsel *evsel, perf_event__handler_t process); 51 int perf_event__synthesize_event_update_name(struct perf_tool *tool, struct evsel *evsel, perf_event__handler_t process); 52 int perf_event__synthesize_event_update_scale(struct perf_tool *tool, struct evsel *evsel, perf_event__handler_t process); 53 int perf_event__synthesize_event_update_unit(struct perf_tool *tool, struct evsel *evsel, perf_event__handler_t process); 54 int perf_event__synthesize_extra_attr(struct perf_tool *tool, struct evlist *evsel_list, perf_event__handler_t process, bool is_pipe); 55 int perf_event__synthesize_extra_kmaps(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); 56 int perf_event__synthesize_features(struct perf_tool *tool, struct perf_session *session, struct evlist *evlist, perf_event__handler_t process); 57 int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, struct evlist *evlist, struct machine *machine); 58 int __perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, struct evlist *evlist, struct machine *machine, size_t from); 59 int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_sample *sample); 60 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); 61 int perf_event__synthesize_mmap_events(struct perf_tool *tool, union perf_event *event, pid_t pid, pid_t tgid, perf_event__handler_t process, struct machine *machine, bool mmap_data); 62 int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); 63 int perf_event__synthesize_namespaces(struct perf_tool *tool, union perf_event *event, pid_t pid, pid_t tgid, perf_event__handler_t process, struct machine *machine); 64 int perf_event__synthesize_cgroups(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); 65 int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_format, const struct perf_sample *sample); 66 int perf_event__synthesize_stat_config(struct perf_tool *tool, struct perf_stat_config *config, perf_event__handler_t process, struct machine *machine); 67 int perf_event__synthesize_stat_events(struct perf_stat_config *config, struct perf_tool *tool, struct evlist *evlist, perf_event__handler_t process, bool attrs); 68 int perf_event__synthesize_stat_round(struct perf_tool *tool, u64 time, u64 type, perf_event__handler_t process, struct machine *machine); 69 int perf_event__synthesize_stat(struct perf_tool *tool, struct perf_cpu cpu, u32 thread, u64 id, struct perf_counts_values *count, perf_event__handler_t process, struct machine *machine); 70 int perf_event__synthesize_thread_map2(struct perf_tool *tool, struct perf_thread_map *threads, perf_event__handler_t process, struct machine *machine); 71 int perf_event__synthesize_thread_map(struct perf_tool *tool, struct perf_thread_map *threads, perf_event__handler_t process, struct machine *machine, bool needs_mmap, bool mmap_data); 72 int perf_event__synthesize_threads(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine, bool needs_mmap, bool mmap_data, unsigned int nr_threads_synthesize); 73 int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd, struct evlist *evlist, perf_event__handler_t process); 74 int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc, struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); 75 pid_t perf_event__synthesize_comm(struct perf_tool *tool, union perf_event *event, pid_t pid, perf_event__handler_t process, struct machine *machine); 76 77 int perf_tool__process_synth_event(struct perf_tool *tool, union perf_event *event, struct machine *machine, perf_event__handler_t process); 78 79 size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, u64 read_format); 80 81 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, 82 struct target *target, struct perf_thread_map *threads, 83 perf_event__handler_t process, bool needs_mmap, bool data_mmap, 84 unsigned int nr_threads_synthesize); 85 int machine__synthesize_threads(struct machine *machine, struct target *target, 86 struct perf_thread_map *threads, bool needs_mmap, bool data_mmap, 87 unsigned int nr_threads_synthesize); 88 89 #ifdef HAVE_AUXTRACE_SUPPORT 90 int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr, struct perf_tool *tool, 91 struct perf_session *session, perf_event__handler_t process); 92 93 #else // HAVE_AUXTRACE_SUPPORT 94 95 #include <errno.h> 96 97 static inline int 98 perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr __maybe_unused, 99 struct perf_tool *tool __maybe_unused, 100 struct perf_session *session __maybe_unused, 101 perf_event__handler_t process __maybe_unused) 102 { 103 return -EINVAL; 104 } 105 #endif // HAVE_AUXTRACE_SUPPORT 106 107 #ifdef HAVE_LIBBPF_SUPPORT 108 int perf_event__synthesize_bpf_events(struct perf_session *session, perf_event__handler_t process, 109 struct machine *machine, struct record_opts *opts); 110 #else // HAVE_LIBBPF_SUPPORT 111 static inline int perf_event__synthesize_bpf_events(struct perf_session *session __maybe_unused, 112 perf_event__handler_t process __maybe_unused, 113 struct machine *machine __maybe_unused, 114 struct record_opts *opts __maybe_unused) 115 { 116 return 0; 117 } 118 #endif // HAVE_LIBBPF_SUPPORT 119 120 int perf_event__synthesize_for_pipe(struct perf_tool *tool, 121 struct perf_session *session, 122 struct perf_data *data, 123 perf_event__handler_t process); 124 125 #endif // __PERF_SYNTHETIC_EVENTS_H 126