diff mbox series

[RFC,8/9] perf metrics: Stop metricgroup__add_metric_sys_event_iter if already matched

Message ID 20230628102949.2598096-9-john.g.garry@oracle.com (mailing list archive)
State New, archived
Headers show
Series perf tool: sys event metric support re-write | expand

Commit Message

John Garry June 28, 2023, 10:29 a.m. UTC
Functions like pmu_for_each_sys_event() may be inefficient, as we only
stop itering for an error. Often when itering, we may want to stop early
as we already found what we're looking for.

Return 1 in metricgroup__add_metric_sys_event_iter() when we want to stop.
Nobody checks the error code from callers anyway - those are
pmu_metrics_table_for_each_metric() ->
metricgroup__add_metric_sys_event_iter() and pmu_for_each_sys_metric() ->
metricgroup__sys_event_iter() -> metricgroup__add_metric_sys_event_iter().

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 tools/perf/util/metricgroup.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 111ad4e3eb6b..c045b111db84 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1130,7 +1130,12 @@  static int metricgroup__add_metric_sys_event_iter(const struct pmu_metric *pm,
 
 out:
 	*(d->ret) = ret;
-	return ret;
+	/*
+	 * Return 1 as we don't want to iter any more, as either:
+	 * a. We found a match
+	 * b. We tried to add a metric, which errored
+	 */
+	return 1;
 }
 
 /**