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 evsel; 15 struct evlist; 16 struct parse_events_error; 17 18 struct option; 19 struct perf_pmu; 20 21 bool is_event_supported(u8 type, u64 config); 22 23 const char *event_type(int type); 24 25 int parse_events_option(const struct option *opt, const char *str, int unset); 26 int parse_events_option_new_evlist(const struct option *opt, const char *str, int unset); 27 __attribute__((nonnull(1, 2, 3))) 28 int __parse_events(struct evlist *evlist, const char *str, struct parse_events_error *error, 29 struct perf_pmu *fake_pmu, bool warn_if_reordered); 30 31 __attribute__((nonnull(1, 2, 3))) 32 static inline int parse_events(struct evlist *evlist, const char *str, 33 struct parse_events_error *err) 34 { 35 return __parse_events(evlist, str, err, /*fake_pmu=*/NULL, /*warn_if_reordered=*/true); 36 } 37 38 int parse_event(struct evlist *evlist, const char *str); 39 40 int parse_events_terms(struct list_head *terms, const char *str); 41 int parse_filter(const struct option *opt, const char *str, int unset); 42 int exclude_perf(const struct option *opt, const char *arg, int unset); 43 44 enum { 45 PARSE_EVENTS__TERM_TYPE_NUM, 46 PARSE_EVENTS__TERM_TYPE_STR, 47 }; 48 49 enum { 50 PARSE_EVENTS__TERM_TYPE_USER, 51 PARSE_EVENTS__TERM_TYPE_CONFIG, 52 PARSE_EVENTS__TERM_TYPE_CONFIG1, 53 PARSE_EVENTS__TERM_TYPE_CONFIG2, 54 PARSE_EVENTS__TERM_TYPE_CONFIG3, 55 PARSE_EVENTS__TERM_TYPE_NAME, 56 PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD, 57 PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ, 58 PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE, 59 PARSE_EVENTS__TERM_TYPE_TIME, 60 PARSE_EVENTS__TERM_TYPE_CALLGRAPH, 61 PARSE_EVENTS__TERM_TYPE_STACKSIZE, 62 PARSE_EVENTS__TERM_TYPE_NOINHERIT, 63 PARSE_EVENTS__TERM_TYPE_INHERIT, 64 PARSE_EVENTS__TERM_TYPE_MAX_STACK, 65 PARSE_EVENTS__TERM_TYPE_MAX_EVENTS, 66 PARSE_EVENTS__TERM_TYPE_NOOVERWRITE, 67 PARSE_EVENTS__TERM_TYPE_OVERWRITE, 68 PARSE_EVENTS__TERM_TYPE_DRV_CFG, 69 PARSE_EVENTS__TERM_TYPE_PERCORE, 70 PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT, 71 PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE, 72 PARSE_EVENTS__TERM_TYPE_METRIC_ID, 73 PARSE_EVENTS__TERM_TYPE_RAW, 74 __PARSE_EVENTS__TERM_TYPE_NR, 75 }; 76 77 struct parse_events_array { 78 size_t nr_ranges; 79 struct { 80 unsigned int start; 81 size_t length; 82 } *ranges; 83 }; 84 85 struct parse_events_term { 86 char *config; 87 struct parse_events_array array; 88 union { 89 char *str; 90 u64 num; 91 } val; 92 int type_val; 93 int type_term; 94 struct list_head list; 95 bool used; 96 bool no_value; 97 98 /* error string indexes for within parsed string */ 99 int err_term; 100 int err_val; 101 102 /* Coming from implicit alias */ 103 bool weak; 104 }; 105 106 struct parse_events_error { 107 int num_errors; /* number of errors encountered */ 108 int idx; /* index in the parsed string */ 109 char *str; /* string to display at the index */ 110 char *help; /* optional help string */ 111 int first_idx;/* as above, but for the first encountered error */ 112 char *first_str; 113 char *first_help; 114 }; 115 116 struct parse_events_state { 117 struct list_head list; 118 int idx; 119 struct parse_events_error *error; 120 struct evlist *evlist; 121 struct list_head *terms; 122 int stoken; 123 struct perf_pmu *fake_pmu; 124 char *hybrid_pmu_name; 125 bool wild_card_pmus; 126 }; 127 128 void parse_events__shrink_config_terms(void); 129 int parse_events__is_hardcoded_term(struct parse_events_term *term); 130 int parse_events_term__num(struct parse_events_term **term, 131 int type_term, char *config, u64 num, 132 bool novalue, 133 void *loc_term, void *loc_val); 134 int parse_events_term__str(struct parse_events_term **term, 135 int type_term, char *config, char *str, 136 void *loc_term, void *loc_val); 137 int parse_events_term__sym_hw(struct parse_events_term **term, 138 char *config, unsigned idx); 139 int parse_events_term__clone(struct parse_events_term **new, 140 struct parse_events_term *term); 141 void parse_events_term__delete(struct parse_events_term *term); 142 void parse_events_terms__delete(struct list_head *terms); 143 void parse_events_terms__purge(struct list_head *terms); 144 void parse_events__clear_array(struct parse_events_array *a); 145 int parse_events__modifier_event(struct list_head *list, char *str, bool add); 146 int parse_events__modifier_group(struct list_head *list, char *event_mod); 147 int parse_events_name(struct list_head *list, const char *name); 148 int parse_events_add_tracepoint(struct list_head *list, int *idx, 149 const char *sys, const char *event, 150 struct parse_events_error *error, 151 struct list_head *head_config); 152 int parse_events_load_bpf(struct parse_events_state *parse_state, 153 struct list_head *list, 154 char *bpf_file_name, 155 bool source, 156 struct list_head *head_config); 157 /* Provide this function for perf test */ 158 struct bpf_object; 159 int parse_events_load_bpf_obj(struct parse_events_state *parse_state, 160 struct list_head *list, 161 struct bpf_object *obj, 162 struct list_head *head_config); 163 int parse_events_add_numeric(struct parse_events_state *parse_state, 164 struct list_head *list, 165 u32 type, u64 config, 166 struct list_head *head_config); 167 int parse_events_add_tool(struct parse_events_state *parse_state, 168 struct list_head *list, 169 int tool_event); 170 int parse_events_add_cache(struct list_head *list, int *idx, const char *name, 171 struct parse_events_error *error, 172 struct list_head *head_config, 173 struct parse_events_state *parse_state); 174 int parse_events_add_breakpoint(struct list_head *list, int *idx, 175 u64 addr, char *type, u64 len); 176 int parse_events_add_pmu(struct parse_events_state *parse_state, 177 struct list_head *list, char *name, 178 struct list_head *head_config, 179 bool auto_merge_stats); 180 181 struct evsel *parse_events__add_event(int idx, struct perf_event_attr *attr, 182 const char *name, const char *metric_id, 183 struct perf_pmu *pmu); 184 185 int parse_events_multi_pmu_add(struct parse_events_state *parse_state, 186 char *str, 187 struct list_head *head_config, 188 struct list_head **listp); 189 190 int parse_events_copy_term_list(struct list_head *old, 191 struct list_head **new); 192 193 void parse_events__set_leader(char *name, struct list_head *list); 194 void parse_events_update_lists(struct list_head *list_event, 195 struct list_head *list_all); 196 void parse_events_evlist_error(struct parse_events_state *parse_state, 197 int idx, const char *str); 198 199 struct event_symbol { 200 const char *symbol; 201 const char *alias; 202 }; 203 extern struct event_symbol event_symbols_hw[]; 204 extern struct event_symbol event_symbols_sw[]; 205 206 char *parse_events_formats_error_string(char *additional_terms); 207 208 void parse_events_error__init(struct parse_events_error *err); 209 void parse_events_error__exit(struct parse_events_error *err); 210 void parse_events_error__handle(struct parse_events_error *err, int idx, 211 char *str, char *help); 212 void parse_events_error__print(struct parse_events_error *err, 213 const char *event); 214 215 #ifdef HAVE_LIBELF_SUPPORT 216 /* 217 * If the probe point starts with '%', 218 * or starts with "sdt_" and has a ':' but no '=', 219 * then it should be a SDT/cached probe point. 220 */ 221 static inline bool is_sdt_event(char *str) 222 { 223 return (str[0] == '%' || 224 (!strncmp(str, "sdt_", 4) && 225 !!strchr(str, ':') && !strchr(str, '='))); 226 } 227 #else 228 static inline bool is_sdt_event(char *str __maybe_unused) 229 { 230 return false; 231 } 232 #endif /* HAVE_LIBELF_SUPPORT */ 233 234 struct evsel *parse_events__add_event_hybrid(struct list_head *list, int *idx, 235 struct perf_event_attr *attr, 236 const char *name, 237 const char *metric_id, 238 struct perf_pmu *pmu, 239 struct list_head *config_terms); 240 241 #endif /* __PERF_PARSE_EVENTS_H */ 242