Skip to content

Commit d4be39c

Browse files
captain5050namhyung
authored andcommitted
perf metrics: Fix metric matching
The metric match function fails for cases like looking for "metric" in the string "all;foo_metric;metric" as the "metric" in "foo_metric" matches but isn't preceeded by a ';'. Fix this by matching the first list item and recursively matching on failure the next item after a semicolon. Signed-off-by: Ian Rogers <[email protected]> Reviewed-by: Kan Liang <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ef5de16 commit d4be39c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

tools/perf/util/metricgroup.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,25 +352,23 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
352352
return 0;
353353
}
354354

355-
static bool match_metric(const char *n, const char *list)
355+
static bool match_metric(const char *metric_or_groups, const char *sought)
356356
{
357357
int len;
358358
char *m;
359359

360-
if (!list)
360+
if (!sought)
361361
return false;
362-
if (!strcmp(list, "all"))
362+
if (!strcmp(sought, "all"))
363363
return true;
364-
if (!n)
365-
return !strcasecmp(list, "No_group");
366-
len = strlen(list);
367-
m = strcasestr(n, list);
368-
if (!m)
369-
return false;
370-
if ((m == n || m[-1] == ';' || m[-1] == ' ') &&
371-
(m[len] == 0 || m[len] == ';'))
364+
if (!metric_or_groups)
365+
return !strcasecmp(sought, "No_group");
366+
len = strlen(sought);
367+
if (!strncasecmp(metric_or_groups, sought, len) &&
368+
(metric_or_groups[len] == 0 || metric_or_groups[len] == ';'))
372369
return true;
373-
return false;
370+
m = strchr(metric_or_groups, ';');
371+
return m && match_metric(m + 1, sought);
374372
}
375373

376374
static bool match_pm_metric(const struct pmu_metric *pm, const char *pmu, const char *metric)

0 commit comments

Comments
 (0)