Re: [PATCH 1/4] libperf evlist: Update group info in perf_evlist__remove()

From: Ian Rogers
Date: Wed Feb 14 2024 - 18:50:38 EST


On Mon, Feb 12, 2024 at 11:52 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> 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>

Should we worry about evlist's all_cpus that could also be stale now?

Thanks,
Ian

> ---
> 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
>