]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf metricgroup: Refine error logs
authorLeo Yan <leo.yan@arm.com>
Thu, 2 Apr 2026 16:04:49 +0000 (17:04 +0100)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 3 Apr 2026 01:11:00 +0000 (18:11 -0700)
Return -ENOENT when no metric/group matches, and directly use the return
value from expr__find_ids(), so -EINVAL is reserved for parse failures.

Print separate logs to make it clear.

Before:

  perf stat -C 5 -vvv
  Using CPUID 0x00000000410fd490
  metric expr 100 * (STALL_SLOT_BACKEND / (CPU_CYCLES * #slots) - BR_MIS_PRED * 3 / CPU_CYCLES) for backend_bound
  parsing metric: 100 * (STALL_SLOT_BACKEND / (CPU_CYCLES * #slots) - BR_MIS_PRED * 3 / CPU_CYCLES)
  Failure to read '#slots'
  literal: #slots = nan
  syntax error
  Cannot find metric or group `Default'

After:

  perf stat -C 5 -vvv
  Using CPUID 0x00000000410fd490
  metric expr 100 * (STALL_SLOT_BACKEND / (CPU_CYCLES * #slots) - BR_MIS_PRED * 3 / CPU_CYCLES) for backend_bound
  parsing metric: 100 * (STALL_SLOT_BACKEND / (CPU_CYCLES * #slots) - BR_MIS_PRED * 3 / CPU_CYCLES)
  Failure to read '#slots'
  literal: #slots = nan
  syntax error
  Fail to parse metric or group `Default'

Signed-off-by: Leo Yan <leo.yan@arm.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/metricgroup.c

index f7d53b4e46f45cb01181a462cb5bb5ca5a3b1a9c..4db9578efd811cf91d192cc13fb757cf5aab21f7 100644 (file)
@@ -914,10 +914,9 @@ static int __add_metric(struct list_head *metric_list,
                expr = metric_no_threshold ? pm->metric_name : pm->metric_threshold;
                visited_node.name = "__threshold__";
        }
-       if (expr__find_ids(expr, NULL, root_metric->pctx) < 0) {
-               /* Broken metric. */
-               ret = -EINVAL;
-       }
+
+       ret = expr__find_ids(expr, NULL, root_metric->pctx);
+
        if (!ret) {
                /* Resolve referenced metrics. */
                struct perf_pmu *pmu;
@@ -1101,7 +1100,7 @@ static int metricgroup__add_metric(const char *pmu, const char *metric_name, con
         */
        ret = metricgroup__for_each_metric(table, metricgroup__add_metric_callback, &data);
        if (!ret && !data.has_match)
-               ret = -EINVAL;
+               ret = -ENOENT;
 
        /*
         * add to metric_list so that they can be released
@@ -1152,6 +1151,8 @@ static int metricgroup__add_metric_list(const char *pmu, const char *list,
                                              user_requested_cpu_list,
                                              system_wide, metric_list, table);
                if (ret == -EINVAL)
+                       pr_err("Fail to parse metric or group `%s'\n", metric_name);
+               else if (ret == -ENOENT)
                        pr_err("Cannot find metric or group `%s'\n", metric_name);
 
                if (ret)