[PATCH v2 00/10] Better fixes for grouping of events

From: Ian Rogers
Date: Thu Mar 02 2023 - 17:22:16 EST


The rules for grouping events has grown more complex. Topdown events
must be grouped, but flags like --metric-no-group and flags on metrics
don't respect this. Uncore events may be expanded using wild cards for
PMU names, but then the events need reordering so the group members
are adjacent. Rather than fixing metrics, this change fixes the main
event parsing code to first sort and then regroup evsels.

As this is shared functionality changes to it should cause
concern. The change is done with the intent of simplifying and making
more robust the grouping logic, examples are given. If additional
changes are necessary, they are most likely necessary to the
evsel__pmu_name logic as the code avoids breaking groups that are on
the same PMU. The pmu_name is tweaked in the case of software and aux
events, that use groups in a slightly different manner to conventional
events.

The code was manually tested as well as passing perf test on a Intel
tigerlake CPU with intel-pt.

v2. Fix up the commit message on 4/10 (thanks Arnaldo). Drop
unnecessary v1 5/10 (thanks Kan). evlist->core.nr_groups wasn't
being correctly maintained after the sort/regrouping and so the
new patch 10/10 removes that variable and computes it from the
evlist when necessary, generally just tests.

Ian Rogers (10):
libperf evlist: Avoid a use of evsel idx
perf stat: Don't remove all grouped events when CPU maps disagree
perf record: Early auxtrace initialization before event parsing
perf stat: Modify the group test
perf evsel: Allow const evsel for certain accesses
perf evsel: Add function to compute pmu_name
perf parse-events: Pass ownership of the group name
perf parse-events: Sort and group parsed events
perf evsel: Remove use_uncore_alias
perf evlist: Remove nr_groups

tools/lib/perf/evlist.c | 31 ++-
tools/lib/perf/include/internal/evlist.h | 1 -
tools/lib/perf/include/perf/evlist.h | 1 +
tools/perf/arch/x86/util/auxtrace.c | 17 +-
tools/perf/arch/x86/util/evlist.c | 39 ++--
tools/perf/builtin-record.c | 8 +-
tools/perf/builtin-report.c | 2 +-
tools/perf/builtin-stat.c | 24 ++-
tools/perf/tests/bpf.c | 1 -
tools/perf/tests/parse-events.c | 22 +-
tools/perf/tests/pfm.c | 12 +-
tools/perf/util/auxtrace.h | 2 +
tools/perf/util/evlist.c | 2 +-
tools/perf/util/evlist.h | 8 +-
tools/perf/util/evsel.c | 27 ++-
tools/perf/util/evsel.h | 8 +-
tools/perf/util/header.c | 3 +-
tools/perf/util/parse-events.c | 254 +++++++++++------------
tools/perf/util/parse-events.h | 7 +-
tools/perf/util/parse-events.y | 27 +--
tools/perf/util/pfm.c | 1 -
tools/perf/util/pmu.c | 6 +-
tools/perf/util/python.c | 2 +-
tools/perf/util/stat-shadow.c | 2 +-
24 files changed, 270 insertions(+), 237 deletions(-)

--
2.40.0.rc0.216.gc4246ad0f0-goog