[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240213075256.1983638-2-namhyung@kernel.org>
Date: Mon, 12 Feb 2024 23:52:53 -0800
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>,
Ian Rogers <irogers@...gle.com>
Cc: Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
linux-perf-users@...r.kernel.org
Subject: [PATCH 1/4] libperf evlist: Update group info in perf_evlist__remove()
When an event in a group is removed, it should update the group status
including the pointer to leader and number of member events.
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
tools/lib/perf/evlist.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c
index 058e3ff10f9b..befdb062fa1d 100644
--- a/tools/lib/perf/evlist.c
+++ b/tools/lib/perf/evlist.c
@@ -102,8 +102,29 @@ void perf_evlist__add(struct perf_evlist *evlist,
void perf_evlist__remove(struct perf_evlist *evlist,
struct perf_evsel *evsel)
{
+ struct perf_evsel *leader = evsel->leader;
+
list_del_init(&evsel->node);
evlist->nr_entries -= 1;
+
+ /* return stand-alone event */
+ if (leader == evsel && leader->nr_members < 2)
+ return;
+
+ if (leader == evsel) {
+ struct perf_evsel *member;
+
+ /* select the next event as a new leader */
+ leader = member = perf_evlist__next(evlist, evsel);
+
+ /* update members to see the new leader */
+ while (member && member->leader == evsel) {
+ member->leader = leader;
+ member = perf_evlist__next(evlist, member);
+ }
+ }
+
+ leader->nr_members = evsel->leader->nr_members - 1;
}
struct perf_evlist *perf_evlist__new(void)
--
2.43.0.687.g38aa6559b0-goog
Powered by blists - more mailing lists