From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Ian Rogers <irogers@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Yang Jihong <yangjihong1@huawei.com>,
James Clark <james.clark@arm.com>,
Ravi Bangoria <ravi.bangoria@amd.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 5/6] perf tools: Use pmus to describe type from attribute
Date: Thu, 7 Mar 2024 09:36:50 -0500 [thread overview]
Message-ID: <c22e0d67-cf63-4bb7-8cef-05fccc384214@linux.intel.com> (raw)
In-Reply-To: <20240307081412.3933750-6-irogers@google.com>
On 2024-03-07 3:14 a.m., Ian Rogers wrote:
> 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 cycles true
faults?
Thanks,
Kan
> ...
> 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>
> ---
> tools/perf/util/perf_event_attr_fprintf.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c
> index 8f04d3b7f3ec..29e66835da3a 100644
> --- a/tools/perf/util/perf_event_attr_fprintf.c
> +++ b/tools/perf/util/perf_event_attr_fprintf.c
> @@ -7,6 +7,8 @@
> #include <linux/types.h>
> #include <linux/perf_event.h>
> #include "util/evsel_fprintf.h"
> +#include "util/pmu.h"
> +#include "util/pmus.h"
> #include "trace-event.h"
>
> struct bit_names {
> @@ -75,9 +77,12 @@ static void __p_read_format(char *buf, size_t size, u64 value)
> }
>
> #define ENUM_ID_TO_STR_CASE(x) case x: return (#x);
> -static const char *stringify_perf_type_id(u64 value)
> +static const char *stringify_perf_type_id(struct perf_pmu *pmu, u32 type)
> {
> - switch (value) {
> + if (pmu)
> + return pmu->name;
> +
> + switch (type) {
> ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE)
> ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE)
> ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT)
> @@ -175,9 +180,9 @@ do { \
> #define print_id_unsigned(_s) PRINT_ID(_s, "%"PRIu64)
> #define print_id_hex(_s) PRINT_ID(_s, "%#"PRIx64)
>
> -static void __p_type_id(char *buf, size_t size, u64 value)
> +static void __p_type_id(struct perf_pmu *pmu, char *buf, size_t size, u64 value)
> {
> - print_id_unsigned(stringify_perf_type_id(value));
> + print_id_unsigned(stringify_perf_type_id(pmu, value));
> }
>
> 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)
> #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val)
> #define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val)
> #define p_read_format(val) __p_read_format(buf, BUF_SIZE, val)
> -#define p_type_id(val) __p_type_id(buf, BUF_SIZE, val)
> +#define p_type_id(val) __p_type_id(pmu, buf, BUF_SIZE, val)
> #define p_config_id(val) __p_config_id(buf, BUF_SIZE, attr->type, val)
>
> #define PRINT_ATTRn(_n, _f, _p, _a) \
> @@ -262,6 +267,7 @@ do { \
> int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
> attr__fprintf_f attr__fprintf, void *priv)
> {
> + struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type);
> char buf[BUF_SIZE];
> int ret = 0;
>
next prev parent reply other threads:[~2024-03-07 14:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 8:14 [PATCH v1 0/6] Extra verbose/perf-list details Ian Rogers
2024-03-07 8:14 ` [PATCH v1 1/6] perf list: Add tracepoint encoding to detailed output Ian Rogers
2024-03-07 8:14 ` [PATCH v1 2/6] perf pmu: Drop "default_core" from alias names Ian Rogers
2024-03-07 8:14 ` [PATCH v1 3/6] perf list: Allow wordwrap to wrap on commas Ian Rogers
2024-03-07 8:14 ` [PATCH v1 4/6] perf list: Give more details about raw event encodings Ian Rogers
2024-03-07 14:34 ` Liang, Kan
2024-03-07 16:41 ` Ian Rogers
2024-03-07 8:14 ` [PATCH v1 5/6] perf tools: Use pmus to describe type from attribute Ian Rogers
2024-03-07 14:36 ` Liang, Kan [this message]
2024-03-07 16:45 ` Ian Rogers
2024-03-07 8:14 ` [PATCH v1 6/6] perf tools: Add/use PMU reverse lookup from config to name Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c22e0d67-cf63-4bb7-8cef-05fccc384214@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=yangjihong1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).