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; 4669aad6f1SArnaldo Carvalho de Melo char *filter; 47c52b12edSArnaldo Carvalho de Melo struct perf_counts *counts; 48c7a79c47SStephane Eranian struct perf_counts *prev_raw_counts; 4969aad6f1SArnaldo Carvalho de Melo int idx; 502fda5adaSArnaldo Carvalho de Melo unsigned long max_events; 51a9c5e6c1SArnaldo Carvalho de Melo unsigned long nr_events_printed; 52f0c55bcfSStephane Eranian char *name; 53410136f5SStephane Eranian double scale; 54410136f5SStephane Eranian const char *unit; 5597fbf3f0STzvetomir Stoyanov struct tep_event *tp_format; 56af339981SJiri Olsa off_t id_offset; 57e669e833SArnaldo Carvalho de Melo struct perf_stat_evsel *stats; 5869aad6f1SArnaldo Carvalho de Melo void *priv; 590db15b1eSAdrian Hunter u64 db_id; 603ca32f69SArnaldo Carvalho de Melo struct cgroup *cgrp; 61744a9719SArnaldo Carvalho de Melo void *handler; 62bde09467SArnaldo Carvalho de Melo unsigned int sample_size; 6375562573SAdrian Hunter int id_pos; 6475562573SAdrian Hunter int is_pos; 65f0fbb114SAndi Kleen enum perf_tool_event tool_event; 6680ee8c58SKan Liang bool uniquified_name; 6786066064SArnaldo Carvalho de Melo bool snapshot; 682cee77c4SDavid Ahern bool supported; 690807d2d8SArnaldo Carvalho de Melo bool needs_swap; 70b7e8452bSArnaldo Carvalho de Melo bool disabled; 716ff1ce76SAdrian Hunter bool no_aux_samples; 722afd2bcfSAdrian Hunter bool immediate; 7360b0896cSAdrian Hunter bool tracking; 74044330c1SMatt Fleming bool per_pkg; 757f94af7aSJiri Olsa bool precise_max; 76a359c17aSJiri Olsa bool ignore_missing_thread; 778ef278bbSJiri Olsa bool forced_leader; 783cdc5c2cSKan Liang bool use_uncore_alias; 79f5b1135bSJiri Olsa /* parse modifier helper */ 80f5b1135bSJiri Olsa int exclude_GH; 813c176311SJiri Olsa int sample_read; 8286066064SArnaldo Carvalho de Melo unsigned long *per_pkg_mask; 8332dcd021SJiri Olsa struct evsel *leader; 846a4bb04cSJiri Olsa char *group_name; 8515bfd2ccSWang Nan bool cmdline_group_boundary; 86930a2e29SJiri Olsa struct list_head config_terms; 87af4a0991SArnaldo Carvalho de Melo struct bpf_object *bpf_obj; 881f45b1d4SWang Nan int bpf_fd; 894b49ab70SAndi Kleen int err; 9063ce8449SArnaldo Carvalho de Melo bool auto_merge_stats; 91430daf2dSAndi Kleen bool merged_stat; 9237932c18SAndi Kleen const char * metric_expr; 9396284814SAndi Kleen const char * metric_name; 9432dcd021SJiri Olsa struct evsel **metric_events; 95f01642e4SJin Yao struct evsel *metric_leader; 9637932c18SAndi Kleen bool collect_stat; 975a5dfe4bSAndi Kleen bool weak_group; 984804e011SAndi Kleen bool reset_group; 994804e011SAndi Kleen bool errored; 100064b4e82SJin Yao bool percore; 101a8cbe40fSAndi Kleen int cpu_iter; 1028c5421c0SAgustin Vega-Frias const char *pmu_name; 103657ee553SSong Liu struct { 10465ddce3fSArnaldo Carvalho de Melo evsel__sb_cb_t *cb; 105657ee553SSong Liu void *data; 106657ee553SSong Liu } side_band; 107e11869a0SAdrian Hunter /* 108e11869a0SAdrian Hunter * For reporting purposes, an evsel sample can have a callchain 109e11869a0SAdrian Hunter * synthesized from AUX area data. Keep track of synthesized sample 110e11869a0SAdrian Hunter * types here. Note, the recorded sample_type cannot be changed because 111e11869a0SAdrian Hunter * it is needed to continue to parse events. 112e11869a0SAdrian Hunter * See also evsel__has_callchain(). 113e11869a0SAdrian Hunter */ 114e11869a0SAdrian Hunter __u64 synth_sample_type; 11569aad6f1SArnaldo Carvalho de Melo }; 11669aad6f1SArnaldo Carvalho de Melo 1179a831b3aSArnaldo Carvalho de Melo struct perf_missing_features { 1189a831b3aSArnaldo Carvalho de Melo bool sample_id_all; 1199a831b3aSArnaldo Carvalho de Melo bool exclude_guest; 1209a831b3aSArnaldo Carvalho de Melo bool mmap2; 1219a831b3aSArnaldo Carvalho de Melo bool cloexec; 1229a831b3aSArnaldo Carvalho de Melo bool clockid; 1239a831b3aSArnaldo Carvalho de Melo bool clockid_wrong; 1249a831b3aSArnaldo Carvalho de Melo bool lbr_flags; 1259a831b3aSArnaldo Carvalho de Melo bool write_backward; 1269a831b3aSArnaldo Carvalho de Melo bool group_read; 1279aa0bfa3SSong Liu bool ksymbol; 12874a1e863SArnaldo Carvalho de Melo bool bpf; 129acb9f2d4SArnaldo Carvalho de Melo bool aux_output; 130d3f85437SKan Liang bool branch_hw_idx; 1318fb4b679SNamhyung Kim bool cgroup; 1329a831b3aSArnaldo Carvalho de Melo }; 1339a831b3aSArnaldo Carvalho de Melo 1349a831b3aSArnaldo Carvalho de Melo extern struct perf_missing_features perf_missing_features; 1359a831b3aSArnaldo Carvalho de Melo 136f854839bSJiri Olsa struct perf_cpu_map; 13780b2210cSArnaldo Carvalho de Melo struct target; 13886bd5e86SArnaldo Carvalho de Melo struct thread_map; 139b4006796SArnaldo Carvalho de Melo struct record_opts; 14086bd5e86SArnaldo Carvalho de Melo 141b49aca3eSJiri Olsa static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel) 142a22e99cdSJiri Olsa { 1430ff1a0fdSJiri Olsa return perf_evsel__cpus(&evsel->core); 144a22e99cdSJiri Olsa } 145a22e99cdSJiri Olsa 1465eb88f04SArnaldo Carvalho de Melo static inline int evsel__nr_cpus(struct evsel *evsel) 147a22e99cdSJiri Olsa { 148b49aca3eSJiri Olsa return evsel__cpus(evsel)->nr; 149a22e99cdSJiri Olsa } 150a22e99cdSJiri Olsa 15113112bbfSJiri Olsa void perf_counts_values__scale(struct perf_counts_values *count, 15213112bbfSJiri Olsa bool scale, s8 *pscaled); 15313112bbfSJiri Olsa 15412f5261dSArnaldo Carvalho de Melo void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread, 155857a94a2SJiri Olsa struct perf_counts_values *count); 156857a94a2SJiri Olsa 157ce8ccff5SArnaldo Carvalho de Melo int perf_evsel__object_config(size_t object_size, 15832dcd021SJiri Olsa int (*init)(struct evsel *evsel), 15932dcd021SJiri Olsa void (*fini)(struct evsel *evsel)); 160ce8ccff5SArnaldo Carvalho de Melo 161e76026bdSArnaldo Carvalho de Melo struct perf_pmu *evsel__find_pmu(struct evsel *evsel); 16239453ed5SArnaldo Carvalho de Melo bool evsel__is_aux_event(struct evsel *evsel); 163e12ee9f7SAdrian Hunter 16432dcd021SJiri Olsa struct evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx); 165ef503831SArnaldo Carvalho de Melo 166365c3ae7SJiri Olsa static inline struct evsel *evsel__new(struct perf_event_attr *attr) 167ef503831SArnaldo Carvalho de Melo { 168ef503831SArnaldo Carvalho de Melo return perf_evsel__new_idx(attr, 0); 169ef503831SArnaldo Carvalho de Melo } 170ef503831SArnaldo Carvalho de Melo 17132dcd021SJiri Olsa struct evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx); 172ef503831SArnaldo Carvalho de Melo 1738dd2a131SJiri Olsa /* 1748dd2a131SJiri Olsa * Returns pointer with encoded error via <linux/err.h> interface. 1758dd2a131SJiri Olsa */ 17632dcd021SJiri Olsa static inline struct evsel *perf_evsel__newtp(const char *sys, const char *name) 177ef503831SArnaldo Carvalho de Melo { 178ef503831SArnaldo Carvalho de Melo return perf_evsel__newtp_idx(sys, name, 0); 179ef503831SArnaldo Carvalho de Melo } 180201b7334SArnaldo Carvalho de Melo 18132dcd021SJiri Olsa struct evsel *perf_evsel__new_cycles(bool precise); 1827c48dcfdSArnaldo Carvalho de Melo 18397fbf3f0STzvetomir Stoyanov struct tep_event *event_format__new(const char *sys, const char *name); 184201b7334SArnaldo Carvalho de Melo 185b4b62ee6SJiri Olsa void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int idx); 18630f7c591SArnaldo Carvalho de Melo void evsel__exit(struct evsel *evsel); 1875eb2dd2aSJiri Olsa void evsel__delete(struct evsel *evsel); 18869aad6f1SArnaldo Carvalho de Melo 189e68ae9cfSArnaldo Carvalho de Melo struct callchain_param; 190e68ae9cfSArnaldo Carvalho de Melo 1916ec17b4eSArnaldo Carvalho de Melo void evsel__config(struct evsel *evsel, struct record_opts *opts, 192e68ae9cfSArnaldo Carvalho de Melo struct callchain_param *callchain); 1936ec17b4eSArnaldo Carvalho de Melo void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts, 19401e0d50cSArnaldo Carvalho de Melo struct callchain_param *callchain); 1950f82ebc4SArnaldo Carvalho de Melo 1962aaefde4SArnaldo Carvalho de Melo int __evsel__sample_size(u64 sample_type); 1974b5e87b7SArnaldo Carvalho de Melo void evsel__calc_id_pos(struct evsel *evsel); 19875562573SAdrian Hunter 199c754c382SArnaldo Carvalho de Melo bool evsel__is_cache_op_valid(u8 type, u8 op); 2000b668bc9SArnaldo Carvalho de Melo 2010b668bc9SArnaldo Carvalho de Melo #define PERF_EVSEL__MAX_ALIASES 8 2020b668bc9SArnaldo Carvalho de Melo 2030b668bc9SArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX] 2040b668bc9SArnaldo Carvalho de Melo [PERF_EVSEL__MAX_ALIASES]; 2050b668bc9SArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX] 2060b668bc9SArnaldo Carvalho de Melo [PERF_EVSEL__MAX_ALIASES]; 2078ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] 2080b668bc9SArnaldo Carvalho de Melo [PERF_EVSEL__MAX_ALIASES]; 2098ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX]; 2108ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX]; 2118ab2e96dSArnaldo Carvalho de Melo int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size); 2128ab2e96dSArnaldo Carvalho de Melo const char *evsel__name(struct evsel *evsel); 213410136f5SStephane Eranian 2148ab2e96dSArnaldo Carvalho de Melo const char *evsel__group_name(struct evsel *evsel); 215347c751aSArnaldo Carvalho de Melo int evsel__group_desc(struct evsel *evsel, char *buf, size_t size); 216c410431cSArnaldo Carvalho de Melo 217862b2f8fSArnaldo Carvalho de Melo void __evsel__set_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit); 218862b2f8fSArnaldo Carvalho de Melo void __evsel__reset_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit); 2197be5ebe8SArnaldo Carvalho de Melo 220862b2f8fSArnaldo Carvalho de Melo #define evsel__set_sample_bit(evsel, bit) \ 221862b2f8fSArnaldo Carvalho de Melo __evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit) 2227be5ebe8SArnaldo Carvalho de Melo 223862b2f8fSArnaldo Carvalho de Melo #define evsel__reset_sample_bit(evsel, bit) \ 224862b2f8fSArnaldo Carvalho de Melo __evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit) 2257be5ebe8SArnaldo Carvalho de Melo 226862b2f8fSArnaldo Carvalho de Melo void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier); 2277a5a5ca5SArnaldo Carvalho de Melo 228ad681adfSArnaldo Carvalho de Melo int evsel__set_filter(struct evsel *evsel, const char *filter); 229ad681adfSArnaldo Carvalho de Melo int evsel__append_tp_filter(struct evsel *evsel, const char *filter); 230ad681adfSArnaldo Carvalho de Melo int evsel__append_addr_filter(struct evsel *evsel, const char *filter); 231363fb121SAndi Kleen int evsel__enable_cpu(struct evsel *evsel, int cpu); 232ec7f24efSJiri Olsa int evsel__enable(struct evsel *evsel); 2339a10bb22SJiri Olsa int evsel__disable(struct evsel *evsel); 234363fb121SAndi Kleen int evsel__disable_cpu(struct evsel *evsel, int cpu); 235745cefc5SArnaldo Carvalho de Melo 236aa8c406bSArnaldo Carvalho de Melo int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu); 237aa8c406bSArnaldo Carvalho de Melo int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads); 2385972d1e0SJiri Olsa int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, 2399749b90eSJiri Olsa struct perf_thread_map *threads); 24088761fa1SJiri Olsa void evsel__close(struct evsel *evsel); 24148290609SArnaldo Carvalho de Melo 2425555ded4SArnaldo Carvalho de Melo struct perf_sample; 2435555ded4SArnaldo Carvalho de Melo 244efc0cdc9SArnaldo Carvalho de Melo void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name); 245efc0cdc9SArnaldo Carvalho de Melo u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name); 2465555ded4SArnaldo Carvalho de Melo 247efc0cdc9SArnaldo Carvalho de Melo static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name) 2485d2074eaSArnaldo Carvalho de Melo { 249efc0cdc9SArnaldo Carvalho de Melo return evsel__rawptr(evsel, sample, name); 2505d2074eaSArnaldo Carvalho de Melo } 2515d2074eaSArnaldo Carvalho de Melo 2522c92f982STzvetomir Stoyanov (VMware) struct tep_format_field; 253efd2b924SArnaldo Carvalho de Melo 2542c92f982STzvetomir Stoyanov (VMware) u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap); 25590525176SArnaldo Carvalho de Melo 256efc0cdc9SArnaldo Carvalho de Melo struct tep_format_field *evsel__field(struct evsel *evsel, const char *name); 257efd2b924SArnaldo Carvalho de Melo 258c754c382SArnaldo Carvalho de Melo #define evsel__match(evsel, t, c) \ 2591fc632ceSJiri Olsa (evsel->core.attr.type == PERF_TYPE_##t && \ 2601fc632ceSJiri Olsa evsel->core.attr.config == PERF_COUNT_##c) 261daec78a0SArnaldo Carvalho de Melo 262c754c382SArnaldo Carvalho de Melo static inline bool evsel__match2(struct evsel *e1, struct evsel *e2) 263863e451fSJiri Olsa { 2641fc632ceSJiri Olsa return (e1->core.attr.type == e2->core.attr.type) && 2651fc632ceSJiri Olsa (e1->core.attr.config == e2->core.attr.config); 266863e451fSJiri Olsa } 267863e451fSJiri Olsa 268*ea089692SArnaldo Carvalho de Melo int evsel__read_counter(struct evsel *evsel, int cpu, int thread); 269f7794d52SJiri Olsa 270*ea089692SArnaldo Carvalho de Melo int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale); 271c52b12edSArnaldo Carvalho de Melo 272c52b12edSArnaldo Carvalho de Melo /** 273*ea089692SArnaldo Carvalho de Melo * evsel__read_on_cpu - Read out the results on a CPU and thread 274c52b12edSArnaldo Carvalho de Melo * 275c52b12edSArnaldo Carvalho de Melo * @evsel - event selector to read value 276c52b12edSArnaldo Carvalho de Melo * @cpu - CPU of interest 277c52b12edSArnaldo Carvalho de Melo * @thread - thread of interest 278c52b12edSArnaldo Carvalho de Melo */ 279*ea089692SArnaldo Carvalho de Melo static inline int evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread) 280c52b12edSArnaldo Carvalho de Melo { 281*ea089692SArnaldo Carvalho de Melo return __evsel__read_on_cpu(evsel, cpu, thread, false); 282c52b12edSArnaldo Carvalho de Melo } 283c52b12edSArnaldo Carvalho de Melo 284c52b12edSArnaldo Carvalho de Melo /** 285*ea089692SArnaldo Carvalho de Melo * evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled 286c52b12edSArnaldo Carvalho de Melo * 287c52b12edSArnaldo Carvalho de Melo * @evsel - event selector to read value 288c52b12edSArnaldo Carvalho de Melo * @cpu - CPU of interest 289c52b12edSArnaldo Carvalho de Melo * @thread - thread of interest 290c52b12edSArnaldo Carvalho de Melo */ 291*ea089692SArnaldo Carvalho de Melo static inline int evsel__read_on_cpu_scaled(struct evsel *evsel, int cpu, int thread) 292c52b12edSArnaldo Carvalho de Melo { 293*ea089692SArnaldo Carvalho de Melo return __evsel__read_on_cpu(evsel, cpu, thread, true); 294c52b12edSArnaldo Carvalho de Melo } 295c52b12edSArnaldo Carvalho de Melo 29632dcd021SJiri Olsa int perf_evsel__parse_sample(struct evsel *evsel, union perf_event *event, 2970807d2d8SArnaldo Carvalho de Melo struct perf_sample *sample); 2980c21f736SArnaldo Carvalho de Melo 29932dcd021SJiri Olsa int perf_evsel__parse_sample_timestamp(struct evsel *evsel, 30001468120SJiri Olsa union perf_event *event, 30101468120SJiri Olsa u64 *timestamp); 30201468120SJiri Olsa 30332dcd021SJiri Olsa static inline struct evsel *perf_evsel__next(struct evsel *evsel) 3040c21f736SArnaldo Carvalho de Melo { 305b27c4eceSJiri Olsa return list_entry(evsel->core.node.next, struct evsel, core.node); 3060c21f736SArnaldo Carvalho de Melo } 30707ac002fSArnaldo Carvalho de Melo 30832dcd021SJiri Olsa static inline struct evsel *perf_evsel__prev(struct evsel *evsel) 309d87fcb4aSArnaldo Carvalho de Melo { 310b27c4eceSJiri Olsa return list_entry(evsel->core.node.prev, struct evsel, core.node); 311d87fcb4aSArnaldo Carvalho de Melo } 312d87fcb4aSArnaldo Carvalho de Melo 313759ff497SNamhyung Kim /** 314c754c382SArnaldo Carvalho de Melo * evsel__is_group_leader - Return whether given evsel is a leader event 315759ff497SNamhyung Kim * 316759ff497SNamhyung Kim * @evsel - evsel selector to be tested 317759ff497SNamhyung Kim * 318759ff497SNamhyung Kim * Return %true if @evsel is a group leader or a stand-alone event 319759ff497SNamhyung Kim */ 320c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_group_leader(const struct evsel *evsel) 32107ac002fSArnaldo Carvalho de Melo { 322823254edSNamhyung Kim return evsel->leader == evsel; 32307ac002fSArnaldo Carvalho de Melo } 3240698aeddSArnaldo Carvalho de Melo 325759ff497SNamhyung Kim /** 326c754c382SArnaldo Carvalho de Melo * evsel__is_group_event - Return whether given evsel is a group event 327759ff497SNamhyung Kim * 328759ff497SNamhyung Kim * @evsel - evsel selector to be tested 329759ff497SNamhyung Kim * 330759ff497SNamhyung Kim * Return %true iff event group view is enabled and @evsel is a actual group 331759ff497SNamhyung Kim * leader which has other members in the group 332759ff497SNamhyung Kim */ 333c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_group_event(struct evsel *evsel) 334759ff497SNamhyung Kim { 335759ff497SNamhyung Kim if (!symbol_conf.event_group) 336759ff497SNamhyung Kim return false; 337759ff497SNamhyung Kim 338c754c382SArnaldo Carvalho de Melo return evsel__is_group_leader(evsel) && evsel->core.nr_members > 1; 339759ff497SNamhyung Kim } 340759ff497SNamhyung Kim 341c754c382SArnaldo Carvalho de Melo bool evsel__is_function_event(struct evsel *evsel); 3426bedfab6SJiri Olsa 343c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_bpf_output(struct evsel *evsel) 34403e0a7dfSWang Nan { 345c754c382SArnaldo Carvalho de Melo return evsel__match(evsel, SOFTWARE, SW_BPF_OUTPUT); 34603e0a7dfSWang Nan } 34703e0a7dfSWang Nan 348c754c382SArnaldo Carvalho de Melo static inline bool evsel__is_clock(struct evsel *evsel) 3490aa802a7SJiri Olsa { 350c754c382SArnaldo Carvalho de Melo return evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) || 351c754c382SArnaldo Carvalho de Melo evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK); 3520aa802a7SJiri Olsa } 3530aa802a7SJiri Olsa 35432dcd021SJiri Olsa bool perf_evsel__fallback(struct evsel *evsel, int err, 355c0a54341SArnaldo Carvalho de Melo char *msg, size_t msgsize); 35632dcd021SJiri Olsa int perf_evsel__open_strerror(struct evsel *evsel, struct target *target, 35756e52e85SArnaldo Carvalho de Melo int err, char *msg, size_t size); 35897f63e4aSNamhyung Kim 35932dcd021SJiri Olsa static inline int perf_evsel__group_idx(struct evsel *evsel) 36097f63e4aSNamhyung Kim { 36197f63e4aSNamhyung Kim return evsel->idx - evsel->leader->idx; 36297f63e4aSNamhyung Kim } 363717e263fSNamhyung Kim 3642bcf7306SJiri Olsa /* Iterates group WITHOUT the leader. */ 365717e263fSNamhyung Kim #define for_each_group_member(_evsel, _leader) \ 366b27c4eceSJiri Olsa for ((_evsel) = list_entry((_leader)->core.node.next, struct evsel, core.node); \ 367717e263fSNamhyung Kim (_evsel) && (_evsel)->leader == (_leader); \ 368b27c4eceSJiri Olsa (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node)) 369717e263fSNamhyung Kim 3702bcf7306SJiri Olsa /* Iterates group WITH the leader. */ 3712bcf7306SJiri Olsa #define for_each_group_evsel(_evsel, _leader) \ 3722bcf7306SJiri Olsa for ((_evsel) = _leader; \ 3732bcf7306SJiri Olsa (_evsel) && (_evsel)->leader == (_leader); \ 374b27c4eceSJiri Olsa (_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node)) 3752bcf7306SJiri Olsa 37632dcd021SJiri Olsa static inline bool perf_evsel__has_branch_callstack(const struct evsel *evsel) 377384b6055SKan Liang { 3781fc632ceSJiri Olsa return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK; 379384b6055SKan Liang } 3802c5e8c52SPeter Zijlstra 38142bbabedSKan Liang static inline bool perf_evsel__has_branch_hw_idx(const struct evsel *evsel) 38242bbabedSKan Liang { 38342bbabedSKan Liang return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX; 38442bbabedSKan Liang } 38542bbabedSKan Liang 38632dcd021SJiri Olsa static inline bool evsel__has_callchain(const struct evsel *evsel) 38727de9b2bSArnaldo Carvalho de Melo { 388e11869a0SAdrian Hunter /* 389e11869a0SAdrian Hunter * For reporting purposes, an evsel sample can have a recorded callchain 390e11869a0SAdrian Hunter * or a callchain synthesized from AUX area data. 391e11869a0SAdrian Hunter */ 392e11869a0SAdrian Hunter return evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN || 393e11869a0SAdrian Hunter evsel->synth_sample_type & PERF_SAMPLE_CALLCHAIN; 39427de9b2bSArnaldo Carvalho de Melo } 39527de9b2bSArnaldo Carvalho de Melo 3966cd2cbfcSAdrian Hunter static inline bool evsel__has_br_stack(const struct evsel *evsel) 3976cd2cbfcSAdrian Hunter { 3986cd2cbfcSAdrian Hunter /* 3996cd2cbfcSAdrian Hunter * For reporting purposes, an evsel sample can have a recorded branch 4006cd2cbfcSAdrian Hunter * stack or a branch stack synthesized from AUX area data. 4016cd2cbfcSAdrian Hunter */ 4026cd2cbfcSAdrian Hunter return evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK || 4036cd2cbfcSAdrian Hunter evsel->synth_sample_type & PERF_SAMPLE_BRANCH_STACK; 4046cd2cbfcSAdrian Hunter } 4056cd2cbfcSAdrian Hunter 40632dcd021SJiri Olsa struct perf_env *perf_evsel__env(struct evsel *evsel); 407f4e47f9fSRavi Bangoria 40863503dbaSJiri Olsa int perf_evsel__store_ids(struct evsel *evsel, struct evlist *evlist); 40969aad6f1SArnaldo Carvalho de Melo #endif /* __PERF_EVSEL_H */ 410