[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230925061824.3818631-14-weilin.wang@intel.com>
Date: Sun, 24 Sep 2023 23:18:12 -0700
From: weilin.wang@...el.com
To: weilin.wang@...el.com, Ian Rogers <irogers@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>
Cc: linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
Perry Taylor <perry.taylor@...el.com>,
Samantha Alt <samantha.alt@...el.com>,
Caleb Biggers <caleb.biggers@...el.com>,
Mark Rutland <mark.rutland@....com>
Subject: [RFC PATCH 13/25] perf stat: Add functions to hardware-grouping method
From: Weilin Wang <weilin.wang@...el.com>
Add functions to free all the group lists before exit metric grouping
Signed-off-by: Weilin Wang <weilin.wang@...el.com>
---
tools/perf/util/metricgroup.c | 39 ++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 8d54e71bf..4b1b0470d 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1528,6 +1528,38 @@ static int parse_counter(const char *counter,
return 0;
}
+static void group_event_list_free(struct metricgroup__group *groups)
+{
+ struct metricgroup__group_events *e, *tmp;
+
+ list_for_each_entry_safe (e, tmp, &groups->event_head, nd) {
+ list_del_init(&e->nd);
+ free(e);
+ }
+}
+
+static void group_list_free(struct metricgroup__pmu_group_list *groups)
+{
+ struct metricgroup__group *g, *tmp;
+
+ list_for_each_entry_safe (g, tmp, &groups->group_head, nd) {
+ list_del_init(&g->nd);
+ group_event_list_free(g);
+ free(g);
+ }
+}
+
+static void metricgroup__free_group_list(struct list_head *groups)
+{
+ struct metricgroup__pmu_group_list *g, *tmp;
+
+ list_for_each_entry_safe (g, tmp, groups, nd) {
+ list_del_init(&g->nd);
+ group_list_free(g);
+ free(g);
+ }
+}
+
static void metricgroup__free_event_info(struct list_head
*event_info_list)
{
@@ -1845,6 +1877,8 @@ static int assign_event_grouping(struct metricgroup__event_info *e,
struct metricgroup__pmu_counters *p;
pmu_group_head = malloc(sizeof(struct metricgroup__pmu_group_list));
+ if (!pmu_group_head)
+ return -ENOMEM;
INIT_LIST_HEAD(&pmu_group_head->group_head);
pr_debug("create new group for event %s in pmu %s\n", e->name, e->pmu_name);
pmu_group_head->pmu_name = e->pmu_name;
@@ -1886,8 +1920,11 @@ static int create_grouping(struct list_head *pmu_info_list,
pr_debug("Event name %s, [pmu]=%s, [counters]=%s\n", e->name,
e->pmu_name, bit_buf);
ret = assign_event_grouping(e, pmu_info_list, &groups);
+ if (ret)
+ goto out;
}
-
+out:
+ metricgroup__free_group_list(&groups);
return ret;
};
--
2.39.3
Powered by blists - more mailing lists