[PATCH 1/4] libperf evlist: Update group info in perf_evlist__remove()
From: Namhyung Kim
Date: Tue Feb 13 2024 - 02:53:24 EST
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@xxxxxxxxxx>
---
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