From nobody Thu Dec 18 08:34:53 2025 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 580EA2FFF94 for ; Tue, 9 Dec 2025 17:36:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765301782; cv=none; b=KCjlDRO9xLvXHi5FT1Z5Dt/L95L2HgHgJhGeRydmBJcrDaGLtlWDh/4N5BHMr61A6j/xq6tckVaL1kZliZE5h1Gc/73yV972nz9wVrPFMmBvBv+PfsQnn6PcBcodkTcCsYVB3wyGWD3mTtlAvTI008zcs/407ZqlsmodrZoAFbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765301782; c=relaxed/simple; bh=2J4VNMTx7hncImwcZzxIKLa0er9axnz0Fzr3Wf9tUQk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=AkTSnd8pXeQlMm9GF4r5g63kD0xm9VR21Xyk4Gp8iAPKu9UdGLO7EyEw7j5wqOsZNru52bs3pK+SxadOptYVmS7l2U9RYLKr6bVVQaTv2cATtEVuBFTQgf2q9PYrNrNFKeN/31YsPtNYxbGzor7RStYwnP4YOCvZxtjSnGCeaUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AU153jSo; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AU153jSo" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-11bd7a827fdso81788c88.1 for ; Tue, 09 Dec 2025 09:36:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765301780; x=1765906580; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=MHFT62zcP+uzBhJJkYNqwWKNM/LVKwF9++8ZaNQtnLE=; b=AU153jSoN/p8I8+iSdJzCL7j1hxo8jRbeIIa6ZMp0XCn6Y8ukxk8pcP0NjATIXZH28 r9KuoYvzDlS7yxHaYwcvp7BcyjyxBkILnMg/cShMVDfSAJ6TkVKC1nDA2UArGsNWScET l4UYEdE5+/v14NEfRTp2+NEn3Yu5sRkL6JuH10SmoSoegGGrL50O5NvkRUKyL4Sytyev XFxjaJKJVRuW0dxCLa2Rvm3oO/wiNIcNpnmJqMWYchZvQb9jEQK4kYz/ZJcWi5VZo23g G9HL0DResKGo8vM3cclkFyRZEH8Ck5KXIp5AAeH9cfREFWK0Y9jtDjoLFSQf2Fe9OQbQ QEVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765301780; x=1765906580; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MHFT62zcP+uzBhJJkYNqwWKNM/LVKwF9++8ZaNQtnLE=; b=UtZKcTGCg+QS++9A6/trg3WemtMnuhs0uicC/cIwkjwSCy5XhRhgE7RBwK4Q6V2tSn KxyddYC3tNL1vRSJHJnZD4OKBGDEKuzd/DK0JaLXAlbvGXWVT1I6dtRRo3n94baVokM2 CJmqwSFZXfBuN1ctrDTCDU9+i9N8Zjc0OM2r79IFi3qI+Zx+9aQBNzqqqqQhOsGDnzIr BC44/PUJonlFG1lxeTFUkN/nR28i/Ay2gtuD/5Btz41EULLhgkLiOTw347j634LjrTU0 UvqKdWCpAneRk8ufGK3Ax0u7g0ypfG2YQcgkDXRrpwKUXhemRT+W+GXldNPJ+LMRIoWD stMw== X-Forwarded-Encrypted: i=1; AJvYcCVxATtibVw50TA6XFAWo4sq0Vumsp7e6FwsoshI2AtNtFxpMbxbC8l+TzRleBGf4KOWbKycbbApXhQSoRU=@vger.kernel.org X-Gm-Message-State: AOJu0YwTEFstD0nESvyCpwh0OdRTOFn6SYfLmOO345NOk1tGxSmVVeph FyxglzLLpoa1rhRhWTRIpImWA1f5TDNzD+Fk1yGaPSrkQCjqO6q8cAjUPfEKtFq3RBoX+2AQcMW 1BbFicWIYeg== X-Google-Smtp-Source: AGHT+IGH5qKcGCeDOkGypUsW1qg77Dqskx2nxip9KgH11cgR6u1rp1/Lii/alrmJCzILGhU3Cy+RFpDcAbIx X-Received: from dlbeg42.prod.google.com ([2002:a05:7022:faa:b0:119:49ca:6ba0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:98c:b0:11b:9b9f:427c with SMTP id a92af1059eb24-11f251c3934mr1393470c88.13.1765301780303; Tue, 09 Dec 2025 09:36:20 -0800 (PST) Date: Tue, 9 Dec 2025 09:36:10 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251209173610.2033973-1-irogers@google.com> Subject: [PATCH v1] perf stat display: Make %f precision consistent From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Chun-Tse Shao , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ingo Molnar Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit bc22de9bcdb2 ("perf stat: Display time in precision based on std deviation") added multirun workload elapsed time. There was an effort to make the precision in the output most useful for the user, however, when gathering over runs it means the formatting varies. This change just makes the output format fixed. Before: ``` $ while :; do perf stat --null --repeat 3 sleep 0.1 2>&1 | grep elapsed; do= ne 0.101140 +- 0.000149 seconds time elapsed ( +- 0.15% ) 0.1011396 +- 0.0000218 seconds time elapsed ( +- 0.02% ) 0.101331 +- 0.000124 seconds time elapsed ( +- 0.12% ) ^C $ while :; do perf stat --null --repeat 3 sleep 1 2>&1 | grep elapsed; done 1.001317 +- 0.000146 seconds time elapsed ( +- 0.01% ) 1.001377 +- 0.000172 seconds time elapsed ( +- 0.02% ) 1.00253 +- 0.00131 seconds time elapsed ( +- 0.13% ) ``` After: ``` $ while :; do perf stat --null --repeat 3 sleep 0.1 2>&1 | grep elapsed; do= ne 0.101406408 +- 0.000064778 seconds time elapsed ( +- 0.06% ) 0.101367315 +- 0.000027253 seconds time elapsed ( +- 0.03% ) 0.101434164 +- 0.000084750 seconds time elapsed ( +- 0.08% ) ^C $ while :; do perf stat --null --repeat 3 sleep 1 2>&1 | grep elapsed; done 1.001525467 +- 0.000051703 seconds time elapsed ( +- 0.01% ) 1.001375093 +- 0.000116200 seconds time elapsed ( +- 0.01% ) 1.001141025 +- 0.000046361 seconds time elapsed ( +- 0.00% ) ``` Suggested-by: Ingo Molnar Closes: https://lore.kernel.org/lkml/aTQRgAOpKyI53TEq@gmail.com/ Signed-off-by: Ian Rogers Tested-by: Ingo Molnar --- tools/perf/util/stat-display.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 6d02f84c5691..2ce0602974a1 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1397,21 +1397,12 @@ static void print_header(struct perf_stat_config *c= onfig, num_print_iv =3D 0; } =20 -static int get_precision(double num) -{ - if (num > 1) - return 0; - - return lround(ceil(-log10(num))); -} - -static void print_table(struct perf_stat_config *config, - FILE *output, int precision, double avg) +static void print_table(struct perf_stat_config *config, FILE *output, dou= ble avg) { char tmp[64]; int idx, indent =3D 0; =20 - scnprintf(tmp, 64, " %17.*f", precision, avg); + scnprintf(tmp, 64, " %17.9f", avg); while (tmp[indent] =3D=3D ' ') indent++; =20 @@ -1421,8 +1412,7 @@ static void print_table(struct perf_stat_config *conf= ig, double run =3D (double) config->walltime_run[idx] / NSEC_PER_SEC; int h, n =3D 1 + abs((int) (100.0 * (run - avg)/run) / 5); =20 - fprintf(output, " %17.*f (%+.*f) ", - precision, run, precision, run - avg); + fprintf(output, " %17.9f (%+.9f) ", run, run - avg); =20 for (h =3D 0; h < n; h++) fprintf(output, "#"); @@ -1462,17 +1452,11 @@ static void print_footer(struct perf_stat_config *c= onfig) } } else { double sd =3D stddev_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC; - /* - * Display at most 2 more significant - * digits than the stddev inaccuracy. - */ - int precision =3D get_precision(sd) + 2; =20 if (config->walltime_run_table) - print_table(config, output, precision, avg); + print_table(config, output, avg); =20 - fprintf(output, " %17.*f +- %.*f seconds time elapsed", - precision, avg, precision, sd); + fprintf(output, " %17.9f +- %.9f seconds time elapsed", avg, sd); =20 print_noise_pct(config, NULL, sd, avg, /*before_metric=3D*/false); } --=20 2.52.0.223.gf5cc29aaa4-goog