Linux Audio

Check our new training course

Loading...
v6.9.4
  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 <stdio.h>
 13#include <string.h>
 14
 15struct evsel;
 16struct evlist;
 17struct parse_events_error;
 18
 19struct option;
 20struct perf_pmu;
 21struct strbuf;
 22
 23const char *event_type(int type);
 24
 25/* Arguments encoded in opt->value. */
 26struct parse_events_option_args {
 27	struct evlist **evlistp;
 28	const char *pmu_filter;
 29};
 30int parse_events_option(const struct option *opt, const char *str, int unset);
 31int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset);
 32__attribute__((nonnull(1, 2, 4)))
 33int __parse_events(struct evlist *evlist, const char *str, const char *pmu_filter,
 34		   struct parse_events_error *error, struct perf_pmu *fake_pmu,
 35		   bool warn_if_reordered);
 36
 37__attribute__((nonnull(1, 2, 3)))
 38static inline int parse_events(struct evlist *evlist, const char *str,
 39			       struct parse_events_error *err)
 40{
 41	return __parse_events(evlist, str, /*pmu_filter=*/NULL, err, /*fake_pmu=*/NULL,
 42			      /*warn_if_reordered=*/true);
 43}
 44
 45int parse_event(struct evlist *evlist, const char *str);
 46
 47int parse_filter(const struct option *opt, const char *str, int unset);
 48int exclude_perf(const struct option *opt, const char *arg, int unset);
 49
 50enum parse_events__term_val_type {
 51	PARSE_EVENTS__TERM_TYPE_NUM,
 52	PARSE_EVENTS__TERM_TYPE_STR,
 53};
 54
 55enum 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)
 83};
 84
 85struct parse_events_term {
 86	/** @list: The term list the term is a part of. */
 87	struct list_head list;
 88	/**
 89	 * @config: The left-hand side of a term assignment, so the term
 90	 * "event=8" would have the config be "event"
 91	 */
 92	const char *config;
 93	/**
 94	 * @val: The right-hand side of a term assignment that can either be a
 95	 * string or a number depending on type_val.
 96	 */
 97	union {
 98		char *str;
 99		u64  num;
100	} val;
101	/** @type_val: The union variable in val to be used for the term. */
102	enum parse_events__term_val_type type_val;
103	/**
104	 * @type_term: A predefined term type or PARSE_EVENTS__TERM_TYPE_USER
105	 * when not inbuilt.
106	 */
107	enum parse_events__term_type type_term;
108	/**
109	 * @err_term: The column index of the term from parsing, used during
110	 * error output.
111	 */
112	int err_term;
113	/**
114	 * @err_val: The column index of the val from parsing, used during error
115	 * output.
116	 */
117	int err_val;
118	/** @used: Was the term used during parameterized-eval. */
119	bool used;
120	/**
121	 * @weak: A term from the sysfs or json encoding of an event that
122	 * shouldn't override terms coming from the command line.
123	 */
124	bool weak;
125	/**
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.
128	 */
129	bool no_value;
130};
131
132struct parse_events_error {
133	/** @list: The head of a list of errors. */
134	struct list_head list;
135};
136
137/* A wrapper around a list of terms for the sake of better type safety. */
138struct parse_events_terms {
139	struct list_head terms;
140};
141
142struct parse_events_state {
143	/* The list parsed events are placed on. */
144	struct list_head	   list;
145	/* The updated index used by entries as they are added. */
146	int			   idx;
147	/* Error information. */
148	struct parse_events_error *error;
149	/* Holds returned terms for term parsing. */
150	struct parse_events_terms *terms;
151	/* Start token. */
152	int			   stoken;
153	/* Special fake PMU marker for testing. */
154	struct perf_pmu		  *fake_pmu;
155	/* If non-null, when wildcard matching only match the given PMU. */
156	const char		  *pmu_filter;
157	/* Should PE_LEGACY_NAME tokens be generated for config terms? */
158	bool			   match_legacy_cache_terms;
159	/* Were multiple PMUs scanned to find events? */
160	bool			   wild_card_pmus;
161};
162
163bool parse_events__filter_pmu(const struct parse_events_state *parse_state,
164			      const struct perf_pmu *pmu);
165void parse_events__shrink_config_terms(void);
166int parse_events__is_hardcoded_term(struct parse_events_term *term);
167int parse_events_term__num(struct parse_events_term **term,
168			   enum parse_events__term_type type_term,
169			   const char *config, u64 num,
170			   bool novalue,
171			   void *loc_term, void *loc_val);
172int parse_events_term__str(struct parse_events_term **term,
173			   enum parse_events__term_type type_term,
174			   char *config, char *str,
175			   void *loc_term, void *loc_val);
176int parse_events_term__term(struct parse_events_term **term,
177			    enum parse_events__term_type term_lhs,
178			    enum parse_events__term_type term_rhs,
179			    void *loc_term, void *loc_val);
180int parse_events_term__clone(struct parse_events_term **new,
181			     struct parse_events_term *term);
182void parse_events_term__delete(struct parse_events_term *term);
183
184void parse_events_terms__delete(struct parse_events_terms *terms);
185void parse_events_terms__init(struct parse_events_terms *terms);
186void parse_events_terms__exit(struct parse_events_terms *terms);
187int parse_events_terms(struct parse_events_terms *terms, const char *str, FILE *input);
188int parse_events_terms__to_strbuf(const struct parse_events_terms *terms, struct strbuf *sb);
189int parse_events__modifier_event(struct list_head *list, char *str, bool add);
190int parse_events__modifier_group(struct list_head *list, char *event_mod);
191int parse_events_name(struct list_head *list, const char *name);
192int parse_events_add_tracepoint(struct list_head *list, int *idx,
193				const char *sys, const char *event,
194				struct parse_events_error *error,
195				struct parse_events_terms *head_config, void *loc);
196int parse_events_add_numeric(struct parse_events_state *parse_state,
197			     struct list_head *list,
198			     u32 type, u64 config,
199			     struct parse_events_terms *head_config,
200			     bool wildcard);
201int parse_events_add_tool(struct parse_events_state *parse_state,
202			  struct list_head *list,
203			  int tool_event);
204int parse_events_add_cache(struct list_head *list, int *idx, const char *name,
205			   struct parse_events_state *parse_state,
206			   struct parse_events_terms *head_config);
207int parse_events__decode_legacy_cache(const char *name, int pmu_type, __u64 *config);
208int parse_events_add_breakpoint(struct parse_events_state *parse_state,
209				struct list_head *list,
210				u64 addr, char *type, u64 len,
211				struct parse_events_terms *head_config);
212int parse_events_add_pmu(struct parse_events_state *parse_state,
213			 struct list_head *list, const char *name,
214			 const struct parse_events_terms *const_parsed_terms,
215			bool auto_merge_stats, void *loc);
216
217struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr,
218				      const char *name, const char *metric_id,
219				      struct perf_pmu *pmu);
220
221int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
222			       const char *event_name,
223			       const struct parse_events_terms *const_parsed_terms,
224			       struct list_head **listp, void *loc);
225
226void parse_events__set_leader(char *name, struct list_head *list);
227void parse_events_update_lists(struct list_head *list_event,
228			       struct list_head *list_all);
229void parse_events_evlist_error(struct parse_events_state *parse_state,
230			       int idx, const char *str);
231
232struct event_symbol {
233	const char	*symbol;
234	const char	*alias;
235};
236extern struct event_symbol event_symbols_hw[];
237extern struct event_symbol event_symbols_sw[];
238
239char *parse_events_formats_error_string(char *additional_terms);
 
 
 
 
 
 
 
 
 
 
 
 
240
241void parse_events_error__init(struct parse_events_error *err);
242void parse_events_error__exit(struct parse_events_error *err);
243void parse_events_error__handle(struct parse_events_error *err, int idx,
244				char *str, char *help);
245void parse_events_error__print(const struct parse_events_error *err,
246			       const char *event);
247bool parse_events_error__contains(const struct parse_events_error *err,
248				  const char *needle);
249#ifdef HAVE_LIBELF_SUPPORT
250/*
251 * If the probe point starts with '%',
252 * or starts with "sdt_" and has a ':' but no '=',
253 * then it should be a SDT/cached probe point.
254 */
255static inline bool is_sdt_event(char *str)
256{
257	return (str[0] == '%' ||
258		(!strncmp(str, "sdt_", 4) &&
259		 !!strchr(str, ':') && !strchr(str, '=')));
260}
261#else
262static inline bool is_sdt_event(char *str __maybe_unused)
263{
264	return false;
265}
266#endif /* HAVE_LIBELF_SUPPORT */
267
268#endif /* __PERF_PARSE_EVENTS_H */
v3.1
 
 1#ifndef __PERF_PARSE_EVENTS_H
 2#define __PERF_PARSE_EVENTS_H
 3/*
 4 * Parse symbolic events/counts passed in as options:
 5 */
 6
 7#include "../../../include/linux/perf_event.h"
 
 
 
 
 
 8
 9struct list_head;
10struct perf_evsel;
11struct perf_evlist;
12
13struct option;
 
 
14
15struct tracepoint_path {
16	char *system;
17	char *name;
18	struct tracepoint_path *next;
 
 
19};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
22extern bool have_tracepoints(struct list_head *evlist);
23
24const char *event_type(int type);
25const char *event_name(struct perf_evsel *event);
26extern const char *__event_name(int type, u64 config);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28extern int parse_events_option(const struct option *opt, const char *str,
29			       int unset);
30extern int parse_events(struct perf_evlist *evlist, const char *str,
31			int unset);
32extern int parse_filter(const struct option *opt, const char *str, int unset);
33
34#define EVENTS_HELP_MAX (128*1024)
35
36void print_events(const char *event_glob);
37void print_events_type(u8 type);
38void print_tracepoint_events(const char *subsys_glob, const char *event_glob);
39int print_hwcache_events(const char *event_glob);
40extern int is_valid_tracepoint(const char *event_string);
41
42extern char debugfs_path[];
43extern int valid_debugfs_mount(const char *debugfs);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
45#endif /* __PERF_PARSE_EVENTS_H */