diff options
author | Ian Rogers | 2024-02-23 17:14:19 -0800 |
---|---|---|
committer | Namhyung Kim | 2024-02-29 13:39:54 -0800 |
commit | d4be39cadef0dbba6667a96e8e7857d510ed4e20 (patch) | |
tree | cf8980f1c19ffde680a1551afec556a3f78d09ba /tools/perf | |
parent | ef5de1613d7d92bdc975e6beb34bb0fa94f34078 (diff) |
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 <irogers@google.com>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240224011420.3066322-1-irogers@google.com
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/metricgroup.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index b24a1c177a80..2d6865c392ef 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -352,25 +352,23 @@ static int setup_metric_events(const char *pmu, struct hashmap *ids, 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; char *m; - if (!list) + if (!sought) return false; - if (!strcmp(list, "all")) + if (!strcmp(sought, "all")) return true; - if (!n) - return !strcasecmp(list, "No_group"); - len = strlen(list); - m = strcasestr(n, list); - if (!m) - return false; - if ((m == n || m[-1] == ';' || m[-1] == ' ') && - (m[len] == 0 || m[len] == ';')) + if (!metric_or_groups) + return !strcasecmp(sought, "No_group"); + len = strlen(sought); + if (!strncasecmp(metric_or_groups, sought, len) && + (metric_or_groups[len] == 0 || metric_or_groups[len] == ';')) 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) |