xref: /linux/tools/perf/util/parse-events.h (revision 95298d63c67673c654c08952672d016212b26054)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_PARSE_EVENTS_H
3 #define __PERF_PARSE_EVENTS_H
4 /*
5  * Parse symbolic events/counts passed in as options:
6  */
7 
8 #include <linux/list.h>
9 #include <stdbool.h>
10 #include <linux/types.h>
11 #include <linux/perf_event.h>
12 #include <string.h>
13 
14 struct list_head;
15 struct evsel;
16 struct evlist;
17 struct parse_events_error;
18 
19 struct option;
20 struct perf_pmu;
21 
22 struct tracepoint_path {
23 	char *system;
24 	char *name;
25 	struct tracepoint_path *next;
26 };
27 
28 struct tracepoint_path *tracepoint_id_to_path(u64 config);
29 struct tracepoint_path *tracepoint_name_to_path(const char *name);
30 bool have_tracepoints(struct list_head *evlist);
31 
32 const char *event_type(int type);
33 
34 int parse_events_option(const struct option *opt, const char *str, int unset);
35 int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset);
36 int parse_events(struct evlist *evlist, const char *str,
37 		 struct parse_events_error *error);
38 int parse_events_terms(struct list_head *terms, const char *str);
39 int parse_filter(const struct option *opt, const char *str, int unset);
40 int exclude_perf(const struct option *opt, const char *arg, int unset);
41 
42 #define EVENTS_HELP_MAX (128*1024)
43 
44 enum perf_pmu_event_symbol_type {
45 	PMU_EVENT_SYMBOL_ERR,		/* not a PMU EVENT */
46 	PMU_EVENT_SYMBOL,		/* normal style PMU event */
47 	PMU_EVENT_SYMBOL_PREFIX,	/* prefix of pre-suf style event */
48 	PMU_EVENT_SYMBOL_SUFFIX,	/* suffix of pre-suf style event */
49 };
50 
51 struct perf_pmu_event_symbol {
52 	char	*symbol;
53 	enum perf_pmu_event_symbol_type	type;
54 };
55 
56 enum {
57 	PARSE_EVENTS__TERM_TYPE_NUM,
58 	PARSE_EVENTS__TERM_TYPE_STR,
59 };
60 
61 enum {
62 	PARSE_EVENTS__TERM_TYPE_USER,
63 	PARSE_EVENTS__TERM_TYPE_CONFIG,
64 	PARSE_EVENTS__TERM_TYPE_CONFIG1,
65 	PARSE_EVENTS__TERM_TYPE_CONFIG2,
66 	PARSE_EVENTS__TERM_TYPE_NAME,
67 	PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD,
68 	PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ,
69 	PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE,
70 	PARSE_EVENTS__TERM_TYPE_TIME,
71 	PARSE_EVENTS__TERM_TYPE_CALLGRAPH,
72 	PARSE_EVENTS__TERM_TYPE_STACKSIZE,
73 	PARSE_EVENTS__TERM_TYPE_NOINHERIT,
74 	PARSE_EVENTS__TERM_TYPE_INHERIT,
75 	PARSE_EVENTS__TERM_TYPE_MAX_STACK,
76 	PARSE_EVENTS__TERM_TYPE_MAX_EVENTS,
77 	PARSE_EVENTS__TERM_TYPE_NOOVERWRITE,
78 	PARSE_EVENTS__TERM_TYPE_OVERWRITE,
79 	PARSE_EVENTS__TERM_TYPE_DRV_CFG,
80 	PARSE_EVENTS__TERM_TYPE_PERCORE,
81 	PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT,
82 	PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE,
83 	__PARSE_EVENTS__TERM_TYPE_NR,
84 };
85 
86 struct parse_events_array {
87 	size_t nr_ranges;
88 	struct {
89 		unsigned int start;
90 		size_t length;
91 	} *ranges;
92 };
93 
94 struct parse_events_term {
95 	char *config;
96 	struct parse_events_array array;
97 	union {
98 		char *str;
99 		u64  num;
100 	} val;
101 	int type_val;
102 	int type_term;
103 	struct list_head list;
104 	bool used;
105 	bool no_value;
106 
107 	/* error string indexes for within parsed string */
108 	int err_term;
109 	int err_val;
110 
111 	/* Coming from implicit alias */
112 	bool weak;
113 };
114 
115 struct parse_events_error {
116 	int   num_errors;       /* number of errors encountered */
117 	int   idx;	/* index in the parsed string */
118 	char *str;      /* string to display at the index */
119 	char *help;	/* optional help string */
120 	int   first_idx;/* as above, but for the first encountered error */
121 	char *first_str;
122 	char *first_help;
123 };
124 
125 struct parse_events_state {
126 	struct list_head	   list;
127 	int			   idx;
128 	int			   nr_groups;
129 	struct parse_events_error *error;
130 	struct evlist	  *evlist;
131 	struct list_head	  *terms;
132 	int			   stoken;
133 };
134 
135 void parse_events__handle_error(struct parse_events_error *err, int idx,
136 				char *str, char *help);
137 void parse_events__shrink_config_terms(void);
138 int parse_events__is_hardcoded_term(struct parse_events_term *term);
139 int parse_events_term__num(struct parse_events_term **term,
140 			   int type_term, char *config, u64 num,
141 			   bool novalue,
142 			   void *loc_term, void *loc_val);
143 int parse_events_term__str(struct parse_events_term **term,
144 			   int type_term, char *config, char *str,
145 			   void *loc_term, void *loc_val);
146 int parse_events_term__sym_hw(struct parse_events_term **term,
147 			      char *config, unsigned idx);
148 int parse_events_term__clone(struct parse_events_term **new,
149 			     struct parse_events_term *term);
150 void parse_events_term__delete(struct parse_events_term *term);
151 void parse_events_terms__delete(struct list_head *terms);
152 void parse_events_terms__purge(struct list_head *terms);
153 void parse_events__clear_array(struct parse_events_array *a);
154 int parse_events__modifier_event(struct list_head *list, char *str, bool add);
155 int parse_events__modifier_group(struct list_head *list, char *event_mod);
156 int parse_events_name(struct list_head *list, char *name);
157 int parse_events_add_tracepoint(struct list_head *list, int *idx,
158 				const char *sys, const char *event,
159 				struct parse_events_error *error,
160 				struct list_head *head_config);
161 int parse_events_load_bpf(struct parse_events_state *parse_state,
162 			  struct list_head *list,
163 			  char *bpf_file_name,
164 			  bool source,
165 			  struct list_head *head_config);
166 /* Provide this function for perf test */
167 struct bpf_object;
168 int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
169 			      struct list_head *list,
170 			      struct bpf_object *obj,
171 			      struct list_head *head_config);
172 int parse_events_add_numeric(struct parse_events_state *parse_state,
173 			     struct list_head *list,
174 			     u32 type, u64 config,
175 			     struct list_head *head_config);
176 enum perf_tool_event;
177 int parse_events_add_tool(struct parse_events_state *parse_state,
178 			  struct list_head *list,
179 			  enum perf_tool_event tool_event);
180 int parse_events_add_cache(struct list_head *list, int *idx,
181 			   char *type, char *op_result1, char *op_result2,
182 			   struct parse_events_error *error,
183 			   struct list_head *head_config);
184 int parse_events_add_breakpoint(struct list_head *list, int *idx,
185 				void *ptr, char *type, u64 len);
186 int parse_events_add_pmu(struct parse_events_state *parse_state,
187 			 struct list_head *list, char *name,
188 			 struct list_head *head_config,
189 			 bool auto_merge_stats,
190 			 bool use_alias);
191 
192 struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr,
193 					char *name, struct perf_pmu *pmu);
194 
195 int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
196 			       char *str,
197 			       struct list_head **listp);
198 
199 int parse_events_copy_term_list(struct list_head *old,
200 				 struct list_head **new);
201 
202 enum perf_pmu_event_symbol_type
203 perf_pmu__parse_check(const char *name);
204 void parse_events__set_leader(char *name, struct list_head *list,
205 			      struct parse_events_state *parse_state);
206 void parse_events_update_lists(struct list_head *list_event,
207 			       struct list_head *list_all);
208 void parse_events_evlist_error(struct parse_events_state *parse_state,
209 			       int idx, const char *str);
210 
211 void print_events(const char *event_glob, bool name_only, bool quiet,
212 		  bool long_desc, bool details_flag, bool deprecated);
213 
214 struct event_symbol {
215 	const char	*symbol;
216 	const char	*alias;
217 };
218 extern struct event_symbol event_symbols_hw[];
219 extern struct event_symbol event_symbols_sw[];
220 void print_symbol_events(const char *event_glob, unsigned type,
221 				struct event_symbol *syms, unsigned max,
222 				bool name_only);
223 void print_tool_events(const char *event_glob, bool name_only);
224 void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
225 			     bool name_only);
226 int print_hwcache_events(const char *event_glob, bool name_only);
227 void print_sdt_events(const char *subsys_glob, const char *event_glob,
228 		      bool name_only);
229 int is_valid_tracepoint(const char *event_string);
230 
231 int valid_event_mount(const char *eventfs);
232 char *parse_events_formats_error_string(char *additional_terms);
233 
234 void parse_events_print_error(struct parse_events_error *err,
235 			      const char *event);
236 
237 #ifdef HAVE_LIBELF_SUPPORT
238 /*
239  * If the probe point starts with '%',
240  * or starts with "sdt_" and has a ':' but no '=',
241  * then it should be a SDT/cached probe point.
242  */
243 static inline bool is_sdt_event(char *str)
244 {
245 	return (str[0] == '%' ||
246 		(!strncmp(str, "sdt_", 4) &&
247 		 !!strchr(str, ':') && !strchr(str, '=')));
248 }
249 #else
250 static inline bool is_sdt_event(char *str __maybe_unused)
251 {
252 	return false;
253 }
254 #endif /* HAVE_LIBELF_SUPPORT */
255 
256 #endif /* __PERF_PARSE_EVENTS_H */
257