xref: /linux/tools/perf/util/evsel.h (revision 86066064e3e545338e9b48b49256d5e51213915a)
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"
1169aad6f1SArnaldo Carvalho de Melo 
12c52b12edSArnaldo Carvalho de Melo struct perf_counts_values {
13c52b12edSArnaldo Carvalho de Melo 	union {
14c52b12edSArnaldo Carvalho de Melo 		struct {
15c52b12edSArnaldo Carvalho de Melo 			u64 val;
16c52b12edSArnaldo Carvalho de Melo 			u64 ena;
17c52b12edSArnaldo Carvalho de Melo 			u64 run;
18c52b12edSArnaldo Carvalho de Melo 		};
19c52b12edSArnaldo Carvalho de Melo 		u64 values[3];
20c52b12edSArnaldo Carvalho de Melo 	};
21c52b12edSArnaldo Carvalho de Melo };
22c52b12edSArnaldo Carvalho de Melo 
23c52b12edSArnaldo Carvalho de Melo struct perf_counts {
24c52b12edSArnaldo Carvalho de Melo 	s8		   	  scaled;
25c52b12edSArnaldo Carvalho de Melo 	struct perf_counts_values aggr;
26c52b12edSArnaldo Carvalho de Melo 	struct perf_counts_values cpu[];
27c52b12edSArnaldo Carvalho de Melo };
28c52b12edSArnaldo Carvalho de Melo 
2970db7533SArnaldo Carvalho de Melo struct perf_evsel;
3070db7533SArnaldo Carvalho de Melo 
3170db7533SArnaldo Carvalho de Melo /*
3270db7533SArnaldo Carvalho de Melo  * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
3370db7533SArnaldo Carvalho de Melo  * more than one entry in the evlist.
3470db7533SArnaldo Carvalho de Melo  */
3570db7533SArnaldo Carvalho de Melo struct perf_sample_id {
3670db7533SArnaldo Carvalho de Melo 	struct hlist_node 	node;
3770db7533SArnaldo Carvalho de Melo 	u64		 	id;
3870db7533SArnaldo Carvalho de Melo 	struct perf_evsel	*evsel;
393c659eedSAdrian Hunter 	int			idx;
403c659eedSAdrian Hunter 	int			cpu;
413c659eedSAdrian Hunter 	pid_t			tid;
42e4caec0dSJiri Olsa 
43e4caec0dSJiri Olsa 	/* Holds total ID period value for PERF_SAMPLE_READ processing. */
44e4caec0dSJiri Olsa 	u64			period;
4570db7533SArnaldo Carvalho de Melo };
4670db7533SArnaldo Carvalho de Melo 
47f14d5707SArnaldo Carvalho de Melo struct cgroup_sel;
48f14d5707SArnaldo Carvalho de Melo 
49f0c55bcfSStephane Eranian /** struct perf_evsel - event selector
50f0c55bcfSStephane Eranian  *
51f0c55bcfSStephane Eranian  * @name - Can be set to retain the original event name passed by the user,
52f0c55bcfSStephane Eranian  *         so that when showing results in tools such as 'perf stat', we
53f0c55bcfSStephane Eranian  *         show the name used, not some alias.
5475562573SAdrian Hunter  * @id_pos: the position of the event id (PERF_SAMPLE_ID or
5575562573SAdrian Hunter  *          PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
5675562573SAdrian Hunter  *          struct sample_event
5775562573SAdrian Hunter  * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
5875562573SAdrian Hunter  *          PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
5975562573SAdrian Hunter  *          is used there is an id sample appended to non-sample events
600db15b1eSAdrian Hunter  * @priv:   And what is in its containing unnamed union are tool specific
61f0c55bcfSStephane Eranian  */
6269aad6f1SArnaldo Carvalho de Melo struct perf_evsel {
6369aad6f1SArnaldo Carvalho de Melo 	struct list_head	node;
6469aad6f1SArnaldo Carvalho de Melo 	struct perf_event_attr	attr;
6569aad6f1SArnaldo Carvalho de Melo 	char			*filter;
6669aad6f1SArnaldo Carvalho de Melo 	struct xyarray		*fd;
67a91e5431SArnaldo Carvalho de Melo 	struct xyarray		*sample_id;
68a91e5431SArnaldo Carvalho de Melo 	u64			*id;
69c52b12edSArnaldo Carvalho de Melo 	struct perf_counts	*counts;
70c7a79c47SStephane Eranian 	struct perf_counts	*prev_raw_counts;
7169aad6f1SArnaldo Carvalho de Melo 	int			idx;
72f4d83436SRobert Richter 	u32			ids;
73f0c55bcfSStephane Eranian 	char			*name;
74410136f5SStephane Eranian 	double			scale;
75410136f5SStephane Eranian 	const char		*unit;
76fcf65bf1SArnaldo Carvalho de Melo 	struct event_format	*tp_format;
77a91e5431SArnaldo Carvalho de Melo 	union {
7869aad6f1SArnaldo Carvalho de Melo 		void		*priv;
79a91e5431SArnaldo Carvalho de Melo 		off_t		id_offset;
800db15b1eSAdrian Hunter 		u64		db_id;
81a91e5431SArnaldo Carvalho de Melo 	};
82023695d9SStephane Eranian 	struct cgroup_sel	*cgrp;
83744a9719SArnaldo Carvalho de Melo 	void			*handler;
847ae92e74SYan, Zheng 	struct cpu_map		*cpus;
85bde09467SArnaldo Carvalho de Melo 	unsigned int		sample_size;
8675562573SAdrian Hunter 	int			id_pos;
8775562573SAdrian Hunter 	int			is_pos;
88*86066064SArnaldo Carvalho de Melo 	bool			snapshot;
892cee77c4SDavid Ahern 	bool 			supported;
900807d2d8SArnaldo Carvalho de Melo 	bool 			needs_swap;
916ff1ce76SAdrian Hunter 	bool			no_aux_samples;
922afd2bcfSAdrian Hunter 	bool			immediate;
93bf8e8f4bSAdrian Hunter 	bool			system_wide;
9460b0896cSAdrian Hunter 	bool			tracking;
95044330c1SMatt Fleming 	bool			per_pkg;
96f5b1135bSJiri Olsa 	/* parse modifier helper */
97f5b1135bSJiri Olsa 	int			exclude_GH;
9897f63e4aSNamhyung Kim 	int			nr_members;
993c176311SJiri Olsa 	int			sample_read;
100*86066064SArnaldo Carvalho de Melo 	unsigned long		*per_pkg_mask;
1016a4bb04cSJiri Olsa 	struct perf_evsel	*leader;
1026a4bb04cSJiri Olsa 	char			*group_name;
10369aad6f1SArnaldo Carvalho de Melo };
10469aad6f1SArnaldo Carvalho de Melo 
10588080ce7SBorislav Petkov union u64_swap {
10688080ce7SBorislav Petkov 	u64 val64;
10788080ce7SBorislav Petkov 	u32 val32[2];
10888080ce7SBorislav Petkov };
10988080ce7SBorislav Petkov 
11086bd5e86SArnaldo Carvalho de Melo struct cpu_map;
11180b2210cSArnaldo Carvalho de Melo struct target;
11286bd5e86SArnaldo Carvalho de Melo struct thread_map;
11370082dd9SArnaldo Carvalho de Melo struct perf_evlist;
114b4006796SArnaldo Carvalho de Melo struct record_opts;
11586bd5e86SArnaldo Carvalho de Melo 
11613112bbfSJiri Olsa void perf_counts_values__scale(struct perf_counts_values *count,
11713112bbfSJiri Olsa 			       bool scale, s8 *pscaled);
11813112bbfSJiri Olsa 
119857a94a2SJiri Olsa void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
120857a94a2SJiri Olsa 				struct perf_counts_values *count);
121857a94a2SJiri Olsa 
122ce8ccff5SArnaldo Carvalho de Melo int perf_evsel__object_config(size_t object_size,
123ce8ccff5SArnaldo Carvalho de Melo 			      int (*init)(struct perf_evsel *evsel),
124ce8ccff5SArnaldo Carvalho de Melo 			      void (*fini)(struct perf_evsel *evsel));
125ce8ccff5SArnaldo Carvalho de Melo 
126ef503831SArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
127ef503831SArnaldo Carvalho de Melo 
128ef503831SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
129ef503831SArnaldo Carvalho de Melo {
130ef503831SArnaldo Carvalho de Melo 	return perf_evsel__new_idx(attr, 0);
131ef503831SArnaldo Carvalho de Melo }
132ef503831SArnaldo Carvalho de Melo 
133ef503831SArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
134ef503831SArnaldo Carvalho de Melo 
135ef503831SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
136ef503831SArnaldo Carvalho de Melo {
137ef503831SArnaldo Carvalho de Melo 	return perf_evsel__newtp_idx(sys, name, 0);
138ef503831SArnaldo Carvalho de Melo }
139201b7334SArnaldo Carvalho de Melo 
140201b7334SArnaldo Carvalho de Melo struct event_format *event_format__new(const char *sys, const char *name);
141201b7334SArnaldo Carvalho de Melo 
142ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__init(struct perf_evsel *evsel,
143ef1d1af2SArnaldo Carvalho de Melo 		      struct perf_event_attr *attr, int idx);
144ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__exit(struct perf_evsel *evsel);
14569aad6f1SArnaldo Carvalho de Melo void perf_evsel__delete(struct perf_evsel *evsel);
14669aad6f1SArnaldo Carvalho de Melo 
1470f82ebc4SArnaldo Carvalho de Melo void perf_evsel__config(struct perf_evsel *evsel,
148b4006796SArnaldo Carvalho de Melo 			struct record_opts *opts);
1490f82ebc4SArnaldo Carvalho de Melo 
15075562573SAdrian Hunter int __perf_evsel__sample_size(u64 sample_type);
15175562573SAdrian Hunter void perf_evsel__calc_id_pos(struct perf_evsel *evsel);
15275562573SAdrian Hunter 
1530b668bc9SArnaldo Carvalho de Melo bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
1540b668bc9SArnaldo Carvalho de Melo 
1550b668bc9SArnaldo Carvalho de Melo #define PERF_EVSEL__MAX_ALIASES 8
1560b668bc9SArnaldo Carvalho de Melo 
1570b668bc9SArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
1580b668bc9SArnaldo Carvalho de Melo 				       [PERF_EVSEL__MAX_ALIASES];
1590b668bc9SArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
1600b668bc9SArnaldo Carvalho de Melo 					  [PERF_EVSEL__MAX_ALIASES];
1618ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
1620b668bc9SArnaldo Carvalho de Melo 					      [PERF_EVSEL__MAX_ALIASES];
1638ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
1648ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
1650b668bc9SArnaldo Carvalho de Melo int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
1660b668bc9SArnaldo Carvalho de Melo 					    char *bf, size_t size);
1677289f83cSArnaldo Carvalho de Melo const char *perf_evsel__name(struct perf_evsel *evsel);
168410136f5SStephane Eranian 
169717e263fSNamhyung Kim const char *perf_evsel__group_name(struct perf_evsel *evsel);
170717e263fSNamhyung Kim int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
171c410431cSArnaldo Carvalho de Melo 
17270db7533SArnaldo Carvalho de Melo int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
173c52b12edSArnaldo Carvalho de Melo int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
174a7e191c3SFrederik Deweerdt void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
17543f8e76eSNamhyung Kim void perf_evsel__free_counts(struct perf_evsel *evsel);
176c52b12edSArnaldo Carvalho de Melo void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
17769aad6f1SArnaldo Carvalho de Melo 
1787be5ebe8SArnaldo Carvalho de Melo void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
1797be5ebe8SArnaldo Carvalho de Melo 				  enum perf_event_sample_format bit);
1807be5ebe8SArnaldo Carvalho de Melo void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
1817be5ebe8SArnaldo Carvalho de Melo 				    enum perf_event_sample_format bit);
1827be5ebe8SArnaldo Carvalho de Melo 
1837be5ebe8SArnaldo Carvalho de Melo #define perf_evsel__set_sample_bit(evsel, bit) \
1847be5ebe8SArnaldo Carvalho de Melo 	__perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
1857be5ebe8SArnaldo Carvalho de Melo 
1867be5ebe8SArnaldo Carvalho de Melo #define perf_evsel__reset_sample_bit(evsel, bit) \
1877be5ebe8SArnaldo Carvalho de Melo 	__perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
1887be5ebe8SArnaldo Carvalho de Melo 
18975562573SAdrian Hunter void perf_evsel__set_sample_id(struct perf_evsel *evsel,
19075562573SAdrian Hunter 			       bool use_sample_identifier);
1917a5a5ca5SArnaldo Carvalho de Melo 
192745cefc5SArnaldo Carvalho de Melo int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads,
193745cefc5SArnaldo Carvalho de Melo 			   const char *filter);
194e2407befSAndi Kleen int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads);
195745cefc5SArnaldo Carvalho de Melo 
196f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
1976a4bb04cSJiri Olsa 			     struct cpu_map *cpus);
198f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_thread(struct perf_evsel *evsel,
1996a4bb04cSJiri Olsa 				struct thread_map *threads);
200f08199d3SArnaldo Carvalho de Melo int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
2016a4bb04cSJiri Olsa 		     struct thread_map *threads);
202727ab04eSArnaldo Carvalho de Melo void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
20348290609SArnaldo Carvalho de Melo 
2045555ded4SArnaldo Carvalho de Melo struct perf_sample;
2055555ded4SArnaldo Carvalho de Melo 
2065d2074eaSArnaldo Carvalho de Melo void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
2075555ded4SArnaldo Carvalho de Melo 			 const char *name);
2085555ded4SArnaldo Carvalho de Melo u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
2095555ded4SArnaldo Carvalho de Melo 		       const char *name);
2105555ded4SArnaldo Carvalho de Melo 
2115d2074eaSArnaldo Carvalho de Melo static inline char *perf_evsel__strval(struct perf_evsel *evsel,
2125d2074eaSArnaldo Carvalho de Melo 				       struct perf_sample *sample,
2135d2074eaSArnaldo Carvalho de Melo 				       const char *name)
2145d2074eaSArnaldo Carvalho de Melo {
2155d2074eaSArnaldo Carvalho de Melo 	return perf_evsel__rawptr(evsel, sample, name);
2165d2074eaSArnaldo Carvalho de Melo }
2175d2074eaSArnaldo Carvalho de Melo 
218efd2b924SArnaldo Carvalho de Melo struct format_field;
219efd2b924SArnaldo Carvalho de Melo 
220efd2b924SArnaldo Carvalho de Melo struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
221efd2b924SArnaldo Carvalho de Melo 
222daec78a0SArnaldo Carvalho de Melo #define perf_evsel__match(evsel, t, c)		\
223daec78a0SArnaldo Carvalho de Melo 	(evsel->attr.type == PERF_TYPE_##t &&	\
224daec78a0SArnaldo Carvalho de Melo 	 evsel->attr.config == PERF_COUNT_##c)
225daec78a0SArnaldo Carvalho de Melo 
226863e451fSJiri Olsa static inline bool perf_evsel__match2(struct perf_evsel *e1,
227863e451fSJiri Olsa 				      struct perf_evsel *e2)
228863e451fSJiri Olsa {
229863e451fSJiri Olsa 	return (e1->attr.type == e2->attr.type) &&
230863e451fSJiri Olsa 	       (e1->attr.config == e2->attr.config);
231863e451fSJiri Olsa }
232863e451fSJiri Olsa 
2334cabc3d1SAndi Kleen #define perf_evsel__cmp(a, b)			\
2344cabc3d1SAndi Kleen 	((a) &&					\
2354cabc3d1SAndi Kleen 	 (b) &&					\
2364cabc3d1SAndi Kleen 	 (a)->attr.type == (b)->attr.type &&	\
2374cabc3d1SAndi Kleen 	 (a)->attr.config == (b)->attr.config)
2384cabc3d1SAndi Kleen 
239011dccbdSJiri Olsa typedef int (perf_evsel__read_cb_t)(struct perf_evsel *evsel,
240011dccbdSJiri Olsa 				    int cpu, int thread,
241011dccbdSJiri Olsa 				    struct perf_counts_values *count);
242011dccbdSJiri Olsa 
243011dccbdSJiri Olsa int perf_evsel__read_cb(struct perf_evsel *evsel, int cpu, int thread,
244011dccbdSJiri Olsa 			perf_evsel__read_cb_t cb);
245011dccbdSJiri Olsa 
246c52b12edSArnaldo Carvalho de Melo int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
247c52b12edSArnaldo Carvalho de Melo 			      int cpu, int thread, bool scale);
248c52b12edSArnaldo Carvalho de Melo 
249c52b12edSArnaldo Carvalho de Melo /**
250c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
251c52b12edSArnaldo Carvalho de Melo  *
252c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
253c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
254c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
255c52b12edSArnaldo Carvalho de Melo  */
256c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
257c52b12edSArnaldo Carvalho de Melo 					  int cpu, int thread)
258c52b12edSArnaldo Carvalho de Melo {
259c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
260c52b12edSArnaldo Carvalho de Melo }
261c52b12edSArnaldo Carvalho de Melo 
262c52b12edSArnaldo Carvalho de Melo /**
263c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
264c52b12edSArnaldo Carvalho de Melo  *
265c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
266c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
267c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
268c52b12edSArnaldo Carvalho de Melo  */
269c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
270c52b12edSArnaldo Carvalho de Melo 						 int cpu, int thread)
271c52b12edSArnaldo Carvalho de Melo {
272c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
273c52b12edSArnaldo Carvalho de Melo }
274c52b12edSArnaldo Carvalho de Melo 
275a3f698feSArnaldo Carvalho de Melo int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
2760807d2d8SArnaldo Carvalho de Melo 			     struct perf_sample *sample);
2770c21f736SArnaldo Carvalho de Melo 
2780c21f736SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
2790c21f736SArnaldo Carvalho de Melo {
2800c21f736SArnaldo Carvalho de Melo 	return list_entry(evsel->node.next, struct perf_evsel, node);
2810c21f736SArnaldo Carvalho de Melo }
28207ac002fSArnaldo Carvalho de Melo 
283d87fcb4aSArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__prev(struct perf_evsel *evsel)
284d87fcb4aSArnaldo Carvalho de Melo {
285d87fcb4aSArnaldo Carvalho de Melo 	return list_entry(evsel->node.prev, struct perf_evsel, node);
286d87fcb4aSArnaldo Carvalho de Melo }
287d87fcb4aSArnaldo Carvalho de Melo 
288759ff497SNamhyung Kim /**
289759ff497SNamhyung Kim  * perf_evsel__is_group_leader - Return whether given evsel is a leader event
290759ff497SNamhyung Kim  *
291759ff497SNamhyung Kim  * @evsel - evsel selector to be tested
292759ff497SNamhyung Kim  *
293759ff497SNamhyung Kim  * Return %true if @evsel is a group leader or a stand-alone event
294759ff497SNamhyung Kim  */
295823254edSNamhyung Kim static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
29607ac002fSArnaldo Carvalho de Melo {
297823254edSNamhyung Kim 	return evsel->leader == evsel;
29807ac002fSArnaldo Carvalho de Melo }
2990698aeddSArnaldo Carvalho de Melo 
300759ff497SNamhyung Kim /**
301759ff497SNamhyung Kim  * perf_evsel__is_group_event - Return whether given evsel is a group event
302759ff497SNamhyung Kim  *
303759ff497SNamhyung Kim  * @evsel - evsel selector to be tested
304759ff497SNamhyung Kim  *
305759ff497SNamhyung Kim  * Return %true iff event group view is enabled and @evsel is a actual group
306759ff497SNamhyung Kim  * leader which has other members in the group
307759ff497SNamhyung Kim  */
308759ff497SNamhyung Kim static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
309759ff497SNamhyung Kim {
310759ff497SNamhyung Kim 	if (!symbol_conf.event_group)
311759ff497SNamhyung Kim 		return false;
312759ff497SNamhyung Kim 
313759ff497SNamhyung Kim 	return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
314759ff497SNamhyung Kim }
315759ff497SNamhyung Kim 
3166bedfab6SJiri Olsa /**
3176bedfab6SJiri Olsa  * perf_evsel__is_function_event - Return whether given evsel is a function
3186bedfab6SJiri Olsa  * trace event
3196bedfab6SJiri Olsa  *
3206bedfab6SJiri Olsa  * @evsel - evsel selector to be tested
3216bedfab6SJiri Olsa  *
3226bedfab6SJiri Olsa  * Return %true if event is function trace event
3236bedfab6SJiri Olsa  */
3246bedfab6SJiri Olsa static inline bool perf_evsel__is_function_event(struct perf_evsel *evsel)
3256bedfab6SJiri Olsa {
3266bedfab6SJiri Olsa #define FUNCTION_EVENT "ftrace:function"
3276bedfab6SJiri Olsa 
3286bedfab6SJiri Olsa 	return evsel->name &&
3296bedfab6SJiri Olsa 	       !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
3306bedfab6SJiri Olsa 
3316bedfab6SJiri Olsa #undef FUNCTION_EVENT
3326bedfab6SJiri Olsa }
3336bedfab6SJiri Olsa 
3340698aeddSArnaldo Carvalho de Melo struct perf_attr_details {
3350698aeddSArnaldo Carvalho de Melo 	bool freq;
3360698aeddSArnaldo Carvalho de Melo 	bool verbose;
337e35ef355SArnaldo Carvalho de Melo 	bool event_group;
3389e3b6ec1SYunlong Song 	bool force;
3390698aeddSArnaldo Carvalho de Melo };
3400698aeddSArnaldo Carvalho de Melo 
3410698aeddSArnaldo Carvalho de Melo int perf_evsel__fprintf(struct perf_evsel *evsel,
3420698aeddSArnaldo Carvalho de Melo 			struct perf_attr_details *details, FILE *fp);
343c0a54341SArnaldo Carvalho de Melo 
344c0a54341SArnaldo Carvalho de Melo bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
345c0a54341SArnaldo Carvalho de Melo 			  char *msg, size_t msgsize);
346602ad878SArnaldo Carvalho de Melo int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
34756e52e85SArnaldo Carvalho de Melo 			      int err, char *msg, size_t size);
34897f63e4aSNamhyung Kim 
34997f63e4aSNamhyung Kim static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
35097f63e4aSNamhyung Kim {
35197f63e4aSNamhyung Kim 	return evsel->idx - evsel->leader->idx;
35297f63e4aSNamhyung Kim }
353717e263fSNamhyung Kim 
354717e263fSNamhyung Kim #define for_each_group_member(_evsel, _leader) 					\
355717e263fSNamhyung Kim for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); 	\
356717e263fSNamhyung Kim      (_evsel) && (_evsel)->leader == (_leader);					\
357717e263fSNamhyung Kim      (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
358717e263fSNamhyung Kim 
359384b6055SKan Liang static inline bool has_branch_callstack(struct perf_evsel *evsel)
360384b6055SKan Liang {
361384b6055SKan Liang 	return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
362384b6055SKan Liang }
3632c5e8c52SPeter Zijlstra 
3642c5e8c52SPeter Zijlstra typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *);
3652c5e8c52SPeter Zijlstra 
3662c5e8c52SPeter Zijlstra int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
3672c5e8c52SPeter Zijlstra 			     attr__fprintf_f attr__fprintf, void *priv);
3682c5e8c52SPeter Zijlstra 
36969aad6f1SArnaldo Carvalho de Melo #endif /* __PERF_EVSEL_H */
370