Re: [PATCH v1 07/10] perf evsel: Add function to compute pmu_name

From: Ian Rogers
Date: Thu Mar 02 2023 - 11:13:33 EST


On Thu, Mar 2, 2023 at 6:39 AM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
>
> Em Wed, Mar 01, 2023 at 08:12:08PM -0800, Ian Rogers escreveu:
> > The computed pmu_name respects software events and aux event groups,
> > such that the pmu_name is changed to be that of the aux event leader
> > or group leader for software events. This is done as a later change
> > will split events that are in different PMUs into different groups.
>
> Adrian, can you please take a look and provide an Ack or Reviewed-by?
>
> - Arnaldo

Adrian's input would be greatly appreciated! The handling of aux
events/grouping was done to make sure the "Miscellaneous Intel PT
testing" was passing, so there is some confidence it is correct :-)

Thanks,
Ian

> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
> > tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++
> > tools/perf/util/evsel.h | 1 +
> > 2 files changed, 25 insertions(+)
> >
> > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> > index 2dc2c24252bb..9c6b486f8bd4 100644
> > --- a/tools/perf/util/evsel.c
> > +++ b/tools/perf/util/evsel.c
> > @@ -821,6 +821,30 @@ const char *evsel__name(struct evsel *evsel)
> > return "unknown";
> > }
> >
> > +const char *evsel__pmu_name(const struct evsel *evsel)
> > +{
> > + const struct evsel *leader;
> > +
> > + /* If the pmu_name is set use it. pmu_name isn't set for CPU and software events. */
> > + if (evsel->pmu_name)
> > + return evsel->pmu_name;
> > + /*
> > + * Software events may be in a group with other uncore PMU events. Use
> > + * the pmu_name of the group leader to avoid breaking the software event
> > + * out of the group.
> > + *
> > + * Aux event leaders, like intel_pt, expect a group with events from
> > + * other PMUs, so substitute the AUX event's PMU in this case.
> > + */
> > + leader = evsel__leader(evsel);
> > + if ((evsel->core.attr.type == PERF_TYPE_SOFTWARE || evsel__is_aux_event(leader)) &&
> > + leader->pmu_name) {
> > + return leader->pmu_name;
> > + }
> > +
> > + return "cpu";
> > +}
> > +
> > const char *evsel__metric_id(const struct evsel *evsel)
> > {
> > if (evsel->metric_id)
> > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> > index 676c499323e9..72121194d3b1 100644
> > --- a/tools/perf/util/evsel.h
> > +++ b/tools/perf/util/evsel.h
> > @@ -280,6 +280,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size);
> >
> > int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size);
> > const char *evsel__name(struct evsel *evsel);
> > +const char *evsel__pmu_name(const struct evsel *evsel);
> > const char *evsel__metric_id(const struct evsel *evsel);
> >
> > static inline bool evsel__is_tool(const struct evsel *evsel)
> > --
> > 2.39.2.722.g9855ee24e9-goog
> >
>
> --
>
> - Arnaldo