1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 269aad6f1SArnaldo Carvalho de Melo #ifndef __PERF_EVSEL_H 369aad6f1SArnaldo Carvalho de Melo #define __PERF_EVSEL_H 1 469aad6f1SArnaldo Carvalho de Melo 569aad6f1SArnaldo Carvalho de Melo #include <linux/list.h> 6c52b12edSArnaldo Carvalho de Melo #include <stdbool.h> 7f7004f59SArnaldo Carvalho de Melo #include <sys/types.h> 8d2709c7cSDavid Howells #include <linux/perf_event.h> 9d944c4eeSBorislav Petkov #include <linux/types.h> 10b27c4eceSJiri Olsa #include <internal/evsel.h> 1169714a4eSArnaldo Carvalho de Melo #include <perf/evsel.h> 129cd997f8SArnaldo Carvalho de Melo #include "symbol_conf.h" 13f7004f59SArnaldo Carvalho de Melo #include <internal/cpumap.h> 14c52b12edSArnaldo Carvalho de Melo 15ca125277SArnaldo Carvalho de Melo struct bpf_object; 16ca125277SArnaldo Carvalho de Melo struct cgroup; 17ca125277SArnaldo Carvalho de Melo struct perf_counts; 18e669e833SArnaldo Carvalho de Melo struct perf_stat_evsel; 19ca125277SArnaldo Carvalho de Melo union perf_event; 20e669e833SArnaldo Carvalho de Melo 2165ddce3fSArnaldo Carvalho de Melo typedef int (evsel__sb_cb_t)(union perf_event *event, void *data); 22657ee553SSong Liu 23f0fbb114SAndi Kleen enum perf_tool_event { 24f0fbb114SAndi Kleen PERF_TOOL_NONE = 0, 25f0fbb114SAndi Kleen PERF_TOOL_DURATION_TIME = 1, 26f0fbb114SAndi Kleen }; 27f0fbb114SAndi Kleen 2832dcd021SJiri Olsa /** struct evsel - event selector 29f0c55bcfSStephane Eranian * 30d49e4695SArnaldo Carvalho de Melo * @evlist - evlist this evsel is in, if it is in one. 31b27c4eceSJiri Olsa * @core - libperf evsel object 32f0c55bcfSStephane Eranian * @name - Can be set to retain the original event name passed by the user, 33f0c55bcfSStephane Eranian * so that when showing results in tools such as 'perf stat', we 34f0c55bcfSStephane Eranian * show the name used, not some alias. 3575562573SAdrian Hunter * @id_pos: the position of the event id (PERF_SAMPLE_ID or 3675562573SAdrian Hunter * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of 3769d81f09SArnaldo Carvalho de Melo * struct perf_record_sample 3875562573SAdrian Hunter * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or 3975562573SAdrian Hunter * PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all 4075562573SAdrian Hunter * is used there is an id sample appended to non-sample events 410db15b1eSAdrian Hunter * @priv: And what is in its containing unnamed union are tool specific 42f0c55bcfSStephane Eranian */ 4332dcd021SJiri Olsa struct evsel { 44b27c4eceSJiri Olsa struct perf_evsel core; 4563503dbaSJiri Olsa struct evlist *evlist; 46*7fedd9b8SNamhyung Kim off_t id_offset; 4769aad6f1SArnaldo Carvalho de Melo int idx; 48*7fedd9b8SNamhyung Kim int id_pos; 49*7fedd9b8SNamhyung Kim int is_pos; 50*7fedd9b8SNamhyung Kim unsigned int sample_size; 51*7fedd9b8SNamhyung Kim 52*7fedd9b8SNamhyung Kim /* 53*7fedd9b8SNamhyung Kim * These fields can be set in the parse-events code or similar. 54*7fedd9b8SNamhyung Kim * Please check evsel__clone() to copy them properly so that 55*7fedd9b8SNamhyung Kim * they can be released properly. 56*7fedd9b8SNamhyung Kim */ 57*7fedd9b8SNamhyung Kim struct { 58f0c55bcfSStephane Eranian char *name; 59*7fedd9b8SNamhyung Kim char *group_name; 60*7fedd9b8SNamhyung Kim const char *pmu_name; 61*7fedd9b8SNamhyung Kim struct tep_event *tp_format; 62*7fedd9b8SNamhyung Kim char *filter; 63*7fedd9b8SNamhyung Kim unsigned long max_events; 64410136f5SStephane Eranian double scale; 65410136f5SStephane Eranian const char *unit; 66*7fedd9b8SNamhyung Kim struct cgroup *cgrp; 67*7fedd9b8SNamhyung Kim enum perf_tool_event tool_event; 68*7fedd9b8SNamhyung Kim /* parse modifier helper */ 69*7fedd9b8SNamhyung Kim int exclude_GH; 70*7fedd9b8SNamhyung Kim int sample_read; 71*7fedd9b8SNamhyung Kim bool snapshot; 72*7fedd9b8SNamhyung Kim bool per_pkg; 73*7fedd9b8SNamhyung Kim bool percore; 74*7fedd9b8SNamhyung Kim bool precise_max; 75*7fedd9b8SNamhyung Kim bool use_uncore_alias; 76*7fedd9b8SNamhyung Kim bool is_libpfm_event; 77*7fedd9b8SNamhyung Kim bool auto_merge_stats; 78*7fedd9b8SNamhyung Kim bool collect_stat; 79*7fedd9b8SNamhyung Kim bool weak_group; 80*7fedd9b8SNamhyung Kim int bpf_fd; 81*7fedd9b8SNamhyung Kim struct bpf_object *bpf_obj; 82*7fedd9b8SNamhyung Kim }; 83*7fedd9b8SNamhyung Kim 84*7fedd9b8SNamhyung Kim /* 85*7fedd9b8SNamhyung Kim * metric fields are similar, but needs more care as they can have 86*7fedd9b8SNamhyung Kim * references to other metric (evsel). 87*7fedd9b8SNamhyung Kim */ 88*7fedd9b8SNamhyung Kim const char * metric_expr; 89*7fedd9b8SNamhyung Kim const char * metric_name; 90*7fedd9b8SNamhyung Kim struct evsel **metric_events; 91*7fedd9b8SNamhyung Kim struct evsel *metric_leader; 92*7fedd9b8SNamhyung Kim 93*7fedd9b8SNamhyung Kim void *handler; 94*7fedd9b8SNamhyung Kim struct perf_counts *counts; 95*7fedd9b8SNamhyung Kim struct perf_counts *prev_raw_counts; 96*7fedd9b8SNamhyung Kim unsigned long nr_events_printed; 97e669e833SArnaldo Carvalho de Melo struct perf_stat_evsel *stats; 9869aad6f1SArnaldo Carvalho de Melo void *priv; 990db15b1eSAdrian Hunter u64 db_id; 10080ee8c58SKan Liang bool uniquified_name; 1012cee77c4SDavid Ahern bool supported; 1020807d2d8SArnaldo Carvalho de Melo bool needs_swap; 103b7e8452bSArnaldo Carvalho de Melo bool disabled; 1046ff1ce76SAdrian Hunter bool no_aux_samples; 1052afd2bcfSAdrian Hunter bool immediate; 10660b0896cSAdrian Hunter bool tracking; 107a359c17aSJiri Olsa bool ignore_missing_thread; 1088ef278bbSJiri Olsa bool forced_leader; 10915bfd2ccSWang Nan bool cmdline_group_boundary; 110430daf2dSAndi Kleen bool merged_stat; 1114804e011SAndi Kleen bool reset_group; 1124804e011SAndi Kleen bool errored; 113*7fedd9b8SNamhyung Kim unsigned long *per_pkg_mask; 114*7fedd9b8SNamhyung Kim struct evsel *leader; 115*7fedd9b8SNamhyung Kim struct list_head config_terms; 116*7fedd9b8SNamhyung Kim int err; 117a8cbe40fSAndi Kleen int cpu_iter; 118657ee553SSong Liu struct { 11965ddce3fSArnaldo Carvalho de Melo evsel__sb_cb_t *cb; 120657ee553SSong Liu void *data; 121657ee553SSong Liu } side_band; 122e11869a0SAdrian Hunter /* 123e11869a0SAdrian Hunter * For reporting purposes, an evsel sample can have a callchain 124e11869a0SAdrian Hunter * synthesized from AUX area data. Keep track of synthesized sample 125e11869a0SAdrian Hunter * types here. Note, the recorded sample_type cannot be changed because 126e11869a0SAdrian Hunter * it is needed to continue to parse events. 127e11869a0SAdrian Hunter * See also evsel__has_callchain(). 128e11869a0SAdrian Hunter */ 129e11869a0SAdrian Hunter __u64 synth_sample_type; 13069aad6f1SArnaldo Carvalho de Melo }; 13169aad6f1SArnaldo Carvalho de Melo 1329a831b3aSArnaldo Carvalho de Melo struct perf_missing_features { 1339a831b3aSArnaldo Carvalho de Melo bool sample_id_all; 1349a831b3aSArnaldo Carvalho de Melo bool exclude_guest; 1359a831b3aSArnaldo Carvalho de Melo bool mmap2; 1369a831b3aSArnaldo Carvalho de Melo bool cloexec; 1379a831b3aSArnaldo Carvalho de Melo bool clockid; 1389a831b3aSArnaldo Carvalho de Melo bool clockid_wrong; 1399a831b3aSArnaldo Carvalho de Melo bool lbr_flags; 1409a831b3aSArnaldo Carvalho de Melo bool write_backward; 1419a831b3aSArnaldo Carvalho de Melo bool group_read; 1429aa0bfa3SSong Liu bool ksymbol; 14374a1e863SArnaldo Carvalho de Melo bool bpf; 144acb9f2d4SArnaldo Carvalho de Melo bool aux_output; 145d3f85437SKan Liang bool branch_hw_idx; 1468fb4b679SNamhyung Kim bool cgroup; 1479a831b3aSArnaldo Carvalho de Melo }; 1489a831b3aSArnaldo Carvalho de Melo 1499a831b3aSArnaldo Carvalho de Melo extern struct perf_missing_features perf_missing_features; 1509a831b3aSArnaldo Carvalho de Melo 151f854839bSJiri Olsa struct perf_cpu_map; 15280b2210cSArnaldo Carvalho de Melo struct target; 15386bd5e86SArnaldo Carvalho de Melo struct thread_map; 154b4006796SArnaldo Carvalho de Melo struct record_opts; 15586bd5e86SArnaldo Carvalho de Melo 156b49aca3eSJiri Olsa static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel) 157a22e99cdSJiri Olsa { 1580ff1a0fdSJiri Olsa return perf_evsel__cpus(&evsel->core); 159a22e99cdSJiri Olsa } 160a22e99cdSJiri Olsa 1615eb88f04SArnaldo Carvalho de Melo static inline int evsel__nr_cpus(struct evsel *evsel) 162a22e99cdSJiri Olsa { 163b49aca3eSJiri Olsa return evsel__cpus(evsel)->nr; 164a22e99cdSJiri Olsa } 165a22e99cdSJiri Olsa 16613112bbfSJiri Olsa void perf_counts_values__scale(struct perf_counts_values *count, 16713112bbfSJiri Olsa bool scale, s8 *pscaled); 16813112bbfSJiri Olsa 16912f5261dSArnaldo Carvalho de Melo void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread, 170857a94a2SJiri Olsa struct perf_counts_values *count); 171857a94a2SJiri Olsa 1724c703828SArnaldo Carvalho de Melo int evsel__object_config(size_t object_size, 17332dcd021SJiri Olsa int (*init)(struct evsel *evsel), 17432dcd021SJiri Olsa void (*fini)(struct evsel *evsel)); 175ce8ccff5SArnaldo Carvalho de Melo 176e76026bdSArnaldo Carvalho de Melo struct perf_pmu *evsel__find_pmu(struct evsel *evsel); 17739453ed5SArnaldo Carvalho de Melo bool evsel__is_aux_event(struct evsel *evsel); 178e12ee9f7SAdrian Hunter 1798f6725a2SArnaldo Carvalho de Melo struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx); 180ef503831SArnaldo Carvalho de Melo 181365c3ae7SJiri Olsa static inline struct evsel *evsel__new(struct perf_event_attr *attr) 182ef503831SArnaldo Carvalho de Melo { 1838f6725a2SArnaldo Carvalho de Melo return evsel__new_idx(attr, 0); 184ef503831SArnaldo Carvalho de Melo } 185ef503831SArnaldo Carvalho de Melo 186*7fedd9b8SNamhyung Kim struct evsel *evsel__clone(struct evsel *orig); 1878f6725a2SArnaldo Carvalho de Melo struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx); 188ef503831SArnaldo Carvalho de Melo 1898dd2a131SJiri Olsa /* 1908dd2a131SJiri Olsa * Returns pointer with encoded error via <linux/err.h> interface. 1918dd2a131SJiri Olsa */ 1928f6725a2SArnaldo Carvalho de Melo static inline struct evsel *evsel__newtp(const char *sys, const char *name) 193ef503831SArnaldo Carvalho de Melo { 1948f6725a2SArnaldo Carvalho de Melo return evsel__newtp_idx(sys, name, 0); 195ef503831SArnaldo Carvalho de Melo } 196201b7334SArnaldo Carvalho de Melo 1978f6725a2SArnaldo Carvalho de Melo struct evsel *evsel__new_cycles(bool precise); 1987c48dcfdSArnaldo Carvalho de Melo 19997fbf3f0STzvetomir Stoyanov struct tep_event *event_format__new(const char *sys, const char *name); 200201b7334SArnaldo Carvalho de Melo 201b4b62ee6SJiri Olsa void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int idx); 20230f7c591SArnaldo Carvalho de Melo void evsel__exit(struct evsel *evsel); 2035eb2dd2aSJiri Olsa void evsel__delete(struct evsel *evsel); 20469aad6f1SArnaldo Carvalho de Melo 205e68ae9cfSArnaldo Carvalho de Melo struct callchain_param; 206e68ae9cfSArnaldo Carvalho de Melo 2076ec17b4eSArnaldo Carvalho de Melo void evsel__config(struct evsel *evsel, struct record_opts *opts, 208e68ae9cfSArnaldo Carvalho de Melo struct callchain_param *callchain); 2096ec17b4eSArnaldo Carvalho de Melo void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, 21001e0d50cSArnaldo Carvalho de Melo struct callchain_param *callchain); 2110f82ebc4SArnaldo Carvalho de Melo 2122aaefde4SArnaldo Carvalho de Melo int __evsel__sample_size(u64 sample_type); 2134b5e87b7SArnaldo Carvalho de Melo void evsel__calc_id_pos(struct evsel *evsel); 21475562573SAdrian Hunter 215c754c382SArnaldo Carvalho de Melo bool evsel__is_cache_op_valid(u8 type, u8 op); 2160b668bc9SArnaldo Carvalho de Melo 217c64e85e1SArnaldo Carvalho de Melo #define EVSEL__MAX_ALIASES 8 2180b668bc9SArnaldo Carvalho de Melo 219c64e85e1SArnaldo Carvalho de Melo extern const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES]; 220c64e85e1SArnaldo Carvalho de Melo extern const char *evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__MAX_ALIASES]; 221c64e85e1SArnaldo Carvalho de Melo extern const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][EVSEL__MAX_ALIASES]; 222c64e85e1SArnaldo Carvalho de Melo extern const char *evsel__hw_names[PERF_COUNT_HW_MAX]; 223c64e85e1SArnaldo Carvalho de Melo extern const char *evsel__sw_names[PERF_COUNT_SW_MAX]; 2248ab2e96dSArnaldo Carvalho de Melo int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size); 2258ab2e96dSArnaldo Carvalho de Melo const char *evsel__name(struct evsel *evsel); 226410136f5SStephane Eranian 2278ab2e96dSArnaldo Carvalho de Melo const char *evsel__group_name(struct evsel *evsel); 228347c751aSArnaldo Carvalho de Melo int evsel__group_desc(struct evsel *evsel, char *buf, size_t size); 229c410431cSArnaldo Carvalho de Melo 230862b2f8fSArnaldo Carvalho de Melo void __evsel__set_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit); 231862b2f8fSArnaldo Carvalho de Melo void __evsel__reset_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit); 2327be5ebe8SArnaldo Carvalho de Melo 233862b2f8fSArnaldo Carvalho de Melo #define evsel__set_sample_bit(evsel, bit) \ 234862b2f8fSArnaldo Carvalho de Melo __evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit) 2357be5ebe8SArnaldo Carvalho de Melo 236862b2f8fSArnaldo Carvalho de Melo #define evsel__reset_sample_bit(evsel, bit) \ 237862b2f8fSArnaldo Carvalho de Melo __evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit) 2387be5ebe8SArnaldo Carvalho de Melo 239862b2f8fSArnaldo Carvalho de Melo void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier); 2407a5a5ca5SArnaldo Carvalho de Melo 241ad681adfSArnaldo Carvalho de Melo int evsel__set_filter(struct evsel *evsel, const char *filter); 242ad681adfSArnaldo Carvalho de Melo int evsel__append_tp_filter(struct evsel *evsel, const char *filter); 243ad681adfSArnaldo Carvalho de Melo int evsel__append_addr_filter(struct evsel *evsel, const char *filter); 244363fb121SAndi Kleen int evsel__enable_cpu(struct evsel *evsel, int cpu); 245ec7f24efSJiri Olsa int evsel__enable(struct evsel *evsel); 2469a10bb22SJiri Olsa int evsel__disable(struct evsel *evsel); 247363fb121SAndi Kleen int evsel__disable_cpu(struct evsel *evsel, int cpu); 248745cefc5SArnaldo Carvalho de Melo 249aa8c406bSArnaldo Carvalho de Melo int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu); 250aa8c406bSArnaldo Carvalho de Melo int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads); 2515972d1e0SJiri Olsa int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, 2529749b90eSJiri Olsa struct perf_thread_map *threads); 25388761fa1SJiri Olsa void evsel__close(struct evsel *evsel); 25448290609SArnaldo Carvalho de Melo 2555555ded4SArnaldo Carvalho de Melo struct perf_sample; 2565555ded4SArnaldo Carvalho de Melo 257efc0cdc9SArnaldo Carvalho de Melo void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); 258efc0cdc9SArnaldo Carvalho de Melo u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name); 2595555ded4SArnaldo Carvalho de Melo 260efc0cdc9SArnaldo Carvalho de Melo static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name) 2615d2074eaSArnaldo Carvalho de Melo { 262efc0cdc9SArnaldo Carvalho de Melo return evsel__rawptr(evsel, sample, name); 2635d2074eaSArnaldo Carvalho de Melo } 2645d2074eaSArnaldo Carvalho de Melo 2652c92f982STzvetomir Stoyanov (VMware) struct tep_format_field; 266efd2b924SArnaldo Carvalho de Melo 2672c92f982STzvetomir Stoyanov (VMware) u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap); 26890525176SArnaldo Carvalho de Melo 269efc0cdc9SArnaldo Carvalho de Melo struct tep_format_field *evsel__field(struct evsel *evsel, const char *name); 270efd2b924SArnaldo Carvalho de Melo 271c754c382SArnaldo Carvalho de Melo #define evsel__match(evsel, t, c) \ 2721fc632ceSJiri Olsa (evsel->core.attr.type == PERF_TYPE_##t && \ 2731fc632ceSJiri Olsa evsel->core.attr.config == PERF_COUNT_##c) 274daec78a0SArnaldo Carvalho de Melo 275c754c382SArnaldo Carvalho de Melo static inline bool evsel__match2(struct evsel *e1, struct evsel *e2) 276863e451fSJiri Olsa { 2771fc632ceSJiri Olsa return (e1->core.attr.type == e2->core.attr.type) && 2781fc632ceSJiri Olsa (e1->core.attr.config == e2->core.attr.config); 279863e451fSJiri Olsa } 280863e451fSJiri Olsa 281ea089692SArnaldo Carvalho de Melo int evsel__read_counter(struct evsel *evsel, int cpu, int thread); 282f7794d52SJiri Olsa 283ea089692SArnaldo Carvalho de Melo int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale); 284c52b12edSArnaldo Carvalho de Melo 285c52b12edSArnaldo Carvalho de Melo /** 286ea089692SArnaldo Carvalho de Melo * evsel__read_on_cpu - Read out the results on a CPU and thread 287c52b12edSArnaldo Carvalho de Melo * 288c52b12edSArnaldo Carvalho de Melo * @evsel - event selector to read value 289c52b12edSArnaldo Carvalho de Melo * @cpu - CPU of interest 290c52b12edSArnaldo Carvalho de Melo * @thread - thread of interest 291c52b12edSArnaldo Carvalho de Melo */ 292ea089692SArnaldo Carvalho de Melo static inline int evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread) 293c52b12edSArnaldo Carvalho de Melo { 294ea089692SArnaldo Carvalho de Melo return __evsel__read_on_cpu(evsel, cpu, thread, false); 295c52b12edSArnaldo Carvalho de Melo } 296c52b12edSArnaldo Carvalho de Melo 297c52b12edSArnaldo Carvalho de Melo /** 298ea089692SArnaldo Carvalho de Melo * evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled 299c52b12edSArnaldo Carvalho de Melo * 300c52b12edSArnaldo Carvalho de Melo * @evsel - event selector to read value 301c52b12edSArnaldo Carvalho de Melo * @cpu - CPU of interest 302c52b12edSArnaldo Carvalho de Melo * @thread - thread of interest 303c52b12edSArnaldo Carvalho de Melo */ 304ea089692SArnaldo Carvalho de Melo static inline int evsel__read_on_cpu_scaled(struct evsel *evsel, int cpu, int thread) 305c52b12edSArnaldo Carvalho de Melo { 306ea089692SArnaldo Carvalho de Melo return __evsel__read_on_cpu(evsel, cpu, thread, true); 307c52b12edSArnaldo Carvalho de Melo } 308c52b12edSArnaldo Carvalho de Melo 3096b6017a2SArnaldo Carvalho de Melo int evsel__parse_sample(struct evsel *evsel, union perf_event *event, 3100807d2d8SArnaldo Carvalho de Melo struct perf_sample *sample); 3110c21f736SArnaldo Carvalho de Melo 3126b6017a2SArnaldo Carvalho de Melo int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, 31301468120SJiri Olsa u64 *timestamp); 31401468120SJiri Olsa 315e470daeaSArnaldo Carvalho de Melo static inline struct evsel *evsel__next(struct evsel *evsel) 3160c21f736SArnaldo Carvalho de Melo { 317b27c4eceSJiri Olsa return list_entry(evsel->core.node.next, struct evsel, core.node); 3180c21f736SArnaldo Carvalho de Melo } 31907ac002fSArnaldo Carvalho de Melo 320e470daeaSArnaldo Carvalho de Melo static inline struct evsel *evsel__prev(struct evsel *evsel) 321d87fcb4aSArnaldo Carvalho de Melo { 322b27c4eceSJiri Olsa return list_entry(evsel->core.node.prev, struct evsel, core.node); 323d87fcb4aSArnaldo Carvalho de Melo } 324d87fcb4aSArnaldo Carvalho de Melo 325759ff497SNamhyung Kim /** 326c754c382SArnaldo Carvalho de Melo * evsel__is_group_leader - Return whether given evsel is a leader event 327759ff497SNamhyung Kim * 328759ff497SNamhyung Kim * @evsel - evsel selector to be tested 329759ff497SNamhyung Kim * 330759ff497SNamhyung Kim * Return %true if @evsel is a group leader or a stand-alone event 331759ff497SNamhyung Kim */ 332c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_group_leader(const struct evsel *evsel) 33307ac002fSArnaldo Carvalho de Melo { 334823254edSNamhyung Kim return evsel->leader == evsel; 33507ac002fSArnaldo Carvalho de Melo } 3360698aeddSArnaldo Carvalho de Melo 337759ff497SNamhyung Kim /** 338c754c382SArnaldo Carvalho de Melo * evsel__is_group_event - Return whether given evsel is a group event 339759ff497SNamhyung Kim * 340759ff497SNamhyung Kim * @evsel - evsel selector to be tested 341759ff497SNamhyung Kim * 342759ff497SNamhyung Kim * Return %true iff event group view is enabled and @evsel is a actual group 343759ff497SNamhyung Kim * leader which has other members in the group 344759ff497SNamhyung Kim */ 345c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_group_event(struct evsel *evsel) 346759ff497SNamhyung Kim { 347759ff497SNamhyung Kim if (!symbol_conf.event_group) 348759ff497SNamhyung Kim return false; 349759ff497SNamhyung Kim 350c754c382SArnaldo Carvalho de Melo return evsel__is_group_leader(evsel) && evsel->core.nr_members > 1; 351759ff497SNamhyung Kim } 352759ff497SNamhyung Kim 353c754c382SArnaldo Carvalho de Melo bool evsel__is_function_event(struct evsel *evsel); 3546bedfab6SJiri Olsa 355c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_bpf_output(struct evsel *evsel) 35603e0a7dfSWang Nan { 357c754c382SArnaldo Carvalho de Melo return evsel__match(evsel, SOFTWARE, SW_BPF_OUTPUT); 35803e0a7dfSWang Nan } 35903e0a7dfSWang Nan 360c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_clock(struct evsel *evsel) 3610aa802a7SJiri Olsa { 362c754c382SArnaldo Carvalho de Melo return evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) || 363c754c382SArnaldo Carvalho de Melo evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK); 3640aa802a7SJiri Olsa } 3650aa802a7SJiri Olsa 366ae430892SArnaldo Carvalho de Melo bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize); 3672bb72dbbSArnaldo Carvalho de Melo int evsel__open_strerror(struct evsel *evsel, struct target *target, 36856e52e85SArnaldo Carvalho de Melo int err, char *msg, size_t size); 36997f63e4aSNamhyung Kim 3702bb72dbbSArnaldo Carvalho de Melo static inline int evsel__group_idx(struct evsel *evsel) 37197f63e4aSNamhyung Kim { 37297f63e4aSNamhyung Kim return evsel->idx - evsel->leader->idx; 37397f63e4aSNamhyung Kim } 374717e263fSNamhyung Kim 3752bcf7306SJiri Olsa /* Iterates group WITHOUT the leader. */ 376717e263fSNamhyung Kim #define for_each_group_member(_evsel, _leader) \ 377b27c4eceSJiri Olsa for ((_evsel) = list_entry((_leader)->core.node.next, struct evsel, core.node); \ 378717e263fSNamhyung Kim (_evsel) && (_evsel)->leader == (_leader); \ 379b27c4eceSJiri Olsa (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node)) 380717e263fSNamhyung Kim 3812bcf7306SJiri Olsa /* Iterates group WITH the leader. */ 3822bcf7306SJiri Olsa #define for_each_group_evsel(_evsel, _leader) \ 3832bcf7306SJiri Olsa for ((_evsel) = _leader; \ 3842bcf7306SJiri Olsa (_evsel) && (_evsel)->leader == (_leader); \ 385b27c4eceSJiri Olsa (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node)) 3862bcf7306SJiri Olsa 3874f138a9eSArnaldo Carvalho de Melo static inline bool evsel__has_branch_callstack(const struct evsel *evsel) 388384b6055SKan Liang { 3891fc632ceSJiri Olsa return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK; 390384b6055SKan Liang } 3912c5e8c52SPeter Zijlstra 3924f138a9eSArnaldo Carvalho de Melo static inline bool evsel__has_branch_hw_idx(const struct evsel *evsel) 39342bbabedSKan Liang { 39442bbabedSKan Liang return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX; 39542bbabedSKan Liang } 39642bbabedSKan Liang 39732dcd021SJiri Olsa static inline bool evsel__has_callchain(const struct evsel *evsel) 39827de9b2bSArnaldo Carvalho de Melo { 399e11869a0SAdrian Hunter /* 400e11869a0SAdrian Hunter * For reporting purposes, an evsel sample can have a recorded callchain 401e11869a0SAdrian Hunter * or a callchain synthesized from AUX area data. 402e11869a0SAdrian Hunter */ 403e11869a0SAdrian Hunter return evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN || 404e11869a0SAdrian Hunter evsel->synth_sample_type & PERF_SAMPLE_CALLCHAIN; 40527de9b2bSArnaldo Carvalho de Melo } 40627de9b2bSArnaldo Carvalho de Melo 4076cd2cbfcSAdrian Hunter static inline bool evsel__has_br_stack(const struct evsel *evsel) 4086cd2cbfcSAdrian Hunter { 4096cd2cbfcSAdrian Hunter /* 4106cd2cbfcSAdrian Hunter * For reporting purposes, an evsel sample can have a recorded branch 4116cd2cbfcSAdrian Hunter * stack or a branch stack synthesized from AUX area data. 4126cd2cbfcSAdrian Hunter */ 4136cd2cbfcSAdrian Hunter return evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK || 4146cd2cbfcSAdrian Hunter evsel->synth_sample_type & PERF_SAMPLE_BRANCH_STACK; 4156cd2cbfcSAdrian Hunter } 4166cd2cbfcSAdrian Hunter 417442ad225SAdrian Hunter static inline bool evsel__is_dummy_event(struct evsel *evsel) 418442ad225SAdrian Hunter { 419442ad225SAdrian Hunter return (evsel->core.attr.type == PERF_TYPE_SOFTWARE) && 420442ad225SAdrian Hunter (evsel->core.attr.config == PERF_COUNT_SW_DUMMY); 421442ad225SAdrian Hunter } 422442ad225SAdrian Hunter 4236e6d1d65SArnaldo Carvalho de Melo struct perf_env *evsel__env(struct evsel *evsel); 424f4e47f9fSRavi Bangoria 42534397753SArnaldo Carvalho de Melo int evsel__store_ids(struct evsel *evsel, struct evlist *evlist); 42669aad6f1SArnaldo Carvalho de Melo #endif /* __PERF_EVSEL_H */ 427