From: Artem Savkov <asavkov@redhat.com>
To: Andi Kleen <ak@linux.intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/2] perf script: Fix perf script -F +metric
Date: Wed, 26 Jun 2024 11:09:24 +0200 [thread overview]
Message-ID: <20240626090924.GA56952@alecto.usersys.redhat.com> (raw)
In-Reply-To: <20240625004232.1852705-1-ak@linux.intel.com>
On Mon, Jun 24, 2024 at 05:42:31PM -0700, Andi Kleen wrote:
> This fixes a regression with perf script -F +metric originally caused by :
>
> commit 37cc8ad77cf81f3ffd226856c367b0e15333a738
> Author: Ian Rogers <irogers@google.com>
> Date: Sun Feb 19 01:28:46 2023 -0800
>
> perf metric: Directly use counts rather than saved_value
>
> In the perf script environment the evsel wouldn't allocate an aggr
> values array, which led to a -1 reference because the metric
> evaluation would try to reference NULL - 1 (for aggr_idx)
>
> Give the perf script evsels a single CPU aggr setup. That's
> enough because the groups are always contiguous, so no need
> to store more than one CPU's worth of values.
>
> Before
>
> % perf record -e '{cycles,instructions}:S' perf bench mem memcpy
> % perf script -F +metric
> Segmentation fault (core dumped)
>
> After:
>
> % perf record -e '{cycles,instructions}:S' perf bench mem memcpy
> ...
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.028 MB perf.data (90 samples) ]
> % perf script -F +metric
> perf-exec 1847557 264658.180789: 3009 cycles: ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
> perf-exec 1847557 264658.180789: 382 instructions: ffffffff990a579a native_write_msr+0xa ([kernel.kallsyms])
> perf-exec 1847557 264658.180789: metric: 0.13 insn per cycle
> ...
>
> Fixes: 37cc8ad77cf8 ("perf metric: Directly use counts rather ...")
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
This works, however there seems to be yet another issue on
perf-tools-next branch that breaks script metrics.
617824a7f0f73 (perf parse-events: Prefer sysfs/JSON hardware
events over legacy, 2024-04-15) changes event priority so on
my host "instructions" have type PERF_TYPE_RAW instead of
PERF_TYPE_HARDWARE.
# event : name = instructions, , id = { 190969, 190970, 190971, 190972, 190973, 190974, 190975, 190976 }, type = 4 (cpu), size = 136, config = 0xc0 (instructions), sample_type = IP|TID|TIME|READ|CPU|PERIOD|IDENTIFIER, read_format = ID|GROUP|LOST, sample_id_all = 1, exclude_guest = 1
This results in evsel__stat_type no longer recognizing these as
STAT_INSTRUCTIONS.
> ---
> tools/perf/builtin-script.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index c16224b1fef3..4aab194b4b1a 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -84,7 +84,7 @@ static bool system_wide;
> static bool print_flags;
> static const char *cpu_list;
> static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
> -static struct perf_stat_config stat_config;
> +static struct perf_stat_config stat_config = { .aggr_map = &(struct cpu_aggr_map){ .nr = 1 } };
> static int max_blocks;
> static bool native_arch;
> static struct dlfilter *dlfilter;
> @@ -2133,12 +2133,14 @@ static void perf_sample__fprint_metric(struct perf_script *script,
> if (evsel_script(leader)->gnum++ == 0)
> perf_stat__reset_shadow_stats();
> val = sample->period * evsel->scale;
> + /* Always use CPU 0 storage because the groups are contiguous. */
> + evsel->stats->aggr[0].counts.val = val;
> evsel_script(evsel)->val = val;
> if (evsel_script(leader)->gnum == leader->core.nr_members) {
> for_each_group_member (ev2, leader) {
> perf_stat__print_shadow_stats(&stat_config, ev2,
> evsel_script(ev2)->val,
> - sample->cpu,
> + 0,
> &ctx,
> NULL);
> }
> --
> 2.45.2
>
--
Artem
next prev parent reply other threads:[~2024-06-26 9:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 0:42 [PATCH 1/2] perf script: Fix perf script -F +metric Andi Kleen
2024-06-25 0:42 ` [PATCH 2/2] Add a test case for " Andi Kleen
2024-06-27 22:54 ` Namhyung Kim
2024-06-26 9:09 ` Artem Savkov [this message]
2024-06-27 22:50 ` [PATCH 1/2] perf script: Fix " Namhyung Kim
2024-06-28 19:19 ` Andi Kleen
2024-07-01 7:04 ` Artem Savkov
2024-07-01 16:54 ` Andi Kleen
2024-06-27 22:46 ` Namhyung Kim
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=20240626090924.GA56952@alecto.usersys.redhat.com \
--to=asavkov@redhat.com \
--cc=ak@linux.intel.com \
--cc=linux-perf-users@vger.kernel.org \
/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).