^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __PERF_EVSEL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __PERF_EVSEL_H 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <internal/evsel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <perf/evsel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "symbol_conf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <internal/cpumap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct bpf_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct cgroup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct perf_counts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct perf_stat_evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) union perf_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) typedef int (evsel__sb_cb_t)(union perf_event *event, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) enum perf_tool_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) PERF_TOOL_NONE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) PERF_TOOL_DURATION_TIME = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /** struct evsel - event selector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * @evlist - evlist this evsel is in, if it is in one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * @core - libperf evsel object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @name - Can be set to retain the original event name passed by the user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * so that when showing results in tools such as 'perf stat', we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * show the name used, not some alias.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @id_pos: the position of the event id (PERF_SAMPLE_ID or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * struct perf_record_sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * is used there is an id sample appended to non-sample events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * @priv: And what is in its containing unnamed union are tool specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct evsel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct perf_evsel core;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct evlist *evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) off_t id_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int id_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int is_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned int sample_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * These fields can be set in the parse-events code or similar.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * Please check evsel__clone() to copy them properly so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * they can be released properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) char *group_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) const char *pmu_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct tep_event *tp_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) char *filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) unsigned long max_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) double scale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) const char *unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct cgroup *cgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) enum perf_tool_event tool_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* parse modifier helper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int exclude_GH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int sample_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) bool snapshot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) bool per_pkg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) bool percore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) bool precise_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) bool use_uncore_alias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) bool is_libpfm_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) bool auto_merge_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) bool collect_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) bool weak_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int bpf_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct bpf_object *bpf_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * metric fields are similar, but needs more care as they can have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * references to other metric (evsel).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) const char * metric_expr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) const char * metric_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct evsel **metric_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct evsel *metric_leader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct perf_counts *counts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct perf_counts *prev_raw_counts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) unsigned long nr_events_printed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct perf_stat_evsel *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) void *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u64 db_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) bool uniquified_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) bool supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) bool needs_swap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) bool disabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) bool no_aux_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) bool immediate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) bool tracking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) bool ignore_missing_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bool forced_leader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) bool cmdline_group_boundary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) bool merged_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) bool reset_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) bool errored;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) unsigned long *per_pkg_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct evsel *leader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct list_head config_terms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int cpu_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) evsel__sb_cb_t *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) } side_band;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * For reporting purposes, an evsel sample can have a callchain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * synthesized from AUX area data. Keep track of synthesized sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * types here. Note, the recorded sample_type cannot be changed because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * it is needed to continue to parse events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * See also evsel__has_callchain().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) __u64 synth_sample_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct perf_missing_features {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) bool sample_id_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) bool exclude_guest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) bool mmap2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) bool cloexec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) bool clockid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) bool clockid_wrong;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) bool lbr_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) bool write_backward;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) bool group_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) bool ksymbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) bool bpf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) bool aux_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) bool branch_hw_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) bool cgroup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) extern struct perf_missing_features perf_missing_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct perf_cpu_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct thread_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct record_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return perf_evsel__cpus(&evsel->core);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static inline int evsel__nr_cpus(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return evsel__cpus(evsel)->nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) void perf_counts_values__scale(struct perf_counts_values *count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) bool scale, s8 *pscaled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct perf_counts_values *count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int evsel__object_config(size_t object_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int (*init)(struct evsel *evsel),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) void (*fini)(struct evsel *evsel));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct perf_pmu *evsel__find_pmu(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) bool evsel__is_aux_event(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static inline struct evsel *evsel__new(struct perf_event_attr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return evsel__new_idx(attr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct evsel *evsel__clone(struct evsel *orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * Returns pointer with encoded error via <linux/err.h> interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static inline struct evsel *evsel__newtp(const char *sys, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return evsel__newtp_idx(sys, name, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct evsel *evsel__new_cycles(bool precise);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct tep_event *event_format__new(const char *sys, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) void evsel__exit(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void evsel__delete(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct callchain_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) void evsel__config(struct evsel *evsel, struct record_opts *opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct callchain_param *callchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct callchain_param *callchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int __evsel__sample_size(u64 sample_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) void evsel__calc_id_pos(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) bool evsel__is_cache_op_valid(u8 type, u8 op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define EVSEL__MAX_ALIASES 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) extern const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) extern const char *evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__MAX_ALIASES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) extern const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][EVSEL__MAX_ALIASES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) extern const char *evsel__hw_names[PERF_COUNT_HW_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) extern const char *evsel__sw_names[PERF_COUNT_SW_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) const char *evsel__name(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) const char *evsel__group_name(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) void __evsel__set_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) void __evsel__reset_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define evsel__set_sample_bit(evsel, bit) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) __evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #define evsel__reset_sample_bit(evsel, bit) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) __evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int evsel__set_filter(struct evsel *evsel, const char *filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) int evsel__append_tp_filter(struct evsel *evsel, const char *filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int evsel__append_addr_filter(struct evsel *evsel, const char *filter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int evsel__enable_cpu(struct evsel *evsel, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int evsel__enable(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int evsel__disable(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int evsel__disable_cpu(struct evsel *evsel, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct perf_thread_map *threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void evsel__close(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct perf_sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return evsel__rawptr(evsel, sample, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct tep_format_field;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct tep_format_field *evsel__field(struct evsel *evsel, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #define evsel__match(evsel, t, c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) (evsel->core.attr.type == PERF_TYPE_##t && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) evsel->core.attr.config == PERF_COUNT_##c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static inline bool evsel__match2(struct evsel *e1, struct evsel *e2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return (e1->core.attr.type == e2->core.attr.type) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) (e1->core.attr.config == e2->core.attr.config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int evsel__read_counter(struct evsel *evsel, int cpu, int thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * evsel__read_on_cpu - Read out the results on a CPU and thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * @evsel - event selector to read value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * @cpu - CPU of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * @thread - thread of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static inline int evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return __evsel__read_on_cpu(evsel, cpu, thread, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * @evsel - event selector to read value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * @cpu - CPU of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * @thread - thread of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static inline int evsel__read_on_cpu_scaled(struct evsel *evsel, int cpu, int thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return __evsel__read_on_cpu(evsel, cpu, thread, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct perf_sample *sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) u64 *timestamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static inline struct evsel *evsel__next(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return list_entry(evsel->core.node.next, struct evsel, core.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static inline struct evsel *evsel__prev(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return list_entry(evsel->core.node.prev, struct evsel, core.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * evsel__is_group_leader - Return whether given evsel is a leader event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * @evsel - evsel selector to be tested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * Return %true if @evsel is a group leader or a stand-alone event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static inline bool evsel__is_group_leader(const struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return evsel->leader == evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * evsel__is_group_event - Return whether given evsel is a group event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * @evsel - evsel selector to be tested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * Return %true iff event group view is enabled and @evsel is a actual group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * leader which has other members in the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static inline bool evsel__is_group_event(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (!symbol_conf.event_group)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return evsel__is_group_leader(evsel) && evsel->core.nr_members > 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) bool evsel__is_function_event(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static inline bool evsel__is_bpf_output(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return evsel__match(evsel, SOFTWARE, SW_BPF_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static inline bool evsel__is_clock(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) int evsel__open_strerror(struct evsel *evsel, struct target *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) int err, char *msg, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) static inline int evsel__group_idx(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return evsel->idx - evsel->leader->idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* Iterates group WITHOUT the leader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define for_each_group_member(_evsel, _leader) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) for ((_evsel) = list_entry((_leader)->core.node.next, struct evsel, core.node); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) (_evsel) && (_evsel)->leader == (_leader); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /* Iterates group WITH the leader. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) #define for_each_group_evsel(_evsel, _leader) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) for ((_evsel) = _leader; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) (_evsel) && (_evsel)->leader == (_leader); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static inline bool evsel__has_branch_callstack(const struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static inline bool evsel__has_branch_hw_idx(const struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static inline bool evsel__has_callchain(const struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) * For reporting purposes, an evsel sample can have a recorded callchain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * or a callchain synthesized from AUX area data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) evsel->synth_sample_type & PERF_SAMPLE_CALLCHAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static inline bool evsel__has_br_stack(const struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * For reporting purposes, an evsel sample can have a recorded branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * stack or a branch stack synthesized from AUX area data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) evsel->synth_sample_type & PERF_SAMPLE_BRANCH_STACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static inline bool evsel__is_dummy_event(struct evsel *evsel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return (evsel->core.attr.type == PERF_TYPE_SOFTWARE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) (evsel->core.attr.config == PERF_COUNT_SW_DUMMY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct perf_env *evsel__env(struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) int evsel__store_ids(struct evsel *evsel, struct evlist *evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) #endif /* __PERF_EVSEL_H */