Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Factor out PMU matching in parser

Factor out the PMU name matching in the event parser into a separate
function, to use the same code for other grammar rules later.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-5-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Andi Kleen and committed by
Arnaldo Carvalho de Melo
2073ad33 b4229e9d

+52 -29
+46
tools/perf/util/parse-events.c
··· 1260 1260 return evsel ? 0 : -ENOMEM; 1261 1261 } 1262 1262 1263 + int parse_events_multi_pmu_add(struct parse_events_evlist *data, 1264 + char *str, struct list_head **listp) 1265 + { 1266 + struct list_head *head; 1267 + struct parse_events_term *term; 1268 + struct list_head *list; 1269 + struct perf_pmu *pmu = NULL; 1270 + int ok = 0; 1271 + 1272 + *listp = NULL; 1273 + /* Add it for all PMUs that support the alias */ 1274 + list = malloc(sizeof(struct list_head)); 1275 + if (!list) 1276 + return -1; 1277 + INIT_LIST_HEAD(list); 1278 + while ((pmu = perf_pmu__scan(pmu)) != NULL) { 1279 + struct perf_pmu_alias *alias; 1280 + 1281 + list_for_each_entry(alias, &pmu->aliases, list) { 1282 + if (!strcasecmp(alias->name, str)) { 1283 + head = malloc(sizeof(struct list_head)); 1284 + if (!head) 1285 + return -1; 1286 + INIT_LIST_HEAD(head); 1287 + if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 1288 + str, 1, false, &str, NULL) < 0) 1289 + return -1; 1290 + list_add_tail(&term->list, head); 1291 + 1292 + if (!parse_events_add_pmu(data, list, 1293 + pmu->name, head)) { 1294 + pr_debug("%s -> %s/%s/\n", str, 1295 + pmu->name, alias->str); 1296 + ok++; 1297 + } 1298 + 1299 + parse_events_terms__delete(head); 1300 + } 1301 + } 1302 + } 1303 + if (!ok) 1304 + return -1; 1305 + *listp = list; 1306 + return 0; 1307 + } 1308 + 1263 1309 int parse_events__modifier_group(struct list_head *list, 1264 1310 char *event_mod) 1265 1311 {
+5
tools/perf/util/parse-events.h
··· 167 167 int parse_events_add_pmu(struct parse_events_evlist *data, 168 168 struct list_head *list, char *name, 169 169 struct list_head *head_config); 170 + 171 + int parse_events_multi_pmu_add(struct parse_events_evlist *data, 172 + char *str, 173 + struct list_head **listp); 174 + 170 175 enum perf_pmu_event_symbol_type 171 176 perf_pmu__parse_check(const char *name); 172 177 void parse_events__set_leader(char *name, struct list_head *list);
+1 -29
tools/perf/util/parse-events.y
··· 236 236 | 237 237 PE_KERNEL_PMU_EVENT sep_dc 238 238 { 239 - struct parse_events_evlist *data = _data; 240 - struct list_head *head; 241 - struct parse_events_term *term; 242 239 struct list_head *list; 243 - struct perf_pmu *pmu = NULL; 244 - int ok = 0; 245 240 246 - /* Add it for all PMUs that support the alias */ 247 - ALLOC_LIST(list); 248 - while ((pmu = perf_pmu__scan(pmu)) != NULL) { 249 - struct perf_pmu_alias *alias; 250 - 251 - list_for_each_entry(alias, &pmu->aliases, list) { 252 - if (!strcasecmp(alias->name, $1)) { 253 - ALLOC_LIST(head); 254 - ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 255 - $1, 1, false, &@1, NULL)); 256 - list_add_tail(&term->list, head); 257 - 258 - if (!parse_events_add_pmu(data, list, 259 - pmu->name, head)) { 260 - pr_debug("%s -> %s/%s/\n", $1, 261 - pmu->name, alias->str); 262 - ok++; 263 - } 264 - 265 - parse_events_terms__delete(head); 266 - } 267 - } 268 - } 269 - if (!ok) 241 + if (parse_events_multi_pmu_add(_data, $1, &list) < 0) 270 242 YYABORT; 271 243 $$ = list; 272 244 }