[PATCH v1 4/5] perf evlist: Add groups to evlist__format_evsels

Ian Rogers
2025-03-18T04:14:57Z

Make groups visible in output:

Before:
{cycles,instructions} ->
cpu_atom/cycles/,cpu_atom/instructions/,cpu_core/cycles/,cpu_core/instructions/

After:
{cycles,instructions} ->
{cpu_atom/cycles/,cpu_atom/instructions/},{cpu_core/cycles/,cpu_core/instructions/}

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/evlist.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 96cfc7ed1512..b59fa407be44 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -2471,19 +2471,30 @@ struct evsel *evlist__find_evsel(struct evlist *evlist, int idx)

void evlist__format_evsels(struct evlist *evlist, struct strbuf *sb)
{
- struct evsel *evsel;
+ struct evsel *evsel, *leader = NULL;
bool first = true;

evlist__for_each_entry(evlist, evsel) {
+ struct evsel *new_leader = evsel__leader(evsel);
+
if (evsel__is_dummy_event(evsel))
continue;

+ if (leader != new_leader && leader && leader->core.nr_members > 1)
+ strbuf_addch(sb, '}');
+
if (!first)
strbuf_addch(sb, ',');

+ if (leader != new_leader && new_leader->core.nr_members > 1)
+ strbuf_addch(sb, '{');
+
strbuf_addstr(sb, evsel__name(evsel));
first = false;
+ leader = new_leader;
}
+ if (leader && leader->core.nr_members > 1)
+ strbuf_addch(sb, '}');
}

void evlist__check_mem_load_aux(struct evlist *evlist)
--
2.49.0.rc1.451.g8f38331e32-goog