Skip to content

Commit c788ef6

Browse files
captain5050acmel
authored andcommitted
perf metrics: Ensure at least 1 id per metric
We may have no events for a metric evaluated to a constant. In such a case ensure a tool event is at least evaluated for metric parsing and displaying. Fixes: 8586d27 ("perf metrics: Don't add all tool events for sharing") Signed-off-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.garry@huawei.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Link: https://lore.kernel.org/r/20220618013957.999321-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 37402d5 commit c788ef6

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

tools/perf/util/metricgroup.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
13721372

13731373
*out_evlist = NULL;
13741374
if (!metric_no_merge || hashmap__size(ids->ids) == 0) {
1375+
bool added_event = false;
13751376
int i;
13761377
/*
13771378
* We may fail to share events between metrics because a tool
@@ -1393,8 +1394,16 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
13931394
if (!tmp)
13941395
return -ENOMEM;
13951396
ids__insert(ids->ids, tmp);
1397+
added_event = true;
13961398
}
13971399
}
1400+
if (!added_event && hashmap__size(ids->ids) == 0) {
1401+
char *tmp = strdup("duration_time");
1402+
1403+
if (!tmp)
1404+
return -ENOMEM;
1405+
ids__insert(ids->ids, tmp);
1406+
}
13981407
}
13991408
ret = metricgroup__build_event_string(&events, ids, modifier,
14001409
has_constraint);

0 commit comments

Comments
 (0)