Skip to contentSkip to conversation

perf metrics: Ensure at least 1 id per metric

PATCH Applied Ian Rogers 2 participants 2 messages Jun 18, 2022 – Jun 19, 2022 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 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 8586d2744ff3 ("perf metrics: Don't add all tool events for sharing")
---
 tools/perf/util/metricgroup.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/util/metricgroup.c +9 -0
index ee8fcfa115e5..8f7baeabc5cf 100644
@@ -1372,6 +1372,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
 
 	*out_evlist = NULL;
 	if (!metric_no_merge || hashmap__size(ids->ids) == 0) {
+		bool added_event = false;
 		int i;
 		/*
 		 * 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,
 				if (!tmp)
 					return -ENOMEM;
 				ids__insert(ids->ids, tmp);
+				added_event = true;
 			}
 		}
+		if (!added_event && hashmap__size(ids->ids) == 0) {
+			char *tmp = strdup("duration_time");
+
+			if (!tmp)
+				return -ENOMEM;
+			ids__insert(ids->ids, tmp);
+		}
 	}
 	ret = metricgroup__build_event_string(&events, ids, modifier,
 					      has_constraint);
Signature · 1 line
2.37.0.rc0.104.g0611611a94-goog
maintainer Applied
#1 lore raw

Em Fri, Jun 17, 2022 at 06:39:57PM -0700, Ian Rogers escreveu:

Quoted 3 lines

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.

Thanks, applied.

- Arnaldo

Quoted 37 lines
Fixes 8586d2744ff3 ("perf metrics: Don't add all tool events for sharing")
---
 tools/perf/util/metricgroup.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/util/metricgroup.c +9 -0
index ee8fcfa115e5..8f7baeabc5cf 100644
@@ -1372,6 +1372,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
 
 	*out_evlist = NULL;
 	if (!metric_no_merge || hashmap__size(ids->ids) == 0) {
+		bool added_event = false;
 		int i;
 		/*
 		 * 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,
 				if (!tmp)
 					return -ENOMEM;
 				ids__insert(ids->ids, tmp);
+				added_event = true;
 			}
 		}
+		if (!added_event && hashmap__size(ids->ids) == 0) {
+			char *tmp = strdup("duration_time");
+
+			if (!tmp)
+				return -ENOMEM;
+			ids__insert(ids->ids, tmp);
+		}
 	}
 	ret = metricgroup__build_event_string(&events, ids, modifier,
 					      has_constraint);
Signature · 1 line
2.37.0.rc0.104.g0611611a94-goog
Signature · 1 line
- Arnaldo