Re: [RFT PATCH v2 2/7] perf stat: Save unnecessary print_metric() call

From: Ian Rogers

Date: Thu May 07 2026 - 11:35:20 EST


On Wed, May 6, 2026 at 11:37 PM Yushan Wang <wangyushan12@xxxxxxxxxx> wrote:
>
> The patch listed under Fixes removed the other branch of iostat_run, and
> changed num to 0 since it is the default behavior of it. But during
> iostat_run, default value 1 of num is required to avoid print_metric()
> call later.
>
> Set num as 1 to avoid redundant print_metric() call that causes
> unaligned blank printed.
>
> Before this patch:
>
> root@localhost$ ./perf stat --iostat=0000:20:0f.0 --timeout 100
>
> Performance counter stats for 'system wide':
>
> port Inbound MWR(MB) Inbound MRD(MB) Inbound CPL(MB) Outbound MWR(MB) Outbound MRD(MB) Outbound CPL(MB)
> 0000:20:0f.0 0.00 0.00 0.00 0.00 0.00
> 0.01
>
> 0.100138030 seconds time elapsed
>
> After this patch:
>
> root@localhost$ ./perf stat --iostat=0000:20:0f.0 --timeout 100
>
> Performance counter stats for 'system wide':
>
> port Inbound MWR(MB) Inbound MRD(MB) Inbound CPL(MB) Outbound MWR(MB) Outbound MRD(MB) Outbound CPL(MB)
> 0000:20:0f.0 0.00 0.00 0.00 0.00 0.00 0.01
>
> 0.100127590 seconds time elapsed
>
> Fixes: b71f46a6a708 ("perf stat: Remove hard coded shadow metrics")
> Signed-off-by: Yushan Wang <wangyushan12@xxxxxxxxxx>

Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>

Thanks,
Ian

> ---
> tools/perf/util/stat-shadow.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
> index bc2d44df7baf..0056444523d6 100644
> --- a/tools/perf/util/stat-shadow.c
> +++ b/tools/perf/util/stat-shadow.c
> @@ -326,8 +326,10 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,
> void *ctxp = out->ctx;
> int num = 0;
>
> - if (config->iostat_run)
> + if (config->iostat_run) {
> iostat_print_metric(config, evsel, out);
> + num = 1;
> + }
>
> perf_stat__print_shadow_stats_metricgroup(config, evsel, aggr_idx,
> &num, NULL, out);
> --
> 2.33.0
>