Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf stat display: Make %f precision consistent

Commit bc22de9bcdb22491 ("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; done
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; done
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% )
```

Closes: https://lore.kernel.org/lkml/aTQRgAOpKyI53TEq@gmail.com/
Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Chun-Tse Shao <ctshao@google.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
6e5f2ad6 383f8e26

+5 -21
+5 -21
tools/perf/util/stat-display.c
··· 1397 1397 num_print_iv = 0; 1398 1398 } 1399 1399 1400 - static int get_precision(double num) 1401 - { 1402 - if (num > 1) 1403 - return 0; 1404 - 1405 - return lround(ceil(-log10(num))); 1406 - } 1407 - 1408 - static void print_table(struct perf_stat_config *config, 1409 - FILE *output, int precision, double avg) 1400 + static void print_table(struct perf_stat_config *config, FILE *output, double avg) 1410 1401 { 1411 1402 char tmp[64]; 1412 1403 int idx, indent = 0; 1413 1404 1414 - scnprintf(tmp, 64, " %17.*f", precision, avg); 1405 + scnprintf(tmp, 64, " %17.9f", avg); 1415 1406 while (tmp[indent] == ' ') 1416 1407 indent++; 1417 1408 ··· 1412 1421 double run = (double) config->walltime_run[idx] / NSEC_PER_SEC; 1413 1422 int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5); 1414 1423 1415 - fprintf(output, " %17.*f (%+.*f) ", 1416 - precision, run, precision, run - avg); 1424 + fprintf(output, " %17.9f (%+.9f) ", run, run - avg); 1417 1425 1418 1426 for (h = 0; h < n; h++) 1419 1427 fprintf(output, "#"); ··· 1452 1462 } 1453 1463 } else { 1454 1464 double sd = stddev_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC; 1455 - /* 1456 - * Display at most 2 more significant 1457 - * digits than the stddev inaccuracy. 1458 - */ 1459 - int precision = get_precision(sd) + 2; 1460 1465 1461 1466 if (config->walltime_run_table) 1462 - print_table(config, output, precision, avg); 1467 + print_table(config, output, avg); 1463 1468 1464 - fprintf(output, " %17.*f +- %.*f seconds time elapsed", 1465 - precision, avg, precision, sd); 1469 + fprintf(output, " %17.9f +- %.9f seconds time elapsed", avg, sd); 1466 1470 1467 1471 print_noise_pct(config, NULL, sd, avg, /*before_metric=*/false); 1468 1472 }