xref: /linux/tools/perf/util/evsel.h (revision 4bb7c42dd54ec72d158f7c4da0e38ba0a73a0136)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_EVSEL_H
3 #define __PERF_EVSEL_H 1
4 
5 #include <stdbool.h>
6 
7 #include <linux/list.h>
8 #include <linux/perf_event.h>
9 #include <linux/refcount.h>
10 #include <linux/types.h>
11 #include <sys/types.h>
12 
13 #include <internal/evsel.h>
14 #include <perf/evsel.h>
15 
16 #include "symbol_conf.h"
17 
18 struct bperf_follower_bpf;
19 struct bperf_leader_bpf;
20 struct bpf_counter_ops;
21 struct bpf_object;
22 struct cgroup;
23 struct hashmap;
24 struct perf_counts;
25 struct perf_pmu;
26 struct perf_stat_config;
27 struct perf_stat_evsel;
28 struct target;
29 union perf_event;
30 
31 typedef int (evsel__sb_cb_t)(union perf_event *event, void *data);
32 
33 /** struct evsel - event selector
34  *
35  * @evlist - evlist this evsel is in, if it is in one.
36  * @core - libperf evsel object
37  * @name - Can be set to retain the original event name passed by the user,
38  *         so that when showing results in tools such as 'perf stat', we
39  *         show the name used, not some alias.
40  * @id_pos: the position of the event id (PERF_SAMPLE_ID or
41  *          PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
42  *          struct perf_record_sample
43  * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
44  *          PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
45  *          is used there is an id sample appended to non-sample events
46  * @priv:   And what is in its containing unnamed union are tool specific
47  */
48 struct evsel {
49 	struct perf_evsel	core;
50 	struct evlist		*evlist;
51 	refcount_t		refcnt;
52 	off_t			id_offset;
53 	int			id_pos;
54 	int			is_pos;
55 	unsigned int		sample_size;
56 	bool			merged_hybrid_group;
57 
58 	/*
59 	 * These fields can be set in the parse-events code or similar.
60 	 * Please check evsel__clone() to copy them properly so that
61 	 * they can be released properly.
62 	 */
63 	struct {
64 		char			*name;
65 		char			*group_name;
66 		const char		*group_pmu_name;
67 #ifdef HAVE_LIBTRACEEVENT
68 		char			*tp_sys;
69 		char			*tp_name;
70 		struct tep_event	*tp_format;
71 #endif
72 		char			*filter;
73 		unsigned long		max_events;
74 		double			scale;
75 		const char		*unit;
76 		struct cgroup		*cgrp;
77 		const char		*metric_id;
78 
79 		/* The PMU the event is from. Used for missing_features, PMU name, etc. */
80 		struct perf_pmu		*pmu;
81 
82 		/*
83 		 * This point to the first evsel with the same name, intended to store the
84 		 * aggregated counts in aggregation mode.
85 		 */
86 		struct evsel		*first_wildcard_match;
87 		/* parse modifier helper */
88 		int			exclude_GH;
89 		int			sample_read;
90 		bool			snapshot;
91 		bool			per_pkg;
92 		bool			percore;
93 		bool			precise_max;
94 		bool			is_libpfm_event;
95 		bool			collect_stat;
96 		bool			weak_group;
97 		bool			bpf_counter;
98 		bool			use_config_name;
99 		bool			skippable;
100 		bool			retire_lat;
101 		bool			dont_regroup;
102 		bool			default_metricgroup; /* A member of the Default metricgroup */
103 		bool			default_show_events; /* If a default group member, show the event */
104 		struct list_head	config_terms;
105 		u64			alternate_hw_config;
106 	};
107 
108 	/*
109 	 * metric fields are similar, but needs more care as they can have
110 	 * references to other metric (evsel).
111 	 */
112 	struct evsel		*metric_leader;
113 
114 	void			*handler;
115 	struct perf_counts	*counts;
116 	struct perf_counts	*prev_raw_counts;
117 	unsigned long		nr_events_printed;
118 	struct perf_stat_evsel  *stats;
119 	void			*priv;
120 	u64			db_id;
121 	bool			uniquified_name;
122 	bool 			supported;
123 	bool			support_probe;	/* Opened just to check for support. */
124 	bool 			needs_swap;
125 	bool 			disabled;
126 	bool			no_aux_samples;
127 	bool			immediate;
128 	bool			tracking;
129 	bool			ignore_missing_thread;
130 	bool			forced_leader;
131 	bool			cmdline_group_boundary;
132 	bool			reset_group;
133 	bool			needs_auxtrace_mmap;
134 	bool			needs_uniquify;
135 	bool			fallenback_eacces;
136 	bool			fallenback_eopnotsupp;
137 	u8			probe_type:3;
138 	struct hashmap		*per_pkg_mask;
139 	int			err;
140 	int			script_output_type;
141 	struct {
142 		evsel__sb_cb_t	*cb;
143 		void		*data;
144 	} side_band;
145 	/*
146 	 * For reporting purposes, an evsel sample can have a callchain
147 	 * synthesized from AUX area data. Keep track of synthesized sample
148 	 * types here. Note, the recorded sample_type cannot be changed because
149 	 * it is needed to continue to parse events.
150 	 * See also evsel__has_callchain().
151 	 */
152 	__u64			synth_sample_type;
153 
154 	/*
155 	 * Store the branch counter related information.
156 	 * br_cntr_idx: The idx of the branch counter event in the evlist
157 	 * br_cntr_nr:  The number of the branch counter event in the group
158 	 *	        (Only available for the leader event)
159 	 * abbr_name:   The abbreviation name assigned to an event which is
160 	 *		logged by the branch counter.
161 	 *		The abbr name is from A to Z9. NA is applied if out
162 	 *		of the range.
163 	 */
164 	int			br_cntr_idx;
165 	int			br_cntr_nr;
166 	char			abbr_name[3];
167 
168 	/*
169 	 * bpf_counter_ops serves two use cases:
170 	 *   1. perf-stat -b          counting events used byBPF programs
171 	 *   2. perf-stat --use-bpf   use BPF programs to aggregate counts
172 	 */
173 	struct bpf_counter_ops	*bpf_counter_ops;
174 
175 	struct list_head	bpf_counter_list; /* for perf-stat -b */
176 	struct list_head	bpf_filters; /* for perf-record --filter */
177 
178 	/* for perf-stat --use-bpf */
179 	int			bperf_leader_prog_fd;
180 	int			bperf_leader_link_fd;
181 	union {
182 		struct bperf_leader_bpf *leader_skel;
183 		struct bperf_follower_bpf *follower_skel;
184 		void *bpf_skel;
185 	};
186 	unsigned long		open_flags;
187 	int			precise_ip_original;
188 
189 	/* For tool events */
190 	/* Beginning time subtracted when the counter is read. */
191 	union {
192 		/* Defaults for retirement latency events. */
193 		struct _retirement_latency {
194 			double mean;
195 			double min;
196 			double max;
197 		} retirement_latency;
198 		/* duration_time is a single global time. */
199 		struct {
200 			__u64 start_time;
201 			__u64 accumulated_time;
202 		} duration_time;
203 		/*
204 		 * user_time and system_time read an initial value potentially
205 		 * per-CPU or per-pid.
206 		 */
207 		struct {
208 			struct xyarray *start_times;
209 			struct xyarray *accumulated_times;
210 		} process_time;
211 	};
212 	/* Is the tool's fd for /proc/pid/stat or /proc/stat. */
213 	bool pid_stat;
214 };
215 
216 struct perf_missing_features {
217 	bool sample_id_all;
218 	bool exclude_guest;
219 	bool mmap2;
220 	bool cloexec;
221 	bool clockid;
222 	bool clockid_wrong;
223 	bool lbr_flags;
224 	bool write_backward;
225 	bool group_read;
226 	bool ksymbol;
227 	bool bpf;
228 	bool aux_output;
229 	bool branch_hw_idx;
230 	bool cgroup;
231 	bool data_page_size;
232 	bool code_page_size;
233 	bool weight_struct;
234 	bool read_lost;
235 	bool branch_counters;
236 	bool aux_action;
237 	bool inherit_sample_read;
238 	bool defer_callchain;
239 };
240 
241 extern struct perf_missing_features perf_missing_features;
242 
243 struct perf_cpu_map;
244 struct thread_map;
245 struct record_opts;
246 
247 static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel)
248 {
249 	return perf_evsel__cpus(&evsel->core);
250 }
251 
252 static inline int evsel__nr_cpus(struct evsel *evsel)
253 {
254 	return perf_cpu_map__nr(evsel__cpus(evsel));
255 }
256 
257 void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
258 			   struct perf_counts_values *count);
259 
260 int evsel__object_config(size_t object_size,
261 			 int (*init)(struct evsel *evsel),
262 			 void (*fini)(struct evsel *evsel));
263 
264 struct perf_pmu *evsel__find_pmu(const struct evsel *evsel);
265 const char *evsel__pmu_name(const struct evsel *evsel);
266 bool evsel__is_aux_event(const struct evsel *evsel);
267 
268 bool evsel__is_probe(struct evsel *evsel);
269 bool evsel__is_kprobe(struct evsel *evsel);
270 bool evsel__is_uprobe(struct evsel *evsel);
271 
272 struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx);
273 
274 static inline struct evsel *evsel__new(struct perf_event_attr *attr)
275 {
276 	return evsel__new_idx(attr, 0);
277 }
278 
279 struct evsel *evsel__clone(struct evsel *orig);
280 
281 int copy_config_terms(struct list_head *dst, struct list_head *src);
282 void free_config_terms(struct list_head *config_terms);
283 
284 
285 /*
286  * Returns pointer with encoded error via <linux/err.h> interface.
287  */
288 struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx, bool format);
289 static inline struct evsel *evsel__newtp(const char *sys, const char *name)
290 {
291 	return evsel__newtp_idx(sys, name, 0, true);
292 }
293 
294 struct evsel *evsel__get(struct evsel *evsel);
295 void evsel__put(struct evsel *evsel);
296 
297 #ifdef HAVE_LIBTRACEEVENT
298 struct tep_event *evsel__tp_format(struct evsel *evsel);
299 #endif
300 
301 void evsel__set_priv_destructor(void (*destructor)(void *priv));
302 
303 struct callchain_param;
304 
305 void evsel__config(struct evsel *evsel, const struct record_opts *opts,
306 		   const struct callchain_param *callchain);
307 void evsel__config_callchain(struct evsel *evsel, const struct record_opts *opts,
308 			     const  struct callchain_param *callchain);
309 
310 int __evsel__sample_size(u64 sample_type);
311 void evsel__calc_id_pos(struct evsel *evsel);
312 
313 bool evsel__is_cache_op_valid(u8 type, u8 op);
314 
315 static inline bool evsel__is_bpf(struct evsel *evsel)
316 {
317 	return evsel->bpf_counter_ops != NULL;
318 }
319 
320 static inline bool evsel__is_bperf(struct evsel *evsel)
321 {
322 	return evsel->bpf_counter_ops != NULL && list_empty(&evsel->bpf_counter_list);
323 }
324 
325 #define EVSEL__MAX_ALIASES 8
326 
327 extern const char *const evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES];
328 extern const char *const evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__MAX_ALIASES];
329 extern const char *const evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][EVSEL__MAX_ALIASES];
330 extern const char *const evsel__hw_names[PERF_COUNT_HW_MAX];
331 extern const char *const evsel__sw_names[PERF_COUNT_SW_MAX];
332 extern char *evsel__bpf_counter_events;
333 bool evsel__match_bpf_counter_events(const char *name);
334 int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size);
335 
336 int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size);
337 const char *evsel__name(struct evsel *evsel);
338 bool evsel__name_is(struct evsel *evsel, const char *name);
339 const char *evsel__metric_id(const struct evsel *evsel);
340 
341 static inline bool evsel__is_retire_lat(const struct evsel *evsel)
342 {
343 	return evsel->retire_lat;
344 }
345 
346 const char *evsel__group_name(struct evsel *evsel);
347 int evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
348 
349 void __evsel__set_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit);
350 void __evsel__reset_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit);
351 
352 #define evsel__set_sample_bit(evsel, bit) \
353 	__evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
354 
355 #define evsel__reset_sample_bit(evsel, bit) \
356 	__evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
357 
358 void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
359 
360 void arch_evsel__set_sample_weight(struct evsel *evsel);
361 void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr);
362 int arch_evsel__open_strerror(struct evsel *evsel, int err, char *msg, size_t size);
363 void arch_evsel__apply_ratio_to_prev(struct evsel *evsel, struct perf_event_attr *attr);
364 
365 int evsel__set_filter(struct evsel *evsel, const char *filter);
366 int evsel__append_tp_filter(struct evsel *evsel, const char *filter);
367 int evsel__append_addr_filter(struct evsel *evsel, const char *filter);
368 
369 int evsel__enable_cpu(struct evsel *evsel, int cpu_map_idx);
370 int evsel__enable(struct evsel *evsel);
371 int evsel__disable(struct evsel *evsel);
372 int evsel__disable_cpu(struct evsel *evsel, int cpu_map_idx);
373 
374 int evsel__open_per_cpu_and_thread(struct evsel *evsel,
375 				   struct perf_cpu_map *cpus, int cpu_map_idx,
376 				   struct perf_thread_map *threads);
377 int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx);
378 int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads);
379 int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
380 		struct perf_thread_map *threads);
381 void evsel__close(struct evsel *evsel);
382 int evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
383 		struct perf_thread_map *threads);
384 
385 bool evsel__precise_ip_fallback(struct evsel *evsel);
386 
387 struct perf_sample;
388 
389 #ifdef HAVE_LIBTRACEEVENT
390 void *perf_sample__rawptr(struct perf_sample *sample, const char *name);
391 u64 perf_sample__intval(struct perf_sample *sample, const char *name);
392 u64 perf_sample__intval_common(struct perf_sample *sample, const char *name);
393 char perf_sample__taskstate(struct perf_sample *sample, const char *name);
394 
395 static inline char *perf_sample__strval(struct perf_sample *sample, const char *name)
396 {
397 	return perf_sample__rawptr(sample, name);
398 }
399 #endif
400 
401 struct tep_format_field;
402 
403 void *format_field__get_raw_data(struct tep_format_field *field,
404 				 struct perf_sample *sample,
405 				 bool needs_swap, u16 *len_out);
406 unsigned long *format_field__get_cpumask(struct tep_format_field *field,
407 					 struct perf_sample *sample,
408 					 bool needs_swap, u16 *len_out);
409 u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap);
410 
411 #ifdef HAVE_LIBTRACEEVENT
412 struct tep_format_field *evsel__field(struct evsel *evsel, const char *name);
413 struct tep_format_field *evsel__common_field(struct evsel *evsel, const char *name);
414 #else
415 static inline struct tep_format_field *
416 evsel__field(struct evsel *evsel __maybe_unused, const char *name __maybe_unused)
417 {
418 	return NULL;
419 }
420 
421 static inline struct tep_format_field *
422 evsel__common_field(struct evsel *evsel __maybe_unused, const char *name __maybe_unused)
423 {
424 	return NULL;
425 }
426 #endif
427 
428 bool __evsel__match(const struct evsel *evsel, u32 type, u64 config);
429 
430 #define evsel__match(evsel, t, c) __evsel__match(evsel, PERF_TYPE_##t, PERF_COUNT_##c)
431 
432 int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread);
433 
434 int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread, bool scale);
435 
436 /**
437  * evsel__read_on_cpu - Read out the results on a CPU and thread
438  *
439  * @evsel - event selector to read value
440  * @cpu_map_idx - CPU of interest
441  * @thread - thread of interest
442  */
443 static inline int evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread)
444 {
445 	return __evsel__read_on_cpu(evsel, cpu_map_idx, thread, false);
446 }
447 
448 /**
449  * evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
450  *
451  * @evsel - event selector to read value
452  * @cpu_map_idx - CPU of interest
453  * @thread - thread of interest
454  */
455 static inline int evsel__read_on_cpu_scaled(struct evsel *evsel, int cpu_map_idx, int thread)
456 {
457 	return __evsel__read_on_cpu(evsel, cpu_map_idx, thread, true);
458 }
459 
460 int __evsel__parse_sample(struct evsel *evsel, union perf_event *event,
461 			  struct perf_sample *data, bool needs_swap);
462 
463 static inline int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
464 				      struct perf_sample *data)
465 {
466 	return __evsel__parse_sample(evsel, event, data, evsel->needs_swap);
467 }
468 
469 int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event,
470 				  u64 *timestamp);
471 
472 u16 evsel__id_hdr_size(const struct evsel *evsel);
473 u16 evsel__event_size(const struct evsel *evsel, const union perf_event *event);
474 
475 static inline struct evsel *evsel__next(struct evsel *evsel)
476 {
477 	return list_entry(evsel->core.node.next, struct evsel, core.node);
478 }
479 
480 static inline struct evsel *evsel__prev(struct evsel *evsel)
481 {
482 	return list_entry(evsel->core.node.prev, struct evsel, core.node);
483 }
484 
485 /**
486  * evsel__is_group_leader - Return whether given evsel is a leader event
487  *
488  * @evsel - evsel selector to be tested
489  *
490  * Return %true if @evsel is a group leader or a stand-alone event
491  */
492 static inline bool evsel__is_group_leader(const struct evsel *evsel)
493 {
494 	return evsel->core.leader == &evsel->core;
495 }
496 
497 /**
498  * evsel__is_group_event - Return whether given evsel is a group event
499  *
500  * @evsel - evsel selector to be tested
501  *
502  * Return %true iff event group view is enabled and @evsel is a actual group
503  * leader which has other members in the group
504  */
505 static inline bool evsel__is_group_event(struct evsel *evsel)
506 {
507 	if (!symbol_conf.event_group)
508 		return false;
509 
510 	return evsel__is_group_leader(evsel) && evsel->core.nr_members > 1;
511 }
512 
513 bool evsel__is_non_perf_event_open_pmu(const struct evsel *evsel);
514 bool evsel__is_function_event(struct evsel *evsel);
515 
516 static inline bool evsel__is_bpf_output(struct evsel *evsel)
517 {
518 	return evsel__match(evsel, SOFTWARE, SW_BPF_OUTPUT);
519 }
520 
521 static inline bool evsel__is_clock(const struct evsel *evsel)
522 {
523 	return evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) ||
524 	       evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK);
525 }
526 
527 bool evsel__fallback(struct evsel *evsel, struct target *target, int err,
528 		     char *msg, size_t msgsize);
529 int evsel__open_strerror(struct evsel *evsel, struct target *target,
530 			 int err, char *msg, size_t size);
531 
532 static inline int evsel__group_idx(struct evsel *evsel)
533 {
534 	return evsel->core.idx - evsel->core.leader->idx;
535 }
536 
537 /* Iterates group WITHOUT the leader. */
538 #define for_each_group_member_head(_evsel, _leader, _head)				\
539 for ((_evsel) = list_entry((_leader)->core.node.next, struct evsel, core.node);		\
540 	(_evsel) && &(_evsel)->core.node != (_head) &&					\
541 	(_evsel)->core.leader == &(_leader)->core;					\
542 	(_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
543 
544 #define for_each_group_member(_evsel, _leader)				\
545 	for_each_group_member_head(_evsel, _leader, &evlist__core((_leader)->evlist)->entries)
546 
547 /* Iterates group WITH the leader. */
548 #define for_each_group_evsel_head(_evsel, _leader, _head)				\
549 for ((_evsel) = _leader;								\
550 	(_evsel) && &(_evsel)->core.node != (_head) &&					\
551 	(_evsel)->core.leader == &(_leader)->core;					\
552 	(_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
553 
554 #define for_each_group_evsel(_evsel, _leader)				\
555 	for_each_group_evsel_head(_evsel, _leader, &evlist__core((_leader)->evlist)->entries)
556 
557 static inline bool evsel__has_branch_callstack(const struct evsel *evsel)
558 {
559 	return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
560 }
561 
562 static inline bool evsel__has_branch_hw_idx(const struct evsel *evsel)
563 {
564 	return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX;
565 }
566 
567 static inline bool evsel__has_callchain(const struct evsel *evsel)
568 {
569 	/*
570 	 * For reporting purposes, an evsel sample can have a recorded callchain
571 	 * or a callchain synthesized from AUX area data.
572 	 */
573 	return evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN ||
574 	       evsel->synth_sample_type & PERF_SAMPLE_CALLCHAIN;
575 }
576 
577 static inline bool evsel__has_br_stack(const struct evsel *evsel)
578 {
579 	/*
580 	 * For reporting purposes, an evsel sample can have a recorded branch
581 	 * stack or a branch stack synthesized from AUX area data.
582 	 */
583 	return evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK ||
584 	       evsel->synth_sample_type & PERF_SAMPLE_BRANCH_STACK;
585 }
586 
587 static inline bool evsel__is_dummy_event(struct evsel *evsel)
588 {
589 	return (evsel->core.attr.type == PERF_TYPE_SOFTWARE) &&
590 	       (evsel->core.attr.config == PERF_COUNT_SW_DUMMY);
591 }
592 
593 static inline bool evsel__is_non_software_event(struct evsel *evsel)
594 {
595 	return (evsel->core.attr.type != PERF_TYPE_SOFTWARE) &&
596 	       (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) &&
597 	       (evsel->core.attr.type != PERF_TYPE_BREAKPOINT);
598 }
599 
600 struct perf_session *evsel__session(struct evsel *evsel);
601 struct perf_env *evsel__env(struct evsel *evsel);
602 uint16_t evsel__e_machine(struct evsel *evsel, uint32_t *e_flags);
603 
604 int evsel__store_ids(struct evsel *evsel, struct evlist *evlist);
605 
606 void evsel__zero_per_pkg(struct evsel *evsel);
607 bool evsel__is_hybrid(const struct evsel *evsel);
608 struct evsel *evsel__leader(const struct evsel *evsel);
609 bool evsel__has_leader(struct evsel *evsel, struct evsel *leader);
610 bool evsel__is_leader(struct evsel *evsel);
611 void evsel__set_leader(struct evsel *evsel, struct evsel *leader);
612 int evsel__source_count(const struct evsel *evsel);
613 void evsel__remove_from_group(struct evsel *evsel, struct evsel *leader);
614 
615 bool arch_evsel__must_be_in_group(const struct evsel *evsel);
616 
617 bool evsel__set_needs_uniquify(struct evsel *counter, const struct perf_stat_config *config);
618 void evsel__uniquify_counter(struct evsel *counter);
619 
620 /*
621  * Macro to swap the bit-field postition and size.
622  * Used when,
623  * - dont need to swap the entire u64 &&
624  * - when u64 has variable bit-field sizes &&
625  * - when presented in a host endian which is different
626  *   than the source endian of the perf.data file
627  */
628 #define bitfield_swap(src, pos, size)	\
629 	((((src) >> (pos)) & ((1ull << (size)) - 1)) << (63 - ((pos) + (size) - 1)))
630 
631 u64 evsel__bitfield_swap_branch_flags(u64 value);
632 bool evsel__config_exists(const struct evsel *evsel, const char *config_name);
633 int evsel__get_config_val(const struct evsel *evsel, const char *config_name,
634 			  u64 *val);
635 void evsel__set_config_if_unset(struct evsel *evsel, const char *config_name,
636 				u64 val);
637 
638 bool evsel__is_offcpu_event(struct evsel *evsel);
639 
640 void evsel__warn_user_requested_cpus(struct evsel *evsel, struct perf_cpu_map *user_requested_cpus);
641 
642 #endif /* __PERF_EVSEL_H */
643