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

Yushan Wang wangyushan12 at huawei.com
Wed May 6 23:37:32 PDT 2026


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 at 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 at 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 at huawei.com>
---
 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




More information about the linux-arm-kernel mailing list