Skip to content

Commit 7093882

Browse files
captain5050acmel
authored andcommitted
perf tools: Use pmus to describe type from attribute
When dumping a perf_event_attr, use pmus to find the PMU and its name by the type number. This allows dynamically added PMUs to be described. Before: $ perf stat -vv -e data_read true ... perf_event_attr: type 24 size 136 config 0x20ff sample_type IDENTIFIER read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING disabled 1 inherit 1 exclude_guest 1 ... After: $ perf stat -vv -e data_read true ... perf_event_attr: type 24 (uncore_imc_free_running_0) size 136 config 0x20ff sample_type IDENTIFIER read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING disabled 1 inherit 1 exclude_guest 1 ... However, it also means that when we have a PMU name we prefer it to a hard coded name: Before: $ perf stat -vv -e faults true ... perf_event_attr: type 1 (PERF_TYPE_SOFTWARE) size 136 config 0x2 (PERF_COUNT_SW_PAGE_FAULTS) sample_type IDENTIFIER read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING disabled 1 inherit 1 enable_on_exec 1 exclude_guest 1 ... After: $ perf stat -vv -e faults true ... perf_event_attr: type 1 (software) size 136 config 0x2 (PERF_COUNT_SW_PAGE_FAULTS) sample_type IDENTIFIER read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING disabled 1 inherit 1 enable_on_exec 1 exclude_guest 1 ... It feels more consistent to do this, rather than only prefer a PMU name when a hard coded name isn't available. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Kan Liang <kan.liang@linux.intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.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: Yang Jihong <yangjihong1@huawei.com> Link: https://lore.kernel.org/r/20240308001915.4060155-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 4ccf3bb commit 7093882

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tools/perf/util/perf_event_attr_fprintf.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/types.h>
88
#include <linux/perf_event.h>
99
#include "util/evsel_fprintf.h"
10+
#include "util/pmu.h"
11+
#include "util/pmus.h"
1012
#include "trace-event.h"
1113

1214
struct bit_names {
@@ -75,9 +77,12 @@ static void __p_read_format(char *buf, size_t size, u64 value)
7577
}
7678

7779
#define ENUM_ID_TO_STR_CASE(x) case x: return (#x);
78-
static const char *stringify_perf_type_id(u64 value)
80+
static const char *stringify_perf_type_id(struct perf_pmu *pmu, u32 type)
7981
{
80-
switch (value) {
82+
if (pmu)
83+
return pmu->name;
84+
85+
switch (type) {
8186
ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE)
8287
ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE)
8388
ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT)
@@ -175,9 +180,9 @@ do { \
175180
#define print_id_unsigned(_s) PRINT_ID(_s, "%"PRIu64)
176181
#define print_id_hex(_s) PRINT_ID(_s, "%#"PRIx64)
177182

178-
static void __p_type_id(char *buf, size_t size, u64 value)
183+
static void __p_type_id(struct perf_pmu *pmu, char *buf, size_t size, u64 value)
179184
{
180-
print_id_unsigned(stringify_perf_type_id(value));
185+
print_id_unsigned(stringify_perf_type_id(pmu, value));
181186
}
182187

183188
static void __p_config_hw_id(char *buf, size_t size, u64 value)
@@ -246,7 +251,7 @@ static void __p_config_id(char *buf, size_t size, u32 type, u64 value)
246251
#define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val)
247252
#define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val)
248253
#define p_read_format(val) __p_read_format(buf, BUF_SIZE, val)
249-
#define p_type_id(val) __p_type_id(buf, BUF_SIZE, val)
254+
#define p_type_id(val) __p_type_id(pmu, buf, BUF_SIZE, val)
250255
#define p_config_id(val) __p_config_id(buf, BUF_SIZE, attr->type, val)
251256

252257
#define PRINT_ATTRn(_n, _f, _p, _a) \
@@ -262,6 +267,7 @@ do { \
262267
int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
263268
attr__fprintf_f attr__fprintf, void *priv)
264269
{
270+
struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type);
265271
char buf[BUF_SIZE];
266272
int ret = 0;
267273

0 commit comments

Comments
 (0)