* [PATCH 1/2] perf tools: Add --quiet option to perf stat @ 2020-10-27 0:27 Andi Kleen 2020-10-27 0:27 ` [PATCH 2/2] perf tools: Support -x for perf stat report Andi Kleen 2020-10-27 15:09 ` [PATCH 1/2] perf tools: Add --quiet option to perf stat Arnaldo Carvalho de Melo 0 siblings, 2 replies; 4+ messages in thread From: Andi Kleen @ 2020-10-27 0:27 UTC (permalink / raw) To: acme; +Cc: jolsa, linux-kernel, alexey.budankov, Andi Kleen 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. Signed-off-by: Andi Kleen <andi@firstfloor.org> --- 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(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 9f9f29025e49..b138dd192423 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -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. diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index b01af171d94f..743fe47e7a88 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -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"; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 487010c624be..05adf8165025 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -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; -- 2.28.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] perf tools: Support -x for perf stat report 2020-10-27 0:27 [PATCH 1/2] perf tools: Add --quiet option to perf stat Andi Kleen @ 2020-10-27 0:27 ` Andi Kleen 2020-10-27 13:09 ` Jiri Olsa 2020-10-27 15:09 ` [PATCH 1/2] perf tools: Add --quiet option to perf stat Arnaldo Carvalho de Melo 1 sibling, 1 reply; 4+ messages in thread From: Andi Kleen @ 2020-10-27 0:27 UTC (permalink / raw) To: acme; +Cc: jolsa, linux-kernel, alexey.budankov, Andi Kleen, 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 <ak@linux.intel.com> --- tools/perf/builtin-stat.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 743fe47e7a88..31e7bd877f1d 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -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; -- 2.28.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] perf tools: Support -x for perf stat report 2020-10-27 0:27 ` [PATCH 2/2] perf tools: Support -x for perf stat report Andi Kleen @ 2020-10-27 13:09 ` Jiri Olsa 0 siblings, 0 replies; 4+ messages in thread From: Jiri Olsa @ 2020-10-27 13:09 UTC (permalink / raw) To: Andi Kleen; +Cc: acme, jolsa, linux-kernel, alexey.budankov, Andi Kleen On Mon, Oct 26, 2020 at 05:27:37PM -0700, Andi Kleen wrote: > 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 <ak@linux.intel.com> > --- > tools/perf/builtin-stat.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 743fe47e7a88..31e7bd877f1d 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -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; > + } stat_config.csv_sep is by default ' ' so this will force the standard output to be with -x jirka > + > perf_stat.data.path = input_name; > perf_stat.data.mode = PERF_DATA_MODE_READ; > > -- > 2.28.0 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] perf tools: Add --quiet option to perf stat 2020-10-27 0:27 [PATCH 1/2] perf tools: Add --quiet option to perf stat Andi Kleen 2020-10-27 0:27 ` [PATCH 2/2] perf tools: Support -x for perf stat report Andi Kleen @ 2020-10-27 15:09 ` Arnaldo Carvalho de Melo 1 sibling, 0 replies; 4+ messages in thread From: Arnaldo Carvalho de Melo @ 2020-10-27 15:09 UTC (permalink / raw) To: Andi Kleen; +Cc: jolsa, linux-kernel, alexey.budankov Em Mon, Oct 26, 2020 at 05:27:36PM -0700, Andi Kleen escreveu: > 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. Applied 1/2, Thanks, - Arnaldo > Signed-off-by: Andi Kleen <andi@firstfloor.org> > --- > 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(-) > > diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt > index 9f9f29025e49..b138dd192423 100644 > --- a/tools/perf/Documentation/perf-stat.txt > +++ b/tools/perf/Documentation/perf-stat.txt > @@ -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. > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index b01af171d94f..743fe47e7a88 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -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"; > > diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h > index 487010c624be..05adf8165025 100644 > --- a/tools/perf/util/stat.h > +++ b/tools/perf/util/stat.h > @@ -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; > -- > 2.28.0 > -- - Arnaldo ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-27 16:59 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-10-27 0:27 [PATCH 1/2] perf tools: Add --quiet option to perf stat Andi Kleen 2020-10-27 0:27 ` [PATCH 2/2] perf tools: Support -x for perf stat report Andi Kleen 2020-10-27 13:09 ` Jiri Olsa 2020-10-27 15:09 ` [PATCH 1/2] perf tools: Add --quiet option to perf stat Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox