xref: /linux/tools/perf/util/evsel.h (revision 7c48dcfd32b45b69aa8d5e81108fff8c7a2272ed)
169aad6f1SArnaldo Carvalho de Melo #ifndef __PERF_EVSEL_H
269aad6f1SArnaldo Carvalho de Melo #define __PERF_EVSEL_H 1
369aad6f1SArnaldo Carvalho de Melo 
469aad6f1SArnaldo Carvalho de Melo #include <linux/list.h>
5c52b12edSArnaldo Carvalho de Melo #include <stdbool.h>
607ac002fSArnaldo Carvalho de Melo #include <stddef.h>
7d2709c7cSDavid Howells #include <linux/perf_event.h>
8d944c4eeSBorislav Petkov #include <linux/types.h>
969aad6f1SArnaldo Carvalho de Melo #include "xyarray.h"
10759ff497SNamhyung Kim #include "symbol.h"
11a22e99cdSJiri Olsa #include "cpumap.h"
12d809560bSJiri Olsa #include "counts.h"
13c52b12edSArnaldo Carvalho de Melo 
1470db7533SArnaldo Carvalho de Melo struct perf_evsel;
1570db7533SArnaldo Carvalho de Melo 
1670db7533SArnaldo Carvalho de Melo /*
1770db7533SArnaldo Carvalho de Melo  * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
1870db7533SArnaldo Carvalho de Melo  * more than one entry in the evlist.
1970db7533SArnaldo Carvalho de Melo  */
2070db7533SArnaldo Carvalho de Melo struct perf_sample_id {
2170db7533SArnaldo Carvalho de Melo 	struct hlist_node 	node;
2270db7533SArnaldo Carvalho de Melo 	u64		 	id;
2370db7533SArnaldo Carvalho de Melo 	struct perf_evsel	*evsel;
243c659eedSAdrian Hunter 	int			idx;
253c659eedSAdrian Hunter 	int			cpu;
263c659eedSAdrian Hunter 	pid_t			tid;
27e4caec0dSJiri Olsa 
28e4caec0dSJiri Olsa 	/* Holds total ID period value for PERF_SAMPLE_READ processing. */
29e4caec0dSJiri Olsa 	u64			period;
3070db7533SArnaldo Carvalho de Melo };
3170db7533SArnaldo Carvalho de Melo 
32f14d5707SArnaldo Carvalho de Melo struct cgroup_sel;
33f14d5707SArnaldo Carvalho de Melo 
34930a2e29SJiri Olsa /*
35930a2e29SJiri Olsa  * The 'struct perf_evsel_config_term' is used to pass event
36930a2e29SJiri Olsa  * specific configuration data to perf_evsel__config routine.
37930a2e29SJiri Olsa  * It is allocated within event parsing and attached to
38930a2e29SJiri Olsa  * perf_evsel::config_terms list head.
39930a2e29SJiri Olsa */
40930a2e29SJiri Olsa enum {
41ee4c7588SJiri Olsa 	PERF_EVSEL__CONFIG_TERM_PERIOD,
4209af2a55SNamhyung Kim 	PERF_EVSEL__CONFIG_TERM_FREQ,
4332067712SKan Liang 	PERF_EVSEL__CONFIG_TERM_TIME,
44d457c963SKan Liang 	PERF_EVSEL__CONFIG_TERM_CALLGRAPH,
45d457c963SKan Liang 	PERF_EVSEL__CONFIG_TERM_STACK_USER,
46374ce938SWang Nan 	PERF_EVSEL__CONFIG_TERM_INHERIT,
47792d48b4SArnaldo Carvalho de Melo 	PERF_EVSEL__CONFIG_TERM_MAX_STACK,
48626a6b78SWang Nan 	PERF_EVSEL__CONFIG_TERM_OVERWRITE,
49930a2e29SJiri Olsa 	PERF_EVSEL__CONFIG_TERM_MAX,
50930a2e29SJiri Olsa };
51930a2e29SJiri Olsa 
52930a2e29SJiri Olsa struct perf_evsel_config_term {
53930a2e29SJiri Olsa 	struct list_head	list;
54930a2e29SJiri Olsa 	int	type;
55930a2e29SJiri Olsa 	union {
56930a2e29SJiri Olsa 		u64	period;
5709af2a55SNamhyung Kim 		u64	freq;
5832067712SKan Liang 		bool	time;
59d457c963SKan Liang 		char	*callgraph;
60d457c963SKan Liang 		u64	stack_user;
61792d48b4SArnaldo Carvalho de Melo 		int	max_stack;
62374ce938SWang Nan 		bool	inherit;
63626a6b78SWang Nan 		bool	overwrite;
64930a2e29SJiri Olsa 	} val;
65930a2e29SJiri Olsa };
66930a2e29SJiri Olsa 
67f0c55bcfSStephane Eranian /** struct perf_evsel - event selector
68f0c55bcfSStephane Eranian  *
69d49e4695SArnaldo Carvalho de Melo  * @evlist - evlist this evsel is in, if it is in one.
70d49e4695SArnaldo Carvalho de Melo  * @node - To insert it into evlist->entries or in other list_heads, say in
71d49e4695SArnaldo Carvalho de Melo  *         the event parsing routines.
72f0c55bcfSStephane Eranian  * @name - Can be set to retain the original event name passed by the user,
73f0c55bcfSStephane Eranian  *         so that when showing results in tools such as 'perf stat', we
74f0c55bcfSStephane Eranian  *         show the name used, not some alias.
7575562573SAdrian Hunter  * @id_pos: the position of the event id (PERF_SAMPLE_ID or
7675562573SAdrian Hunter  *          PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
7775562573SAdrian Hunter  *          struct sample_event
7875562573SAdrian Hunter  * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
7975562573SAdrian Hunter  *          PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
8075562573SAdrian Hunter  *          is used there is an id sample appended to non-sample events
810db15b1eSAdrian Hunter  * @priv:   And what is in its containing unnamed union are tool specific
82f0c55bcfSStephane Eranian  */
8369aad6f1SArnaldo Carvalho de Melo struct perf_evsel {
8469aad6f1SArnaldo Carvalho de Melo 	struct list_head	node;
85d49e4695SArnaldo Carvalho de Melo 	struct perf_evlist	*evlist;
8669aad6f1SArnaldo Carvalho de Melo 	struct perf_event_attr	attr;
8769aad6f1SArnaldo Carvalho de Melo 	char			*filter;
8869aad6f1SArnaldo Carvalho de Melo 	struct xyarray		*fd;
89a91e5431SArnaldo Carvalho de Melo 	struct xyarray		*sample_id;
90a91e5431SArnaldo Carvalho de Melo 	u64			*id;
91c52b12edSArnaldo Carvalho de Melo 	struct perf_counts	*counts;
92c7a79c47SStephane Eranian 	struct perf_counts	*prev_raw_counts;
9369aad6f1SArnaldo Carvalho de Melo 	int			idx;
94f4d83436SRobert Richter 	u32			ids;
95f0c55bcfSStephane Eranian 	char			*name;
96410136f5SStephane Eranian 	double			scale;
97410136f5SStephane Eranian 	const char		*unit;
98fcf65bf1SArnaldo Carvalho de Melo 	struct event_format	*tp_format;
99af339981SJiri Olsa 	off_t			id_offset;
10069aad6f1SArnaldo Carvalho de Melo 	void			*priv;
1010db15b1eSAdrian Hunter 	u64			db_id;
102023695d9SStephane Eranian 	struct cgroup_sel	*cgrp;
103744a9719SArnaldo Carvalho de Melo 	void			*handler;
1047ae92e74SYan, Zheng 	struct cpu_map		*cpus;
105fce4d296SAdrian Hunter 	struct cpu_map		*own_cpus;
106578e91ecSJiri Olsa 	struct thread_map	*threads;
107bde09467SArnaldo Carvalho de Melo 	unsigned int		sample_size;
10875562573SAdrian Hunter 	int			id_pos;
10975562573SAdrian Hunter 	int			is_pos;
11086066064SArnaldo Carvalho de Melo 	bool			snapshot;
1112cee77c4SDavid Ahern 	bool 			supported;
1120807d2d8SArnaldo Carvalho de Melo 	bool 			needs_swap;
1136ff1ce76SAdrian Hunter 	bool			no_aux_samples;
1142afd2bcfSAdrian Hunter 	bool			immediate;
115bf8e8f4bSAdrian Hunter 	bool			system_wide;
11660b0896cSAdrian Hunter 	bool			tracking;
117044330c1SMatt Fleming 	bool			per_pkg;
1187f94af7aSJiri Olsa 	bool			precise_max;
119f5b1135bSJiri Olsa 	/* parse modifier helper */
120f5b1135bSJiri Olsa 	int			exclude_GH;
12197f63e4aSNamhyung Kim 	int			nr_members;
1223c176311SJiri Olsa 	int			sample_read;
12386066064SArnaldo Carvalho de Melo 	unsigned long		*per_pkg_mask;
1246a4bb04cSJiri Olsa 	struct perf_evsel	*leader;
1256a4bb04cSJiri Olsa 	char			*group_name;
12615bfd2ccSWang Nan 	bool			cmdline_group_boundary;
127930a2e29SJiri Olsa 	struct list_head	config_terms;
1281f45b1d4SWang Nan 	int			bpf_fd;
12969aad6f1SArnaldo Carvalho de Melo };
13069aad6f1SArnaldo Carvalho de Melo 
13188080ce7SBorislav Petkov union u64_swap {
13288080ce7SBorislav Petkov 	u64 val64;
13388080ce7SBorislav Petkov 	u32 val32[2];
13488080ce7SBorislav Petkov };
13588080ce7SBorislav Petkov 
13686bd5e86SArnaldo Carvalho de Melo struct 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 
141a22e99cdSJiri Olsa static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)
142a22e99cdSJiri Olsa {
143a22e99cdSJiri Olsa 	return evsel->cpus;
144a22e99cdSJiri Olsa }
145a22e99cdSJiri Olsa 
146a22e99cdSJiri Olsa static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel)
147a22e99cdSJiri Olsa {
148a22e99cdSJiri Olsa 	return perf_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 
154a6fa0038SJiri Olsa void perf_evsel__compute_deltas(struct perf_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,
158ce8ccff5SArnaldo Carvalho de Melo 			      int (*init)(struct perf_evsel *evsel),
159ce8ccff5SArnaldo Carvalho de Melo 			      void (*fini)(struct perf_evsel *evsel));
160ce8ccff5SArnaldo Carvalho de Melo 
161ef503831SArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
162ef503831SArnaldo Carvalho de Melo 
163ef503831SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
164ef503831SArnaldo Carvalho de Melo {
165ef503831SArnaldo Carvalho de Melo 	return perf_evsel__new_idx(attr, 0);
166ef503831SArnaldo Carvalho de Melo }
167ef503831SArnaldo Carvalho de Melo 
168ef503831SArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
169ef503831SArnaldo Carvalho de Melo 
1708dd2a131SJiri Olsa /*
1718dd2a131SJiri Olsa  * Returns pointer with encoded error via <linux/err.h> interface.
1728dd2a131SJiri Olsa  */
173ef503831SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
174ef503831SArnaldo Carvalho de Melo {
175ef503831SArnaldo Carvalho de Melo 	return perf_evsel__newtp_idx(sys, name, 0);
176ef503831SArnaldo Carvalho de Melo }
177201b7334SArnaldo Carvalho de Melo 
178*7c48dcfdSArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__new_cycles(void);
179*7c48dcfdSArnaldo Carvalho de Melo 
180201b7334SArnaldo Carvalho de Melo struct event_format *event_format__new(const char *sys, const char *name);
181201b7334SArnaldo Carvalho de Melo 
182ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__init(struct perf_evsel *evsel,
183ef1d1af2SArnaldo Carvalho de Melo 		      struct perf_event_attr *attr, int idx);
184ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__exit(struct perf_evsel *evsel);
18569aad6f1SArnaldo Carvalho de Melo void perf_evsel__delete(struct perf_evsel *evsel);
18669aad6f1SArnaldo Carvalho de Melo 
187e68ae9cfSArnaldo Carvalho de Melo struct callchain_param;
188e68ae9cfSArnaldo Carvalho de Melo 
1890f82ebc4SArnaldo Carvalho de Melo void perf_evsel__config(struct perf_evsel *evsel,
190e68ae9cfSArnaldo Carvalho de Melo 			struct record_opts *opts,
191e68ae9cfSArnaldo Carvalho de Melo 			struct callchain_param *callchain);
19201e0d50cSArnaldo Carvalho de Melo void perf_evsel__config_callchain(struct perf_evsel *evsel,
19301e0d50cSArnaldo Carvalho de Melo 				  struct record_opts *opts,
19401e0d50cSArnaldo Carvalho de Melo 				  struct callchain_param *callchain);
1950f82ebc4SArnaldo Carvalho de Melo 
19675562573SAdrian Hunter int __perf_evsel__sample_size(u64 sample_type);
19775562573SAdrian Hunter void perf_evsel__calc_id_pos(struct perf_evsel *evsel);
19875562573SAdrian Hunter 
1990b668bc9SArnaldo Carvalho de Melo bool perf_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];
2110b668bc9SArnaldo Carvalho de Melo int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
2120b668bc9SArnaldo Carvalho de Melo 					    char *bf, size_t size);
2137289f83cSArnaldo Carvalho de Melo const char *perf_evsel__name(struct perf_evsel *evsel);
214410136f5SStephane Eranian 
215717e263fSNamhyung Kim const char *perf_evsel__group_name(struct perf_evsel *evsel);
216717e263fSNamhyung Kim int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
217c410431cSArnaldo Carvalho de Melo 
21870db7533SArnaldo Carvalho de Melo int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
219c52b12edSArnaldo Carvalho de Melo void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
22069aad6f1SArnaldo Carvalho de Melo 
2217be5ebe8SArnaldo Carvalho de Melo void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
2227be5ebe8SArnaldo Carvalho de Melo 				  enum perf_event_sample_format bit);
2237be5ebe8SArnaldo Carvalho de Melo void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
2247be5ebe8SArnaldo Carvalho de Melo 				    enum perf_event_sample_format bit);
2257be5ebe8SArnaldo Carvalho de Melo 
2267be5ebe8SArnaldo Carvalho de Melo #define perf_evsel__set_sample_bit(evsel, bit) \
2277be5ebe8SArnaldo Carvalho de Melo 	__perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
2287be5ebe8SArnaldo Carvalho de Melo 
2297be5ebe8SArnaldo Carvalho de Melo #define perf_evsel__reset_sample_bit(evsel, bit) \
2307be5ebe8SArnaldo Carvalho de Melo 	__perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
2317be5ebe8SArnaldo Carvalho de Melo 
23275562573SAdrian Hunter void perf_evsel__set_sample_id(struct perf_evsel *evsel,
23375562573SAdrian Hunter 			       bool use_sample_identifier);
2347a5a5ca5SArnaldo Carvalho de Melo 
23512467ae4SArnaldo Carvalho de Melo int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter);
23664ec84f5SArnaldo Carvalho de Melo int perf_evsel__append_filter(struct perf_evsel *evsel,
23764ec84f5SArnaldo Carvalho de Melo 			      const char *op, const char *filter);
238f47805a2SArnaldo Carvalho de Melo int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
239745cefc5SArnaldo Carvalho de Melo 			     const char *filter);
2405cd95fc3SJiri Olsa int perf_evsel__enable(struct perf_evsel *evsel);
241e98a4cbbSJiri Olsa int perf_evsel__disable(struct perf_evsel *evsel);
242745cefc5SArnaldo Carvalho de Melo 
243f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
2446a4bb04cSJiri Olsa 			     struct cpu_map *cpus);
245f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_thread(struct perf_evsel *evsel,
2466a4bb04cSJiri Olsa 				struct thread_map *threads);
247f08199d3SArnaldo Carvalho de Melo int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
2486a4bb04cSJiri Olsa 		     struct thread_map *threads);
249727ab04eSArnaldo Carvalho de Melo void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
25048290609SArnaldo Carvalho de Melo 
2515555ded4SArnaldo Carvalho de Melo struct perf_sample;
2525555ded4SArnaldo Carvalho de Melo 
2535d2074eaSArnaldo Carvalho de Melo void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
2545555ded4SArnaldo Carvalho de Melo 			 const char *name);
2555555ded4SArnaldo Carvalho de Melo u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
2565555ded4SArnaldo Carvalho de Melo 		       const char *name);
2575555ded4SArnaldo Carvalho de Melo 
2585d2074eaSArnaldo Carvalho de Melo static inline char *perf_evsel__strval(struct perf_evsel *evsel,
2595d2074eaSArnaldo Carvalho de Melo 				       struct perf_sample *sample,
2605d2074eaSArnaldo Carvalho de Melo 				       const char *name)
2615d2074eaSArnaldo Carvalho de Melo {
2625d2074eaSArnaldo Carvalho de Melo 	return perf_evsel__rawptr(evsel, sample, name);
2635d2074eaSArnaldo Carvalho de Melo }
2645d2074eaSArnaldo Carvalho de Melo 
265efd2b924SArnaldo Carvalho de Melo struct format_field;
266efd2b924SArnaldo Carvalho de Melo 
26790525176SArnaldo Carvalho de Melo u64 format_field__intval(struct format_field *field, struct perf_sample *sample, bool needs_swap);
26890525176SArnaldo Carvalho de Melo 
269efd2b924SArnaldo Carvalho de Melo struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
270efd2b924SArnaldo Carvalho de Melo 
271daec78a0SArnaldo Carvalho de Melo #define perf_evsel__match(evsel, t, c)		\
272daec78a0SArnaldo Carvalho de Melo 	(evsel->attr.type == PERF_TYPE_##t &&	\
273daec78a0SArnaldo Carvalho de Melo 	 evsel->attr.config == PERF_COUNT_##c)
274daec78a0SArnaldo Carvalho de Melo 
275863e451fSJiri Olsa static inline bool perf_evsel__match2(struct perf_evsel *e1,
276863e451fSJiri Olsa 				      struct perf_evsel *e2)
277863e451fSJiri Olsa {
278863e451fSJiri Olsa 	return (e1->attr.type == e2->attr.type) &&
279863e451fSJiri Olsa 	       (e1->attr.config == e2->attr.config);
280863e451fSJiri Olsa }
281863e451fSJiri Olsa 
2824cabc3d1SAndi Kleen #define perf_evsel__cmp(a, b)			\
2834cabc3d1SAndi Kleen 	((a) &&					\
2844cabc3d1SAndi Kleen 	 (b) &&					\
2854cabc3d1SAndi Kleen 	 (a)->attr.type == (b)->attr.type &&	\
2864cabc3d1SAndi Kleen 	 (a)->attr.config == (b)->attr.config)
2874cabc3d1SAndi Kleen 
288f99f4719SJiri Olsa int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
289f99f4719SJiri Olsa 		     struct perf_counts_values *count);
290f99f4719SJiri Olsa 
291c52b12edSArnaldo Carvalho de Melo int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
292c52b12edSArnaldo Carvalho de Melo 			      int cpu, int thread, bool scale);
293c52b12edSArnaldo Carvalho de Melo 
294c52b12edSArnaldo Carvalho de Melo /**
295c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
296c52b12edSArnaldo Carvalho de Melo  *
297c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
298c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
299c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
300c52b12edSArnaldo Carvalho de Melo  */
301c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
302c52b12edSArnaldo Carvalho de Melo 					  int cpu, int thread)
303c52b12edSArnaldo Carvalho de Melo {
304c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
305c52b12edSArnaldo Carvalho de Melo }
306c52b12edSArnaldo Carvalho de Melo 
307c52b12edSArnaldo Carvalho de Melo /**
308c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
309c52b12edSArnaldo Carvalho de Melo  *
310c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
311c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
312c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
313c52b12edSArnaldo Carvalho de Melo  */
314c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
315c52b12edSArnaldo Carvalho de Melo 						 int cpu, int thread)
316c52b12edSArnaldo Carvalho de Melo {
317c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
318c52b12edSArnaldo Carvalho de Melo }
319c52b12edSArnaldo Carvalho de Melo 
320a3f698feSArnaldo Carvalho de Melo int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
3210807d2d8SArnaldo Carvalho de Melo 			     struct perf_sample *sample);
3220c21f736SArnaldo Carvalho de Melo 
3230c21f736SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
3240c21f736SArnaldo Carvalho de Melo {
3250c21f736SArnaldo Carvalho de Melo 	return list_entry(evsel->node.next, struct perf_evsel, node);
3260c21f736SArnaldo Carvalho de Melo }
32707ac002fSArnaldo Carvalho de Melo 
328d87fcb4aSArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__prev(struct perf_evsel *evsel)
329d87fcb4aSArnaldo Carvalho de Melo {
330d87fcb4aSArnaldo Carvalho de Melo 	return list_entry(evsel->node.prev, struct perf_evsel, node);
331d87fcb4aSArnaldo Carvalho de Melo }
332d87fcb4aSArnaldo Carvalho de Melo 
333759ff497SNamhyung Kim /**
334759ff497SNamhyung Kim  * perf_evsel__is_group_leader - Return whether given evsel is a leader event
335759ff497SNamhyung Kim  *
336759ff497SNamhyung Kim  * @evsel - evsel selector to be tested
337759ff497SNamhyung Kim  *
338759ff497SNamhyung Kim  * Return %true if @evsel is a group leader or a stand-alone event
339759ff497SNamhyung Kim  */
340823254edSNamhyung Kim static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
34107ac002fSArnaldo Carvalho de Melo {
342823254edSNamhyung Kim 	return evsel->leader == evsel;
34307ac002fSArnaldo Carvalho de Melo }
3440698aeddSArnaldo Carvalho de Melo 
345759ff497SNamhyung Kim /**
346759ff497SNamhyung Kim  * perf_evsel__is_group_event - Return whether given evsel is a group event
347759ff497SNamhyung Kim  *
348759ff497SNamhyung Kim  * @evsel - evsel selector to be tested
349759ff497SNamhyung Kim  *
350759ff497SNamhyung Kim  * Return %true iff event group view is enabled and @evsel is a actual group
351759ff497SNamhyung Kim  * leader which has other members in the group
352759ff497SNamhyung Kim  */
353759ff497SNamhyung Kim static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
354759ff497SNamhyung Kim {
355759ff497SNamhyung Kim 	if (!symbol_conf.event_group)
356759ff497SNamhyung Kim 		return false;
357759ff497SNamhyung Kim 
358759ff497SNamhyung Kim 	return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
359759ff497SNamhyung Kim }
360759ff497SNamhyung Kim 
3615496bc0cSArnaldo Carvalho de Melo bool perf_evsel__is_function_event(struct perf_evsel *evsel);
3626bedfab6SJiri Olsa 
36303e0a7dfSWang Nan static inline bool perf_evsel__is_bpf_output(struct perf_evsel *evsel)
36403e0a7dfSWang Nan {
36503e0a7dfSWang Nan 	struct perf_event_attr *attr = &evsel->attr;
36603e0a7dfSWang Nan 
36703e0a7dfSWang Nan 	return (attr->config == PERF_COUNT_SW_BPF_OUTPUT) &&
36803e0a7dfSWang Nan 		(attr->type == PERF_TYPE_SOFTWARE);
36903e0a7dfSWang Nan }
37003e0a7dfSWang Nan 
3710698aeddSArnaldo Carvalho de Melo struct perf_attr_details {
3720698aeddSArnaldo Carvalho de Melo 	bool freq;
3730698aeddSArnaldo Carvalho de Melo 	bool verbose;
374e35ef355SArnaldo Carvalho de Melo 	bool event_group;
3759e3b6ec1SYunlong Song 	bool force;
376775d8a1bSNamhyung Kim 	bool trace_fields;
3770698aeddSArnaldo Carvalho de Melo };
3780698aeddSArnaldo Carvalho de Melo 
3790698aeddSArnaldo Carvalho de Melo int perf_evsel__fprintf(struct perf_evsel *evsel,
3800698aeddSArnaldo Carvalho de Melo 			struct perf_attr_details *details, FILE *fp);
381c0a54341SArnaldo Carvalho de Melo 
382e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_IP			(1<<0)
383e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_SYM		(1<<1)
384e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_DSO		(1<<2)
385e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_SYMOFFSET		(1<<3)
386e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_ONELINE		(1<<4)
387e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_SRCLINE		(1<<5)
388e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_UNKNOWN_AS_ADDR	(1<<6)
389e20ab86eSArnaldo Carvalho de Melo 
3906f736735SArnaldo Carvalho de Melo struct callchain_cursor;
391ea453965SArnaldo Carvalho de Melo 
392d327e60cSArnaldo Carvalho de Melo int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
393d327e60cSArnaldo Carvalho de Melo 			      unsigned int print_opts,
3946f736735SArnaldo Carvalho de Melo 			      struct callchain_cursor *cursor, FILE *fp);
3956f736735SArnaldo Carvalho de Melo 
3966f736735SArnaldo Carvalho de Melo int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,
3976f736735SArnaldo Carvalho de Melo 			int left_alignment, unsigned int print_opts,
3986f736735SArnaldo Carvalho de Melo 			struct callchain_cursor *cursor, FILE *fp);
399e20ab86eSArnaldo Carvalho de Melo 
400c0a54341SArnaldo Carvalho de Melo bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
401c0a54341SArnaldo Carvalho de Melo 			  char *msg, size_t msgsize);
402602ad878SArnaldo Carvalho de Melo int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
40356e52e85SArnaldo Carvalho de Melo 			      int err, char *msg, size_t size);
40497f63e4aSNamhyung Kim 
40597f63e4aSNamhyung Kim static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
40697f63e4aSNamhyung Kim {
40797f63e4aSNamhyung Kim 	return evsel->idx - evsel->leader->idx;
40897f63e4aSNamhyung Kim }
409717e263fSNamhyung Kim 
410717e263fSNamhyung Kim #define for_each_group_member(_evsel, _leader) 					\
411717e263fSNamhyung Kim for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); 	\
412717e263fSNamhyung Kim      (_evsel) && (_evsel)->leader == (_leader);					\
413717e263fSNamhyung Kim      (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
414717e263fSNamhyung Kim 
415acf2abbdSArnaldo Carvalho de Melo static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evsel)
416384b6055SKan Liang {
417384b6055SKan Liang 	return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
418384b6055SKan Liang }
4192c5e8c52SPeter Zijlstra 
4202c5e8c52SPeter Zijlstra typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *);
4212c5e8c52SPeter Zijlstra 
4222c5e8c52SPeter Zijlstra int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
4232c5e8c52SPeter Zijlstra 			     attr__fprintf_f attr__fprintf, void *priv);
4242c5e8c52SPeter Zijlstra 
425f4e47f9fSRavi Bangoria char *perf_evsel__env_arch(struct perf_evsel *evsel);
426f4e47f9fSRavi Bangoria 
42769aad6f1SArnaldo Carvalho de Melo #endif /* __PERF_EVSEL_H */
428