xref: /linux/tools/perf/util/evsel.h (revision a9c5e6c1e9bff42ca5f01ceb3092a27a010755fb)
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>
707ac002fSArnaldo Carvalho de Melo #include <stddef.h>
8d2709c7cSDavid Howells #include <linux/perf_event.h>
9d944c4eeSBorislav Petkov #include <linux/types.h>
1069aad6f1SArnaldo Carvalho de Melo #include "xyarray.h"
11759ff497SNamhyung Kim #include "symbol.h"
12a22e99cdSJiri Olsa #include "cpumap.h"
13d809560bSJiri Olsa #include "counts.h"
14c52b12edSArnaldo Carvalho de Melo 
1570db7533SArnaldo Carvalho de Melo struct perf_evsel;
1670db7533SArnaldo Carvalho de Melo 
1770db7533SArnaldo Carvalho de Melo /*
1870db7533SArnaldo Carvalho de Melo  * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
1970db7533SArnaldo Carvalho de Melo  * more than one entry in the evlist.
2070db7533SArnaldo Carvalho de Melo  */
2170db7533SArnaldo Carvalho de Melo struct perf_sample_id {
2270db7533SArnaldo Carvalho de Melo 	struct hlist_node 	node;
2370db7533SArnaldo Carvalho de Melo 	u64		 	id;
2470db7533SArnaldo Carvalho de Melo 	struct perf_evsel	*evsel;
253c659eedSAdrian Hunter 	int			idx;
263c659eedSAdrian Hunter 	int			cpu;
273c659eedSAdrian Hunter 	pid_t			tid;
28e4caec0dSJiri Olsa 
29e4caec0dSJiri Olsa 	/* Holds total ID period value for PERF_SAMPLE_READ processing. */
30e4caec0dSJiri Olsa 	u64			period;
3170db7533SArnaldo Carvalho de Melo };
3270db7533SArnaldo Carvalho de Melo 
333ca32f69SArnaldo Carvalho de Melo struct cgroup;
34f14d5707SArnaldo Carvalho de Melo 
35930a2e29SJiri Olsa /*
36930a2e29SJiri Olsa  * The 'struct perf_evsel_config_term' is used to pass event
37930a2e29SJiri Olsa  * specific configuration data to perf_evsel__config routine.
38930a2e29SJiri Olsa  * It is allocated within event parsing and attached to
39930a2e29SJiri Olsa  * perf_evsel::config_terms list head.
40930a2e29SJiri Olsa */
41d0565132SAndi Kleen enum term_type {
42ee4c7588SJiri Olsa 	PERF_EVSEL__CONFIG_TERM_PERIOD,
4309af2a55SNamhyung Kim 	PERF_EVSEL__CONFIG_TERM_FREQ,
4432067712SKan Liang 	PERF_EVSEL__CONFIG_TERM_TIME,
45d457c963SKan Liang 	PERF_EVSEL__CONFIG_TERM_CALLGRAPH,
46d457c963SKan Liang 	PERF_EVSEL__CONFIG_TERM_STACK_USER,
47374ce938SWang Nan 	PERF_EVSEL__CONFIG_TERM_INHERIT,
48792d48b4SArnaldo Carvalho de Melo 	PERF_EVSEL__CONFIG_TERM_MAX_STACK,
492fda5adaSArnaldo Carvalho de Melo 	PERF_EVSEL__CONFIG_TERM_MAX_EVENTS,
50626a6b78SWang Nan 	PERF_EVSEL__CONFIG_TERM_OVERWRITE,
51dd60fba7SMathieu Poirier 	PERF_EVSEL__CONFIG_TERM_DRV_CFG,
52ac12f676SAndi Kleen 	PERF_EVSEL__CONFIG_TERM_BRANCH,
53930a2e29SJiri Olsa };
54930a2e29SJiri Olsa 
55930a2e29SJiri Olsa struct perf_evsel_config_term {
56930a2e29SJiri Olsa 	struct list_head	list;
57d0565132SAndi Kleen 	enum term_type	type;
58930a2e29SJiri Olsa 	union {
59930a2e29SJiri Olsa 		u64	period;
6009af2a55SNamhyung Kim 		u64	freq;
6132067712SKan Liang 		bool	time;
62d457c963SKan Liang 		char	*callgraph;
63dd60fba7SMathieu Poirier 		char	*drv_cfg;
64d457c963SKan Liang 		u64	stack_user;
65792d48b4SArnaldo Carvalho de Melo 		int	max_stack;
66374ce938SWang Nan 		bool	inherit;
67626a6b78SWang Nan 		bool	overwrite;
68ac12f676SAndi Kleen 		char	*branch;
692fda5adaSArnaldo Carvalho de Melo 		unsigned long max_events;
70930a2e29SJiri Olsa 	} val;
71c2f1ceadSAndi Kleen 	bool weak;
72930a2e29SJiri Olsa };
73930a2e29SJiri Olsa 
74e669e833SArnaldo Carvalho de Melo struct perf_stat_evsel;
75e669e833SArnaldo Carvalho de Melo 
76f0c55bcfSStephane Eranian /** struct perf_evsel - event selector
77f0c55bcfSStephane Eranian  *
78d49e4695SArnaldo Carvalho de Melo  * @evlist - evlist this evsel is in, if it is in one.
79d49e4695SArnaldo Carvalho de Melo  * @node - To insert it into evlist->entries or in other list_heads, say in
80d49e4695SArnaldo Carvalho de Melo  *         the event parsing routines.
81f0c55bcfSStephane Eranian  * @name - Can be set to retain the original event name passed by the user,
82f0c55bcfSStephane Eranian  *         so that when showing results in tools such as 'perf stat', we
83f0c55bcfSStephane Eranian  *         show the name used, not some alias.
8475562573SAdrian Hunter  * @id_pos: the position of the event id (PERF_SAMPLE_ID or
8575562573SAdrian Hunter  *          PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
8675562573SAdrian Hunter  *          struct sample_event
8775562573SAdrian Hunter  * @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
8875562573SAdrian Hunter  *          PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
8975562573SAdrian Hunter  *          is used there is an id sample appended to non-sample events
900db15b1eSAdrian Hunter  * @priv:   And what is in its containing unnamed union are tool specific
91f0c55bcfSStephane Eranian  */
9269aad6f1SArnaldo Carvalho de Melo struct perf_evsel {
9369aad6f1SArnaldo Carvalho de Melo 	struct list_head	node;
94d49e4695SArnaldo Carvalho de Melo 	struct perf_evlist	*evlist;
9569aad6f1SArnaldo Carvalho de Melo 	struct perf_event_attr	attr;
9669aad6f1SArnaldo Carvalho de Melo 	char			*filter;
9769aad6f1SArnaldo Carvalho de Melo 	struct xyarray		*fd;
98a91e5431SArnaldo Carvalho de Melo 	struct xyarray		*sample_id;
99a91e5431SArnaldo Carvalho de Melo 	u64			*id;
100c52b12edSArnaldo Carvalho de Melo 	struct perf_counts	*counts;
101c7a79c47SStephane Eranian 	struct perf_counts	*prev_raw_counts;
10269aad6f1SArnaldo Carvalho de Melo 	int			idx;
103f4d83436SRobert Richter 	u32			ids;
1042fda5adaSArnaldo Carvalho de Melo 	unsigned long		max_events;
105*a9c5e6c1SArnaldo Carvalho de Melo 	unsigned long		nr_events_printed;
106f0c55bcfSStephane Eranian 	char			*name;
107410136f5SStephane Eranian 	double			scale;
108410136f5SStephane Eranian 	const char		*unit;
1094963b0f8STzvetomir Stoyanov (VMware) 	struct tep_event_format	*tp_format;
110af339981SJiri Olsa 	off_t			id_offset;
111e669e833SArnaldo Carvalho de Melo 	struct perf_stat_evsel  *stats;
11269aad6f1SArnaldo Carvalho de Melo 	void			*priv;
1130db15b1eSAdrian Hunter 	u64			db_id;
1143ca32f69SArnaldo Carvalho de Melo 	struct cgroup		*cgrp;
115744a9719SArnaldo Carvalho de Melo 	void			*handler;
1167ae92e74SYan, Zheng 	struct cpu_map		*cpus;
117fce4d296SAdrian Hunter 	struct cpu_map		*own_cpus;
118578e91ecSJiri Olsa 	struct thread_map	*threads;
119bde09467SArnaldo Carvalho de Melo 	unsigned int		sample_size;
12075562573SAdrian Hunter 	int			id_pos;
12175562573SAdrian Hunter 	int			is_pos;
12280ee8c58SKan Liang 	bool			uniquified_name;
12386066064SArnaldo Carvalho de Melo 	bool			snapshot;
1242cee77c4SDavid Ahern 	bool 			supported;
1250807d2d8SArnaldo Carvalho de Melo 	bool 			needs_swap;
126b7e8452bSArnaldo Carvalho de Melo 	bool 			disabled;
1276ff1ce76SAdrian Hunter 	bool			no_aux_samples;
1282afd2bcfSAdrian Hunter 	bool			immediate;
129bf8e8f4bSAdrian Hunter 	bool			system_wide;
13060b0896cSAdrian Hunter 	bool			tracking;
131044330c1SMatt Fleming 	bool			per_pkg;
1327f94af7aSJiri Olsa 	bool			precise_max;
133a359c17aSJiri Olsa 	bool			ignore_missing_thread;
1348ef278bbSJiri Olsa 	bool			forced_leader;
1353cdc5c2cSKan Liang 	bool			use_uncore_alias;
136f5b1135bSJiri Olsa 	/* parse modifier helper */
137f5b1135bSJiri Olsa 	int			exclude_GH;
13897f63e4aSNamhyung Kim 	int			nr_members;
1393c176311SJiri Olsa 	int			sample_read;
14086066064SArnaldo Carvalho de Melo 	unsigned long		*per_pkg_mask;
1416a4bb04cSJiri Olsa 	struct perf_evsel	*leader;
1426a4bb04cSJiri Olsa 	char			*group_name;
14315bfd2ccSWang Nan 	bool			cmdline_group_boundary;
144930a2e29SJiri Olsa 	struct list_head	config_terms;
1451f45b1d4SWang Nan 	int			bpf_fd;
14663ce8449SArnaldo Carvalho de Melo 	bool			auto_merge_stats;
147430daf2dSAndi Kleen 	bool			merged_stat;
14837932c18SAndi Kleen 	const char *		metric_expr;
14996284814SAndi Kleen 	const char *		metric_name;
15037932c18SAndi Kleen 	struct perf_evsel	**metric_events;
15137932c18SAndi Kleen 	bool			collect_stat;
1525a5dfe4bSAndi Kleen 	bool			weak_group;
1538c5421c0SAgustin Vega-Frias 	const char		*pmu_name;
15469aad6f1SArnaldo Carvalho de Melo };
15569aad6f1SArnaldo Carvalho de Melo 
15688080ce7SBorislav Petkov union u64_swap {
15788080ce7SBorislav Petkov 	u64 val64;
15888080ce7SBorislav Petkov 	u32 val32[2];
15988080ce7SBorislav Petkov };
16088080ce7SBorislav Petkov 
1619a831b3aSArnaldo Carvalho de Melo struct perf_missing_features {
1629a831b3aSArnaldo Carvalho de Melo 	bool sample_id_all;
1639a831b3aSArnaldo Carvalho de Melo 	bool exclude_guest;
1649a831b3aSArnaldo Carvalho de Melo 	bool mmap2;
1659a831b3aSArnaldo Carvalho de Melo 	bool cloexec;
1669a831b3aSArnaldo Carvalho de Melo 	bool clockid;
1679a831b3aSArnaldo Carvalho de Melo 	bool clockid_wrong;
1689a831b3aSArnaldo Carvalho de Melo 	bool lbr_flags;
1699a831b3aSArnaldo Carvalho de Melo 	bool write_backward;
1709a831b3aSArnaldo Carvalho de Melo 	bool group_read;
1719a831b3aSArnaldo Carvalho de Melo };
1729a831b3aSArnaldo Carvalho de Melo 
1739a831b3aSArnaldo Carvalho de Melo extern struct perf_missing_features perf_missing_features;
1749a831b3aSArnaldo Carvalho de Melo 
17586bd5e86SArnaldo Carvalho de Melo struct cpu_map;
17680b2210cSArnaldo Carvalho de Melo struct target;
17786bd5e86SArnaldo Carvalho de Melo struct thread_map;
178b4006796SArnaldo Carvalho de Melo struct record_opts;
17986bd5e86SArnaldo Carvalho de Melo 
180a22e99cdSJiri Olsa static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)
181a22e99cdSJiri Olsa {
182a22e99cdSJiri Olsa 	return evsel->cpus;
183a22e99cdSJiri Olsa }
184a22e99cdSJiri Olsa 
185a22e99cdSJiri Olsa static inline int perf_evsel__nr_cpus(struct perf_evsel *evsel)
186a22e99cdSJiri Olsa {
187a22e99cdSJiri Olsa 	return perf_evsel__cpus(evsel)->nr;
188a22e99cdSJiri Olsa }
189a22e99cdSJiri Olsa 
19013112bbfSJiri Olsa void perf_counts_values__scale(struct perf_counts_values *count,
19113112bbfSJiri Olsa 			       bool scale, s8 *pscaled);
19213112bbfSJiri Olsa 
193a6fa0038SJiri Olsa void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, int thread,
194857a94a2SJiri Olsa 				struct perf_counts_values *count);
195857a94a2SJiri Olsa 
196ce8ccff5SArnaldo Carvalho de Melo int perf_evsel__object_config(size_t object_size,
197ce8ccff5SArnaldo Carvalho de Melo 			      int (*init)(struct perf_evsel *evsel),
198ce8ccff5SArnaldo Carvalho de Melo 			      void (*fini)(struct perf_evsel *evsel));
199ce8ccff5SArnaldo Carvalho de Melo 
200ef503831SArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
201ef503831SArnaldo Carvalho de Melo 
202ef503831SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
203ef503831SArnaldo Carvalho de Melo {
204ef503831SArnaldo Carvalho de Melo 	return perf_evsel__new_idx(attr, 0);
205ef503831SArnaldo Carvalho de Melo }
206ef503831SArnaldo Carvalho de Melo 
207ef503831SArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
208ef503831SArnaldo Carvalho de Melo 
2098dd2a131SJiri Olsa /*
2108dd2a131SJiri Olsa  * Returns pointer with encoded error via <linux/err.h> interface.
2118dd2a131SJiri Olsa  */
212ef503831SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
213ef503831SArnaldo Carvalho de Melo {
214ef503831SArnaldo Carvalho de Melo 	return perf_evsel__newtp_idx(sys, name, 0);
215ef503831SArnaldo Carvalho de Melo }
216201b7334SArnaldo Carvalho de Melo 
21730269dc1SArnaldo Carvalho de Melo struct perf_evsel *perf_evsel__new_cycles(bool precise);
2187c48dcfdSArnaldo Carvalho de Melo 
2194963b0f8STzvetomir Stoyanov (VMware) struct tep_event_format *event_format__new(const char *sys, const char *name);
220201b7334SArnaldo Carvalho de Melo 
221ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__init(struct perf_evsel *evsel,
222ef1d1af2SArnaldo Carvalho de Melo 		      struct perf_event_attr *attr, int idx);
223ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__exit(struct perf_evsel *evsel);
22469aad6f1SArnaldo Carvalho de Melo void perf_evsel__delete(struct perf_evsel *evsel);
22569aad6f1SArnaldo Carvalho de Melo 
226e68ae9cfSArnaldo Carvalho de Melo struct callchain_param;
227e68ae9cfSArnaldo Carvalho de Melo 
2280f82ebc4SArnaldo Carvalho de Melo void perf_evsel__config(struct perf_evsel *evsel,
229e68ae9cfSArnaldo Carvalho de Melo 			struct record_opts *opts,
230e68ae9cfSArnaldo Carvalho de Melo 			struct callchain_param *callchain);
23101e0d50cSArnaldo Carvalho de Melo void perf_evsel__config_callchain(struct perf_evsel *evsel,
23201e0d50cSArnaldo Carvalho de Melo 				  struct record_opts *opts,
23301e0d50cSArnaldo Carvalho de Melo 				  struct callchain_param *callchain);
2340f82ebc4SArnaldo Carvalho de Melo 
23575562573SAdrian Hunter int __perf_evsel__sample_size(u64 sample_type);
23675562573SAdrian Hunter void perf_evsel__calc_id_pos(struct perf_evsel *evsel);
23775562573SAdrian Hunter 
2380b668bc9SArnaldo Carvalho de Melo bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
2390b668bc9SArnaldo Carvalho de Melo 
2400b668bc9SArnaldo Carvalho de Melo #define PERF_EVSEL__MAX_ALIASES 8
2410b668bc9SArnaldo Carvalho de Melo 
2420b668bc9SArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
2430b668bc9SArnaldo Carvalho de Melo 				       [PERF_EVSEL__MAX_ALIASES];
2440b668bc9SArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
2450b668bc9SArnaldo Carvalho de Melo 					  [PERF_EVSEL__MAX_ALIASES];
2468ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
2470b668bc9SArnaldo Carvalho de Melo 					      [PERF_EVSEL__MAX_ALIASES];
2488ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
2498ad7013bSArnaldo Carvalho de Melo extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
2500b668bc9SArnaldo Carvalho de Melo int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
2510b668bc9SArnaldo Carvalho de Melo 					    char *bf, size_t size);
2527289f83cSArnaldo Carvalho de Melo const char *perf_evsel__name(struct perf_evsel *evsel);
253410136f5SStephane Eranian 
254717e263fSNamhyung Kim const char *perf_evsel__group_name(struct perf_evsel *evsel);
255717e263fSNamhyung Kim int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size);
256c410431cSArnaldo Carvalho de Melo 
25770db7533SArnaldo Carvalho de Melo int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
258475fb533SAndi Kleen void perf_evsel__close_fd(struct perf_evsel *evsel);
25969aad6f1SArnaldo Carvalho de Melo 
2607be5ebe8SArnaldo Carvalho de Melo void __perf_evsel__set_sample_bit(struct perf_evsel *evsel,
2617be5ebe8SArnaldo Carvalho de Melo 				  enum perf_event_sample_format bit);
2627be5ebe8SArnaldo Carvalho de Melo void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel,
2637be5ebe8SArnaldo Carvalho de Melo 				    enum perf_event_sample_format bit);
2647be5ebe8SArnaldo Carvalho de Melo 
2657be5ebe8SArnaldo Carvalho de Melo #define perf_evsel__set_sample_bit(evsel, bit) \
2667be5ebe8SArnaldo Carvalho de Melo 	__perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
2677be5ebe8SArnaldo Carvalho de Melo 
2687be5ebe8SArnaldo Carvalho de Melo #define perf_evsel__reset_sample_bit(evsel, bit) \
2697be5ebe8SArnaldo Carvalho de Melo 	__perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
2707be5ebe8SArnaldo Carvalho de Melo 
27175562573SAdrian Hunter void perf_evsel__set_sample_id(struct perf_evsel *evsel,
27275562573SAdrian Hunter 			       bool use_sample_identifier);
2737a5a5ca5SArnaldo Carvalho de Melo 
27412467ae4SArnaldo Carvalho de Melo int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter);
2753541c034SMathieu Poirier int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter);
2761e857484SMathieu Poirier int perf_evsel__append_addr_filter(struct perf_evsel *evsel,
2771e857484SMathieu Poirier 				   const char *filter);
278475fb533SAndi Kleen int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
2795cd95fc3SJiri Olsa int perf_evsel__enable(struct perf_evsel *evsel);
280e98a4cbbSJiri Olsa int perf_evsel__disable(struct perf_evsel *evsel);
281745cefc5SArnaldo Carvalho de Melo 
282f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
2836a4bb04cSJiri Olsa 			     struct cpu_map *cpus);
284f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_thread(struct perf_evsel *evsel,
2856a4bb04cSJiri Olsa 				struct thread_map *threads);
286f08199d3SArnaldo Carvalho de Melo int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
2876a4bb04cSJiri Olsa 		     struct thread_map *threads);
288475fb533SAndi Kleen void perf_evsel__close(struct perf_evsel *evsel);
28948290609SArnaldo Carvalho de Melo 
2905555ded4SArnaldo Carvalho de Melo struct perf_sample;
2915555ded4SArnaldo Carvalho de Melo 
2925d2074eaSArnaldo Carvalho de Melo void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
2935555ded4SArnaldo Carvalho de Melo 			 const char *name);
2945555ded4SArnaldo Carvalho de Melo u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
2955555ded4SArnaldo Carvalho de Melo 		       const char *name);
2965555ded4SArnaldo Carvalho de Melo 
2975d2074eaSArnaldo Carvalho de Melo static inline char *perf_evsel__strval(struct perf_evsel *evsel,
2985d2074eaSArnaldo Carvalho de Melo 				       struct perf_sample *sample,
2995d2074eaSArnaldo Carvalho de Melo 				       const char *name)
3005d2074eaSArnaldo Carvalho de Melo {
3015d2074eaSArnaldo Carvalho de Melo 	return perf_evsel__rawptr(evsel, sample, name);
3025d2074eaSArnaldo Carvalho de Melo }
3035d2074eaSArnaldo Carvalho de Melo 
3042c92f982STzvetomir Stoyanov (VMware) struct tep_format_field;
305efd2b924SArnaldo Carvalho de Melo 
3062c92f982STzvetomir Stoyanov (VMware) u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap);
30790525176SArnaldo Carvalho de Melo 
3082c92f982STzvetomir Stoyanov (VMware) struct tep_format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
309efd2b924SArnaldo Carvalho de Melo 
310daec78a0SArnaldo Carvalho de Melo #define perf_evsel__match(evsel, t, c)		\
311daec78a0SArnaldo Carvalho de Melo 	(evsel->attr.type == PERF_TYPE_##t &&	\
312daec78a0SArnaldo Carvalho de Melo 	 evsel->attr.config == PERF_COUNT_##c)
313daec78a0SArnaldo Carvalho de Melo 
314863e451fSJiri Olsa static inline bool perf_evsel__match2(struct perf_evsel *e1,
315863e451fSJiri Olsa 				      struct perf_evsel *e2)
316863e451fSJiri Olsa {
317863e451fSJiri Olsa 	return (e1->attr.type == e2->attr.type) &&
318863e451fSJiri Olsa 	       (e1->attr.config == e2->attr.config);
319863e451fSJiri Olsa }
320863e451fSJiri Olsa 
3214cabc3d1SAndi Kleen #define perf_evsel__cmp(a, b)			\
3224cabc3d1SAndi Kleen 	((a) &&					\
3234cabc3d1SAndi Kleen 	 (b) &&					\
3244cabc3d1SAndi Kleen 	 (a)->attr.type == (b)->attr.type &&	\
3254cabc3d1SAndi Kleen 	 (a)->attr.config == (b)->attr.config)
3264cabc3d1SAndi Kleen 
327f99f4719SJiri Olsa int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
328f99f4719SJiri Olsa 		     struct perf_counts_values *count);
329f99f4719SJiri Olsa 
330f7794d52SJiri Olsa int perf_evsel__read_counter(struct perf_evsel *evsel, int cpu, int thread);
331f7794d52SJiri Olsa 
332c52b12edSArnaldo Carvalho de Melo int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
333c52b12edSArnaldo Carvalho de Melo 			      int cpu, int thread, bool scale);
334c52b12edSArnaldo Carvalho de Melo 
335c52b12edSArnaldo Carvalho de Melo /**
336c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
337c52b12edSArnaldo Carvalho de Melo  *
338c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
339c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
340c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
341c52b12edSArnaldo Carvalho de Melo  */
342c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
343c52b12edSArnaldo Carvalho de Melo 					  int cpu, int thread)
344c52b12edSArnaldo Carvalho de Melo {
345c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
346c52b12edSArnaldo Carvalho de Melo }
347c52b12edSArnaldo Carvalho de Melo 
348c52b12edSArnaldo Carvalho de Melo /**
349c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
350c52b12edSArnaldo Carvalho de Melo  *
351c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
352c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
353c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
354c52b12edSArnaldo Carvalho de Melo  */
355c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
356c52b12edSArnaldo Carvalho de Melo 						 int cpu, int thread)
357c52b12edSArnaldo Carvalho de Melo {
358c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
359c52b12edSArnaldo Carvalho de Melo }
360c52b12edSArnaldo Carvalho de Melo 
361a3f698feSArnaldo Carvalho de Melo int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
3620807d2d8SArnaldo Carvalho de Melo 			     struct perf_sample *sample);
3630c21f736SArnaldo Carvalho de Melo 
36401468120SJiri Olsa int perf_evsel__parse_sample_timestamp(struct perf_evsel *evsel,
36501468120SJiri Olsa 				       union perf_event *event,
36601468120SJiri Olsa 				       u64 *timestamp);
36701468120SJiri Olsa 
3680c21f736SArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
3690c21f736SArnaldo Carvalho de Melo {
3700c21f736SArnaldo Carvalho de Melo 	return list_entry(evsel->node.next, struct perf_evsel, node);
3710c21f736SArnaldo Carvalho de Melo }
37207ac002fSArnaldo Carvalho de Melo 
373d87fcb4aSArnaldo Carvalho de Melo static inline struct perf_evsel *perf_evsel__prev(struct perf_evsel *evsel)
374d87fcb4aSArnaldo Carvalho de Melo {
375d87fcb4aSArnaldo Carvalho de Melo 	return list_entry(evsel->node.prev, struct perf_evsel, node);
376d87fcb4aSArnaldo Carvalho de Melo }
377d87fcb4aSArnaldo Carvalho de Melo 
378759ff497SNamhyung Kim /**
379759ff497SNamhyung Kim  * perf_evsel__is_group_leader - Return whether given evsel is a leader event
380759ff497SNamhyung Kim  *
381759ff497SNamhyung Kim  * @evsel - evsel selector to be tested
382759ff497SNamhyung Kim  *
383759ff497SNamhyung Kim  * Return %true if @evsel is a group leader or a stand-alone event
384759ff497SNamhyung Kim  */
385823254edSNamhyung Kim static inline bool perf_evsel__is_group_leader(const struct perf_evsel *evsel)
38607ac002fSArnaldo Carvalho de Melo {
387823254edSNamhyung Kim 	return evsel->leader == evsel;
38807ac002fSArnaldo Carvalho de Melo }
3890698aeddSArnaldo Carvalho de Melo 
390759ff497SNamhyung Kim /**
391759ff497SNamhyung Kim  * perf_evsel__is_group_event - Return whether given evsel is a group event
392759ff497SNamhyung Kim  *
393759ff497SNamhyung Kim  * @evsel - evsel selector to be tested
394759ff497SNamhyung Kim  *
395759ff497SNamhyung Kim  * Return %true iff event group view is enabled and @evsel is a actual group
396759ff497SNamhyung Kim  * leader which has other members in the group
397759ff497SNamhyung Kim  */
398759ff497SNamhyung Kim static inline bool perf_evsel__is_group_event(struct perf_evsel *evsel)
399759ff497SNamhyung Kim {
400759ff497SNamhyung Kim 	if (!symbol_conf.event_group)
401759ff497SNamhyung Kim 		return false;
402759ff497SNamhyung Kim 
403759ff497SNamhyung Kim 	return perf_evsel__is_group_leader(evsel) && evsel->nr_members > 1;
404759ff497SNamhyung Kim }
405759ff497SNamhyung Kim 
4065496bc0cSArnaldo Carvalho de Melo bool perf_evsel__is_function_event(struct perf_evsel *evsel);
4076bedfab6SJiri Olsa 
40803e0a7dfSWang Nan static inline bool perf_evsel__is_bpf_output(struct perf_evsel *evsel)
40903e0a7dfSWang Nan {
4102d6cae13SJiri Olsa 	return perf_evsel__match(evsel, SOFTWARE, SW_BPF_OUTPUT);
41103e0a7dfSWang Nan }
41203e0a7dfSWang Nan 
4130aa802a7SJiri Olsa static inline bool perf_evsel__is_clock(struct perf_evsel *evsel)
4140aa802a7SJiri Olsa {
4150aa802a7SJiri Olsa 	return perf_evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) ||
4160aa802a7SJiri Olsa 	       perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK);
4170aa802a7SJiri Olsa }
4180aa802a7SJiri Olsa 
4190698aeddSArnaldo Carvalho de Melo struct perf_attr_details {
4200698aeddSArnaldo Carvalho de Melo 	bool freq;
4210698aeddSArnaldo Carvalho de Melo 	bool verbose;
422e35ef355SArnaldo Carvalho de Melo 	bool event_group;
4239e3b6ec1SYunlong Song 	bool force;
424775d8a1bSNamhyung Kim 	bool trace_fields;
4250698aeddSArnaldo Carvalho de Melo };
4260698aeddSArnaldo Carvalho de Melo 
4270698aeddSArnaldo Carvalho de Melo int perf_evsel__fprintf(struct perf_evsel *evsel,
4280698aeddSArnaldo Carvalho de Melo 			struct perf_attr_details *details, FILE *fp);
429c0a54341SArnaldo Carvalho de Melo 
430e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_IP			(1<<0)
431e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_SYM		(1<<1)
432e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_DSO		(1<<2)
433e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_SYMOFFSET		(1<<3)
434e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_ONELINE		(1<<4)
435e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_SRCLINE		(1<<5)
436e20ab86eSArnaldo Carvalho de Melo #define EVSEL__PRINT_UNKNOWN_AS_ADDR	(1<<6)
43769b7e480SNamhyung Kim #define EVSEL__PRINT_CALLCHAIN_ARROW	(1<<7)
4382d9bbf6eSNamhyung Kim #define EVSEL__PRINT_SKIP_IGNORED	(1<<8)
439e20ab86eSArnaldo Carvalho de Melo 
4406f736735SArnaldo Carvalho de Melo struct callchain_cursor;
441ea453965SArnaldo Carvalho de Melo 
442d327e60cSArnaldo Carvalho de Melo int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
443d327e60cSArnaldo Carvalho de Melo 			      unsigned int print_opts,
4446f736735SArnaldo Carvalho de Melo 			      struct callchain_cursor *cursor, FILE *fp);
4456f736735SArnaldo Carvalho de Melo 
4466f736735SArnaldo Carvalho de Melo int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,
4476f736735SArnaldo Carvalho de Melo 			int left_alignment, unsigned int print_opts,
4486f736735SArnaldo Carvalho de Melo 			struct callchain_cursor *cursor, FILE *fp);
449e20ab86eSArnaldo Carvalho de Melo 
450c0a54341SArnaldo Carvalho de Melo bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
451c0a54341SArnaldo Carvalho de Melo 			  char *msg, size_t msgsize);
452602ad878SArnaldo Carvalho de Melo int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
45356e52e85SArnaldo Carvalho de Melo 			      int err, char *msg, size_t size);
45497f63e4aSNamhyung Kim 
45597f63e4aSNamhyung Kim static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
45697f63e4aSNamhyung Kim {
45797f63e4aSNamhyung Kim 	return evsel->idx - evsel->leader->idx;
45897f63e4aSNamhyung Kim }
459717e263fSNamhyung Kim 
4602bcf7306SJiri Olsa /* Iterates group WITHOUT the leader. */
461717e263fSNamhyung Kim #define for_each_group_member(_evsel, _leader) 					\
462717e263fSNamhyung Kim for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); 	\
463717e263fSNamhyung Kim      (_evsel) && (_evsel)->leader == (_leader);					\
464717e263fSNamhyung Kim      (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
465717e263fSNamhyung Kim 
4662bcf7306SJiri Olsa /* Iterates group WITH the leader. */
4672bcf7306SJiri Olsa #define for_each_group_evsel(_evsel, _leader) 					\
4682bcf7306SJiri Olsa for ((_evsel) = _leader; 							\
4692bcf7306SJiri Olsa      (_evsel) && (_evsel)->leader == (_leader);					\
4702bcf7306SJiri Olsa      (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
4712bcf7306SJiri Olsa 
472acf2abbdSArnaldo Carvalho de Melo static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evsel)
473384b6055SKan Liang {
474384b6055SKan Liang 	return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
475384b6055SKan Liang }
4762c5e8c52SPeter Zijlstra 
47727de9b2bSArnaldo Carvalho de Melo static inline bool evsel__has_callchain(const struct perf_evsel *evsel)
47827de9b2bSArnaldo Carvalho de Melo {
47927de9b2bSArnaldo Carvalho de Melo 	return (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) != 0;
48027de9b2bSArnaldo Carvalho de Melo }
48127de9b2bSArnaldo Carvalho de Melo 
4822c5e8c52SPeter Zijlstra typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *);
4832c5e8c52SPeter Zijlstra 
4842c5e8c52SPeter Zijlstra int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
4852c5e8c52SPeter Zijlstra 			     attr__fprintf_f attr__fprintf, void *priv);
4862c5e8c52SPeter Zijlstra 
4875449f13cSArnaldo Carvalho de Melo struct perf_env *perf_evsel__env(struct perf_evsel *evsel);
488f4e47f9fSRavi Bangoria 
489650d6220SJiri Olsa int perf_evsel__store_ids(struct perf_evsel *evsel, struct perf_evlist *evlist);
49069aad6f1SArnaldo Carvalho de Melo #endif /* __PERF_EVSEL_H */
491