perf evsel: Add function to compute group PMU name
authorIan Rogers <irogers@google.com>
Sun, 12 Mar 2023 02:15:38 +0000 (18:15 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 13 Mar 2023 20:42:02 +0000 (17:42 -0300)
The computed 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.

Committer notes:

Added a stub for this new function so that 'perf test python' passes.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20230312021543.3060328-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/python.c

index 798f072..3dda8a2 100644 (file)
@@ -821,6 +821,30 @@ out_unknown:
        return "unknown";
 }
 
+const char *evsel__group_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)
index 676c499..d26745c 100644 (file)
@@ -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__group_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)
index ab48ffb..be336f1 100644 (file)
@@ -93,6 +93,11 @@ int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
        return EOF;
 }
 
+bool evsel__is_aux_event(const struct evsel *evsel __maybe_unused)
+{
+       return false;
+}
+
 /*
  * Add this one here not to drag util/metricgroup.c
  */