linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf metrics: Ensure at least 1 id per metric
@ 2022-06-18  1:39 Ian Rogers
  2022-06-19 14:24 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2022-06-18  1:39 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Andi Kleen, John Garry, Zhengjun Xing, linux-perf-users,
	linux-kernel
  Cc: Stephane Eranian, Ian Rogers

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")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/metricgroup.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index ee8fcfa115e5..8f7baeabc5cf 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -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);
-- 
2.37.0.rc0.104.g0611611a94-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf metrics: Ensure at least 1 id per metric
  2022-06-18  1:39 [PATCH] perf metrics: Ensure at least 1 id per metric Ian Rogers
@ 2022-06-19 14:24 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-06-19 14:24 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Andi Kleen, John Garry, Zhengjun Xing,
	linux-perf-users, linux-kernel, Stephane Eranian

Em Fri, Jun 17, 2022 at 06:39:57PM -0700, Ian Rogers escreveu:
> 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

 
> Fixes: 8586d2744ff3 ("perf metrics: Don't add all tool events for sharing")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/metricgroup.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index ee8fcfa115e5..8f7baeabc5cf 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -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);
> -- 
> 2.37.0.rc0.104.g0611611a94-goog

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-19 14:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-18  1:39 [PATCH] perf metrics: Ensure at least 1 id per metric Ian Rogers
2022-06-19 14:24 ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).