Commit d4be39ca authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim

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: default avatarIan Rogers <irogers@google.com>
Reviewed-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240224011420.3066322-1-irogers@google.com
parent ef5de161
...@@ -352,25 +352,23 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, ...@@ -352,25 +352,23 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids,
return 0; return 0;
} }
static bool match_metric(const char *n, const char *list) static bool match_metric(const char *metric_or_groups, const char *sought)
{ {
int len; int len;
char *m; char *m;
if (!list) if (!sought)
return false; return false;
if (!strcmp(list, "all")) if (!strcmp(sought, "all"))
return true; return true;
if (!n) if (!metric_or_groups)
return !strcasecmp(list, "No_group"); return !strcasecmp(sought, "No_group");
len = strlen(list); len = strlen(sought);
m = strcasestr(n, list); if (!strncasecmp(metric_or_groups, sought, len) &&
if (!m) (metric_or_groups[len] == 0 || metric_or_groups[len] == ';'))
return false;
if ((m == n || m[-1] == ';' || m[-1] == ' ') &&
(m[len] == 0 || m[len] == ';'))
return true; return true;
return false; m = strchr(metric_or_groups, ';');
return m && match_metric(m + 1, sought);
} }
static bool match_pm_metric(const struct pmu_metric *pm, const char *pmu, const char *metric) static bool match_pm_metric(const struct pmu_metric *pm, const char *pmu, const char *metric)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment