1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_PARSE_EVENTS_H
3 #define __PERF_PARSE_EVENTS_H
5 * Parse symbolic events/counts passed in as options:
8 #include <linux/list.h>
10 #include <linux/types.h>
11 #include <linux/perf_event.h>
17 struct parse_events_error
;
23 const char *event_type(int type
);
25 /* Arguments encoded in opt->value. */
26 struct parse_events_option_args
{
27 struct evlist
**evlistp
;
28 const char *pmu_filter
;
30 int parse_events_option(const struct option
*opt
, const char *str
, int unset
);
31 int parse_events_option_new_evlist(const struct option
*opt
, const char *str
, int unset
);
32 __attribute__((nonnull(1, 2, 4)))
33 int __parse_events(struct evlist
*evlist
, const char *str
, const char *pmu_filter
,
34 struct parse_events_error
*error
, bool fake_pmu
,
35 bool warn_if_reordered
, bool fake_tp
);
37 __attribute__((nonnull(1, 2, 3)))
38 static inline int parse_events(struct evlist
*evlist
, const char *str
,
39 struct parse_events_error
*err
)
41 return __parse_events(evlist
, str
, /*pmu_filter=*/NULL
, err
, /*fake_pmu=*/false,
42 /*warn_if_reordered=*/true, /*fake_tp=*/false);
45 int parse_event(struct evlist
*evlist
, const char *str
);
47 int parse_filter(const struct option
*opt
, const char *str
, int unset
);
48 int exclude_perf(const struct option
*opt
, const char *arg
, int unset
);
50 enum parse_events__term_val_type
{
51 PARSE_EVENTS__TERM_TYPE_NUM
,
52 PARSE_EVENTS__TERM_TYPE_STR
,
55 enum parse_events__term_type
{
56 PARSE_EVENTS__TERM_TYPE_USER
,
57 PARSE_EVENTS__TERM_TYPE_CONFIG
,
58 PARSE_EVENTS__TERM_TYPE_CONFIG1
,
59 PARSE_EVENTS__TERM_TYPE_CONFIG2
,
60 PARSE_EVENTS__TERM_TYPE_CONFIG3
,
61 PARSE_EVENTS__TERM_TYPE_NAME
,
62 PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD
,
63 PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ
,
64 PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE
,
65 PARSE_EVENTS__TERM_TYPE_TIME
,
66 PARSE_EVENTS__TERM_TYPE_CALLGRAPH
,
67 PARSE_EVENTS__TERM_TYPE_STACKSIZE
,
68 PARSE_EVENTS__TERM_TYPE_NOINHERIT
,
69 PARSE_EVENTS__TERM_TYPE_INHERIT
,
70 PARSE_EVENTS__TERM_TYPE_MAX_STACK
,
71 PARSE_EVENTS__TERM_TYPE_MAX_EVENTS
,
72 PARSE_EVENTS__TERM_TYPE_NOOVERWRITE
,
73 PARSE_EVENTS__TERM_TYPE_OVERWRITE
,
74 PARSE_EVENTS__TERM_TYPE_DRV_CFG
,
75 PARSE_EVENTS__TERM_TYPE_PERCORE
,
76 PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT
,
77 PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE
,
78 PARSE_EVENTS__TERM_TYPE_METRIC_ID
,
79 PARSE_EVENTS__TERM_TYPE_RAW
,
80 PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE
,
81 PARSE_EVENTS__TERM_TYPE_HARDWARE
,
82 #define __PARSE_EVENTS__TERM_TYPE_NR (PARSE_EVENTS__TERM_TYPE_HARDWARE + 1)
85 struct parse_events_term
{
86 /** @list: The term list the term is a part of. */
87 struct list_head list
;
89 * @config: The left-hand side of a term assignment, so the term
90 * "event=8" would have the config be "event"
94 * @val: The right-hand side of a term assignment that can either be a
95 * string or a number depending on type_val.
101 /** @type_val: The union variable in val to be used for the term. */
102 enum parse_events__term_val_type type_val
;
104 * @type_term: A predefined term type or PARSE_EVENTS__TERM_TYPE_USER
107 enum parse_events__term_type type_term
;
109 * @err_term: The column index of the term from parsing, used during
114 * @err_val: The column index of the val from parsing, used during error
118 /** @used: Was the term used during parameterized-eval. */
121 * @weak: A term from the sysfs or json encoding of an event that
122 * shouldn't override terms coming from the command line.
126 * @no_value: Is there no value. If a numeric term has no value then the
127 * value is assumed to be 1. An event name also has no value.
131 * @alternate_hw_config: config is the event name but num is an
132 * alternate PERF_TYPE_HARDWARE config value which is often nice for the
133 * sake of quick matching.
135 bool alternate_hw_config
;
138 struct parse_events_error
{
139 /** @list: The head of a list of errors. */
140 struct list_head list
;
143 /* A wrapper around a list of terms for the sake of better type safety. */
144 struct parse_events_terms
{
145 struct list_head terms
;
148 struct parse_events_state
{
149 /* The list parsed events are placed on. */
150 struct list_head list
;
151 /* The updated index used by entries as they are added. */
153 /* Error information. */
154 struct parse_events_error
*error
;
155 /* Holds returned terms for term parsing. */
156 struct parse_events_terms
*terms
;
159 /* Use the fake PMU marker for testing. */
161 /* Skip actual tracepoint processing for testing. */
163 /* If non-null, when wildcard matching only match the given PMU. */
164 const char *pmu_filter
;
165 /* Should PE_LEGACY_NAME tokens be generated for config terms? */
166 bool match_legacy_cache_terms
;
167 /* Were multiple PMUs scanned to find events? */
171 const char *parse_events__term_type_str(enum parse_events__term_type term_type
);
173 bool parse_events__filter_pmu(const struct parse_events_state
*parse_state
,
174 const struct perf_pmu
*pmu
);
175 void parse_events__shrink_config_terms(void);
176 int parse_events__is_hardcoded_term(struct parse_events_term
*term
);
177 int parse_events_term__num(struct parse_events_term
**term
,
178 enum parse_events__term_type type_term
,
179 const char *config
, u64 num
,
181 void *loc_term
, void *loc_val
);
182 int parse_events_term__str(struct parse_events_term
**term
,
183 enum parse_events__term_type type_term
,
184 char *config
, char *str
,
185 void *loc_term
, void *loc_val
);
186 int parse_events_term__term(struct parse_events_term
**term
,
187 enum parse_events__term_type term_lhs
,
188 enum parse_events__term_type term_rhs
,
189 void *loc_term
, void *loc_val
);
190 int parse_events_term__clone(struct parse_events_term
**new,
191 const struct parse_events_term
*term
);
192 void parse_events_term__delete(struct parse_events_term
*term
);
194 void parse_events_terms__delete(struct parse_events_terms
*terms
);
195 void parse_events_terms__init(struct parse_events_terms
*terms
);
196 void parse_events_terms__exit(struct parse_events_terms
*terms
);
197 int parse_events_terms(struct parse_events_terms
*terms
, const char *str
, FILE *input
);
198 int parse_events_terms__to_strbuf(const struct parse_events_terms
*terms
, struct strbuf
*sb
);
200 struct parse_events_modifier
{
201 u8 precise
; /* Number of repeated 'p' for precision. */
202 bool precise_max
: 1; /* 'P' */
203 bool non_idle
: 1; /* 'I' */
204 bool sample_read
: 1; /* 'S' */
205 bool pinned
: 1; /* 'D' */
206 bool exclusive
: 1; /* 'e' */
207 bool weak
: 1; /* 'W' */
208 bool bpf
: 1; /* 'b' */
209 bool user
: 1; /* 'u' */
210 bool kernel
: 1; /* 'k' */
211 bool hypervisor
: 1; /* 'h' */
212 bool guest
: 1; /* 'G' */
213 bool host
: 1; /* 'H' */
214 bool retire_lat
: 1; /* 'R' */
217 int parse_events__modifier_event(struct parse_events_state
*parse_state
, void *loc
,
218 struct list_head
*list
, struct parse_events_modifier mod
);
219 int parse_events__modifier_group(struct parse_events_state
*parse_state
, void *loc
,
220 struct list_head
*list
, struct parse_events_modifier mod
);
221 int parse_events__set_default_name(struct list_head
*list
, char *name
);
222 int parse_events_add_tracepoint(struct parse_events_state
*parse_state
,
223 struct list_head
*list
,
224 const char *sys
, const char *event
,
225 struct parse_events_error
*error
,
226 struct parse_events_terms
*head_config
, void *loc
);
227 int parse_events_add_numeric(struct parse_events_state
*parse_state
,
228 struct list_head
*list
,
229 u32 type
, u64 config
,
230 const struct parse_events_terms
*head_config
,
232 int parse_events_add_cache(struct list_head
*list
, int *idx
, const char *name
,
233 struct parse_events_state
*parse_state
,
234 struct parse_events_terms
*parsed_terms
);
235 int parse_events__decode_legacy_cache(const char *name
, int pmu_type
, __u64
*config
);
236 int parse_events_add_breakpoint(struct parse_events_state
*parse_state
,
237 struct list_head
*list
,
238 u64 addr
, char *type
, u64 len
,
239 struct parse_events_terms
*head_config
);
241 struct evsel
*parse_events__add_event(int idx
, struct perf_event_attr
*attr
,
242 const char *name
, const char *metric_id
,
243 struct perf_pmu
*pmu
);
245 int parse_events_multi_pmu_add(struct parse_events_state
*parse_state
,
246 const char *event_name
, u64 hw_config
,
247 const struct parse_events_terms
*const_parsed_terms
,
248 struct list_head
**listp
, void *loc
);
250 int parse_events_multi_pmu_add_or_add_pmu(struct parse_events_state
*parse_state
,
251 const char *event_or_pmu
,
252 const struct parse_events_terms
*const_parsed_terms
,
253 struct list_head
**listp
,
256 void parse_events__set_leader(char *name
, struct list_head
*list
);
258 struct event_symbol
{
262 extern const struct event_symbol event_symbols_hw
[];
263 extern const struct event_symbol event_symbols_sw
[];
265 char *parse_events_formats_error_string(char *additional_terms
);
267 void parse_events_error__init(struct parse_events_error
*err
);
268 void parse_events_error__exit(struct parse_events_error
*err
);
269 void parse_events_error__handle(struct parse_events_error
*err
, int idx
,
270 char *str
, char *help
);
271 void parse_events_error__print(const struct parse_events_error
*err
,
273 bool parse_events_error__contains(const struct parse_events_error
*err
,
275 #ifdef HAVE_LIBELF_SUPPORT
277 * If the probe point starts with '%',
278 * or starts with "sdt_" and has a ':' but no '=',
279 * then it should be a SDT/cached probe point.
281 static inline bool is_sdt_event(char *str
)
283 return (str
[0] == '%' ||
284 (!strncmp(str
, "sdt_", 4) &&
285 !!strchr(str
, ':') && !strchr(str
, '=')));
288 static inline bool is_sdt_event(char *str __maybe_unused
)
292 #endif /* HAVE_LIBELF_SUPPORT */
294 size_t default_breakpoint_len(void);
296 #endif /* __PERF_PARSE_EVENTS_H */