From: Jiri Olsa <jolsa@redhat.com>
To: "Liang, Kan" <kan.liang@linux.intel.com>
Cc: linux-perf-users@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Joe Mario <jmario@redhat.com>, Andi Kleen <ak@linux.intel.com>,
Jin Yao <yao.jin@linux.intel.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: Re: problem with 'perf script -F weight'
Date: Wed, 29 Sep 2021 08:08:11 +0200 [thread overview]
Message-ID: <YVQCy2yEK00XbWAq@krava> (raw)
In-Reply-To: <732928be-f438-120f-7c9f-685630147495@linux.intel.com>
On Tue, Sep 28, 2021 at 05:35:51PM -0400, Liang, Kan wrote:
>
>
> On 9/28/2021 3:20 PM, Jiri Olsa wrote:
> > Joe reported broken -F weight in perf script with (on x86):
> >
> > # ./perf mem record
> > # ./perf script -F weight
> > Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot print 'weight' field.
> >
> > the problem seems to be introduced with the WEIGHT_STRUCT change:
> > ea8d0ed6eae3 perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT
> >
> > which enables WEIGHT_STRUCT sample_type on x86 instead of WEIGHT,
> > and leaves 'perf script -F weight' in the dark
>
> Right, I missed the support for the perf script. Because the default perf
> script worked. It didn't ring the bell. :(
>
> >
> > I'm not sure what the fix should look like.. should we allow user
> > to use just 'WEIGHT' sample type? or is there a way to get original
> > weight from 'WEIGHT_STRUCT' data, so we could fix just perf script?
>
> Just fix the perf script is enough.
> Could you please try the below patch?
>
> (I probably need to split the patch into two patches, since it fixed two
> issues, one is this error, the other is to print the instruction latency.
> Anyway, let's try it first.)
>
> From 99443f49a6236ef6e3bea3930792967a7863f753 Mon Sep 17 00:00:00 2001
> From: Kan Liang <kan.liang@linux.intel.com>
> Date: Tue, 28 Sep 2021 13:57:18 -0700
> Subject: [PATCH] perf script: Fix PERF_SAMPLE_WEIGHT_STRUCT support
>
> -F weight in perf script is broken.
>
> # ./perf mem record
> # ./perf script -F weight
> Samples for 'dummy:HG' event do not have WEIGHT attribute set. Cannot
> print 'weight' field.
>
> The sample type, PERF_SAMPLE_WEIGHT_STRUCT, is an alternative of the
> PERF_SAMPLE_WEIGHT sample type. They share the same space, weight. The
> lower 32 bits are exactly the same for both sample type. The higher 32
> bits may be different for different architecture. For a new kernel on
> x86, the PERF_SAMPLE_WEIGHT_STRUCT is used. For an old kernel or other
> ARCHs, the PERF_SAMPLE_WEIGHT is used.
>
> With -F weight, current perf script will check the input string "weight"
> with the corresponding sample type. However, the commit ID ea8d0ed6eae3
> ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT") didn't update the
> sample type for perf script. The check fails with a new kernel on x86.
>
> Use PERF_SAMPLE_WEIGHT_TYPE, which supports both sample types, to
> replace PERF_SAMPLE_WEIGHT.
>
> Also, print the instruction latency for PERF_SAMPLE_WEIGHT_STRUCT type.
>
> Reported-by: Joe Mario <jmario@redhat.com>
> Fixes: ea8d0ed6eae3 ("perf tools: Support PERF_SAMPLE_WEIGHT_STRUCT")
> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
> ---
> tools/perf/builtin-script.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 6211d0b..fd73bbc 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -459,7 +459,7 @@ static int evsel__check_attr(struct evsel *evsel, struct
> perf_session *session)
> return -EINVAL;
>
> if (PRINT_FIELD(WEIGHT) &&
> - evsel__check_stype(evsel, PERF_SAMPLE_WEIGHT, "WEIGHT",
> PERF_OUTPUT_WEIGHT))
> + evsel__check_stype(evsel, PERF_SAMPLE_WEIGHT_TYPE, "WEIGHT",
> PERF_OUTPUT_WEIGHT))
> return -EINVAL;
>
> if (PRINT_FIELD(SYM) &&
> @@ -2036,8 +2036,11 @@ static void process_event(struct perf_script *script,
> if (PRINT_FIELD(DATA_SRC))
> data_src__fprintf(sample->data_src, fp);
>
> - if (PRINT_FIELD(WEIGHT))
> + if (PRINT_FIELD(WEIGHT)) {
> fprintf(fp, "%16" PRIu64, sample->weight);
> + if (attr->sample_type & PERF_SAMPLE_WEIGHT_STRUCT)
> + fprintf(fp, ",0x%" PRIx16, sample->ins_lat);
this will add extra number to weight.. should we add separate column
for that -F 'insn-lat' ? users expect just single value for -F weight
thanks,
jirka
> + }
>
> if (PRINT_FIELD(IP)) {
> struct callchain_cursor *cursor = NULL;
> --
> 2.7.4
>
> Thanks,
> Kan
>
next prev parent reply other threads:[~2021-09-29 6:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-28 19:20 problem with 'perf script -F weight' Jiri Olsa
2021-09-28 20:38 ` Andi Kleen
2021-09-28 21:35 ` Liang, Kan
2021-09-29 6:08 ` Jiri Olsa [this message]
2021-09-29 15:13 ` Liang, Kan
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=YVQCy2yEK00XbWAq@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=jmario@redhat.com \
--cc=kan.liang@linux.intel.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=yao.jin@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.