perf tools: Add --quiet option to perf stat
PATCH 1/2 perf tools: Add --quiet option to perf stat
Add a new --quiet option to perf stat. This is useful with perf stat record to write the data only to the perf.data file, which can lower measurement overhead because the data doesn't need to be formatted.
On my 4C desktop:
% time ./perf stat record -e $(python -c 'print ",".join(["cycles"]*1000)') -a -I 1000 sleep 5
...
real 0m5.377s user 0m0.238s sys 0m0.452s
% time ./perf stat record --quiet -e $(python -c 'print ",".join(["cycles"]*1000)') -a -I 1000 sleep 5
real 0m5.452s user 0m0.183s sys 0m0.423s
In this example it cuts the user time by 20%. On systems with more cores the savings are higher.
--- tools/perf/Documentation/perf-stat.txt | 4 ++++ tools/perf/builtin-stat.c | 6 +++++- tools/perf/util/stat.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-stat.txt +4 -0
@@ -316,6 +316,10 @@ small group that need not have multiplexing is lowered. This option forbids the event merging logic from sharing events between groups and may be used to increase accuracy in this case. +--quiet:: +Don't print output. This is useful with perf stat record below to only +write data to the perf.data file. + STAT RECORD ----------- Stores stat data into perf data file.
tools/perf/builtin-stat.c +5 -1
@@ -972,6 +972,8 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)/* Do not print anything if we record to the pipe. */ if (STAT_RECORD && perf_stat.data.is_pipe)return ; +if (stat_config.quiet) +return ;perf_evlist__print_counters (evsel_list, &stat_config, &target, ts, argc, argv);
@@ -1171,6 +1173,8 @@ static struct option stat_options[] = { "threads of same physical core"),OPT_BOOLEAN (0 ,"summary" , &stat_config.summary,"print summary for interval mode" ), +OPT_BOOLEAN (0 ,"quiet" , &stat_config.quiet, +"don't print output (useful with record)" ), #ifdef HAVE_LIBPFM OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", "libpfm4 event selector. use 'perf list' to list available events",
@@ -2132,7 +2136,7 @@ int cmd_stat(int argc, const char **argv) goto out; } -if (!output) { +if (!output && !stat_config.quiet) {struct timespec tm; mode = append_file ?"a" :"w" ;
tools/perf/util/stat.h +1 -0
@@ -122,6 +122,7 @@ struct perf_stat_config {bool metric_no_group;bool metric_no_merge;bool stop_read_counter; +bool quiet;FILE *output;unsigned int interval;unsigned int timeout;
Signature · 1 line
2.28.0
PATCH 2/2 perf tools: Support -x for perf stat report
Add support for the -x, option to enable CSV output with perf stat report. Useful to parse the information with other programs.
% perf stat record --quiet -a -I 1000 sleep 5
% perf stat report -x,
1.000838672,4003.55,msec,cpu-clock,4003548736,100.00,,
1.000838672,11243,,context-switches,4003631885,100.00,0.003,M/sec
1.000838672,1682,,cpu-migrations,4003672150,100.00,0.420,K/sec
1.000838672,13244,,page-faults,4003697471,100.00,0.003,M/sec
1.000838672,2953214077,,cycles,4003715495,100.00,0.738,GHz
1.000838672,4380820799,,instructions,4003738270,100.00,1.48,insn per cycle
1.000838672,809865653,,branches,4003760616,100.00,202.287,M/sec
1.000838672,12439843,,branch-misses,4003780785,100.00,1.54,of all branches...
--- tools/perf/builtin-stat.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/perf/builtin-stat.c +7 -0
@@ -1988,6 +1988,8 @@ static int __cmd_report(int argc, const char **argv) "aggregate counts per numa node", AGGR_NODE),OPT_SET_UINT ('A' ,"no-aggr" , &perf_stat.aggr_mode,"disable CPU count aggregation" ,AGGR_NONE ), +OPT_STRING ('x' ,"field-separator" , &stat_config.csv_sep,"separator" , +"print counts with custom separator" ), OPT_END() };struct stat st;
@@ -2002,6 +2004,11 @@ static int __cmd_report(int argc, const char **argv) input_name ="perf.data" ; } +if (stat_config.csv_sep) { + stat_config.csv_output = true; + stat_config.big_num = false; + } + perf_stat.data.path = input_name; perf_stat.data.mode =PERF_DATA_MODE_READ ;
Signature · 1 line
2.28.0
Re: [PATCH 2/2] perf tools: Support -x for perf stat report
Quoted 34 lines · Andi Kleen
Add support for the -x, option to enable CSV output with perf stat report. Useful to parse the information with other programs.
% perf stat record --quiet -a -I 1000 sleep 5
% perf stat report -x,1.000838672,4003.55,msec,cpu-clock,4003548736,100.00,, 1.000838672,11243,,context-switches,4003631885,100.00,0.003,M/sec 1.000838672,1682,,cpu-migrations,4003672150,100.00,0.420,K/sec 1.000838672,13244,,page-faults,4003697471,100.00,0.003,M/sec 1.000838672,2953214077,,cycles,4003715495,100.00,0.738,GHz 1.000838672,4380820799,,instructions,4003738270,100.00,1.48,insn per cycle 1.000838672,809865653,,branches,4003760616,100.00,202.287,M/sec 1.000838672,12439843,,branch-misses,4003780785,100.00,1.54,of all branches...
Signed-off-by Andi Kleen <[email protected]>--- tools/perf/builtin-stat.c | 7 +++++++ 1 file changed, 7 insertions(+)tools/perf/builtin-stat.c +2
-0@@ -1988,6 +1988,8 @@ static int __cmd_report(int argc, const char **argv) "aggregate counts per numa node", AGGR_NODE),OPT_SET_UINT ('A' ,"no-aggr" , &perf_stat.aggr_mode,"disable CPU count aggregation" ,AGGR_NONE ), +OPT_STRING ('x' ,"field-separator" , &stat_config.csv_sep,"separator" , +"print counts with custom separator" ), OPT_END() };struct stat st;
tools/perf/builtin-stat.c static int __cmd_report(int argc, const char **argv) · line 2010
Quoted 7 lines
tools/perf/builtin-stat.c +4
-0@@ -2002,6 +2004,11 @@ static int __cmd_report(int argc, const char **argv) input_name ="perf.data" ; } +if (stat_config.csv_sep) { + stat_config.csv_output = true; + stat_config.big_num = false; + }
stat_config.csv_sep is by default ' ' so this will force the standard output to be with -x
jirka
Quoted 7 lines
tools/perf/builtin-stat.c +1
-0+ perf_stat.data.path = input_name; perf_stat.data.mode =PERF_DATA_MODE_READ ;Signature · 1 line
2.28.0
Arnaldo Carvalho de Melo
maintainerEm Mon, Oct 26, 2020 at 05:27:36PM -0700, Andi Kleen escreveu:
Quoted 11 lines
Add a new --quiet option to perf stat. This is useful with perf stat record to write the data only to the perf.data file, which can lower measurement overhead because the data doesn't need to be formatted.
On my 4C desktop:
% time ./perf stat record -e $(python -c 'print ",".join(["cycles"]*1000)') -a -I 1000 sleep 5
...real 0m5.377s user 0m0.238s sys 0m0.452s
Quoted 8 lines
% time ./perf stat record --quiet -e $(python -c 'print ",".join(["cycles"]*1000)') -a -I 1000 sleep 5
real 0m5.452s user 0m0.183s sys 0m0.423sIn this example it cuts the user time by 20%. On systems with more cores the savings are higher.
Applied 1/2,
Thanks,
- Arnaldo
Quoted 68 lines
Signed-off-by Andi Kleen <[email protected]>--- tools/perf/Documentation/perf-stat.txt | 4 ++++ tools/perf/builtin-stat.c | 6 +++++- tools/perf/util/stat.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-)tools/perf/Documentation/perf-stat.txt +4
-0@@ -316,6 +316,10 @@ small group that need not have multiplexing is lowered. This option forbids the event merging logic from sharing events between groups and may be used to increase accuracy in this case. +--quiet:: +Don't print output. This is useful with perf stat record below to only +write data to the perf.data file. + STAT RECORD ----------- Stores stat data into perf data file.tools/perf/builtin-stat.c +5
-1@@ -972,6 +972,8 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)/* Do not print anything if we record to the pipe. */ if (STAT_RECORD && perf_stat.data.is_pipe)return ; +if (stat_config.quiet) +return ;perf_evlist__print_counters (evsel_list, &stat_config, &target, ts, argc, argv);@@ -1171,6 +1173,8 @@ static struct option stat_options[] = { "threads of same physical core"),OPT_BOOLEAN (0 ,"summary" , &stat_config.summary,"print summary for interval mode" ), +OPT_BOOLEAN (0 ,"quiet" , &stat_config.quiet, +"don't print output (useful with record)" ), #ifdef HAVE_LIBPFM OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", "libpfm4 event selector. use 'perf list' to list available events",@@ -2132,7 +2136,7 @@ int cmd_stat(int argc, const char **argv) goto out; } -if (!output) { +if (!output && !stat_config.quiet) {struct timespec tm; mode = append_file ?"a" :"w" ;tools/perf/util/stat.h +1
-0@@ -122,6 +122,7 @@ struct perf_stat_config {bool metric_no_group;bool metric_no_merge;bool stop_read_counter; +bool quiet;FILE *output;unsigned int interval;unsigned int timeout;Signature · 1 line
2.28.0
Signature · 1 line
- Arnaldo