perf stat display: Make %f precision consistent
Ian Rogers
reviewerPATCH 1/1 perf stat display: Make %f precision consistent
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; 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% )
```--- tools/perf/util/stat-display.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-)
tools/perf/util/stat-display.c +5 -21
@@ -1397,21 +1397,12 @@ static void print_header(struct perf_stat_config *config, num_print_iv =0 ; } -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,double avg) {char tmp[64 ];int idx, indent =0 ; -scnprintf (tmp,64 ," %17.*f" , precision, avg); +scnprintf (tmp,64 ," %17.9f" , avg);while (tmp[indent] ==' ' ) indent++;
@@ -1421,8 +1412,7 @@ static void print_table(struct perf_stat_config *config,double run = (double ) config->walltime_run[idx] /NSEC_PER_SEC ;int h, n =1 +abs ((int ) (100.0 * (run - avg)/run) /5 ); -fprintf (output," %17.*f (%+.*f) " , - precision, run, precision, run - avg); +fprintf (output," %17.9f (%+.9f) " , run, run - avg);for (h =0 ; h < n; h++)fprintf (output,"#" );
@@ -1462,17 +1452,11 @@ static void print_footer(struct perf_stat_config *config) } }else {double sd =stddev_stats (config->walltime_nsecs_stats) /NSEC_PER_SEC ; -/* -* Display at most 2 more significant -* digits than the stddev inaccuracy. -*/ -int precision =get_precision (sd) +2 ;if (config->walltime_run_table) -print_table (config, output, precision, avg); +print_table (config, output, avg); -fprintf (output," %17.*f +- %.*f seconds time elapsed" , - precision, avg, precision, sd); +fprintf (output," %17.9f +- %.9f seconds time elapsed" , avg, sd);print_noise_pct (config,NULL , sd, avg,/*before_metric=*/ false); }
Signature · 1 line
2.52.0.223.gf5cc29aaa4-goog
Quoted 21 lines · Ian Rogers
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; 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:
```
Quoted 9 lines
$ 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% )Perfect, thank you!
Ingo
Ian Rogers
reviewerQuoted 34 lines · Ingo Molnar
Quoted 21 lines · Ian Rogers
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; 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:
```Quoted 9 lines
$ 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% )
Quoted 3 lines
Perfect, thank you!
Tested-by Ingo Molnar <[email protected]>
Ping.
Thanks,
Ian
Quoted 2 lines
Ingo
Quoted 35 lines · Ian Rogers
Quoted 34 lines · Ingo Molnar
Quoted 30 lines · Ian Rogers
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; 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% )
Quoted 5 lines
Quoted 3 lines
Perfect, thank you!
Tested-by Ingo Molnar <[email protected]>Ping.
Thanks, applied to perf-tools-next,
- Arnaldo