Skip to content

Commit 2073ad3

Browse files
Andi Kleenacmel
authored andcommitted
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 <[email protected]> Acked-by: Jiri Olsa <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b4229e9 commit 2073ad3

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

tools/perf/util/parse-events.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,52 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
12601260
return evsel ? 0 : -ENOMEM;
12611261
}
12621262

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+
12631309
int parse_events__modifier_group(struct list_head *list,
12641310
char *event_mod)
12651311
{

tools/perf/util/parse-events.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
167167
int parse_events_add_pmu(struct parse_events_evlist *data,
168168
struct list_head *list, char *name,
169169
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+
170175
enum perf_pmu_event_symbol_type
171176
perf_pmu__parse_check(const char *name);
172177
void parse_events__set_leader(char *name, struct list_head *list);

tools/perf/util/parse-events.y

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -236,37 +236,9 @@ PE_NAME opt_event_config
236236
|
237237
PE_KERNEL_PMU_EVENT sep_dc
238238
{
239-
struct parse_events_evlist *data = _data;
240-
struct list_head *head;
241-
struct parse_events_term *term;
242239
struct list_head *list;
243-
struct perf_pmu *pmu = NULL;
244-
int ok = 0;
245240

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)
270242
YYABORT;
271243
$$ = list;
272244
}

0 commit comments

Comments
 (0)