提交 30ab85ad 编写于 作者: A Andi Kleen 提交者: Wang ShaoBo

perf stat: Add a new --quiet option to 'perf stat'

mainline inclusion
from mainline-5.11
commit 55a4de94
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4CMQA
CVE: NA

--------------------------------

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: NAndi Kleen <andi@firstfloor.org>
Acked-by: NJiri Olsa <jolsa@kernel.org>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Link: http://lore.kernel.org/lkml/20201027002737.30942-1-andi@firstfloor.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Nyin-xiujiang <yinxiujiang@kylinos.cn>
Reviewed-by: Jian Cheng <cj.chengjian(a)huawei.com>
Signed-off-by: NWang ShaoBo <bobo.shaobowang@huawei.com>
上级 8ead6437
...@@ -320,6 +320,10 @@ STAT RECORD ...@@ -320,6 +320,10 @@ STAT RECORD
----------- -----------
Stores stat data into perf data file. Stores stat data into perf data file.
--quiet::
Don't print output. This is useful with perf stat record below to only
write data to the perf.data file.
-o file:: -o file::
--output file:: --output file::
Output file name. Output file name.
......
...@@ -973,6 +973,8 @@ static void print_counters(struct timespec *ts, int argc, const char **argv) ...@@ -973,6 +973,8 @@ static void print_counters(struct timespec *ts, int argc, const char **argv)
if (STAT_RECORD && perf_stat.data.is_pipe) if (STAT_RECORD && perf_stat.data.is_pipe)
return; return;
if (stat_config.quiet)
return;
perf_evlist__print_counters(evsel_list, &stat_config, &target, perf_evlist__print_counters(evsel_list, &stat_config, &target,
ts, argc, argv); ts, argc, argv);
} }
...@@ -1171,6 +1173,8 @@ static struct option stat_options[] = { ...@@ -1171,6 +1173,8 @@ static struct option stat_options[] = {
"threads of same physical core"), "threads of same physical core"),
OPT_BOOLEAN(0, "summary", &stat_config.summary, OPT_BOOLEAN(0, "summary", &stat_config.summary,
"print summary for interval mode"), "print summary for interval mode"),
OPT_BOOLEAN(0, "quiet", &stat_config.quiet,
"don't print output (useful with record)"),
#ifdef HAVE_LIBPFM #ifdef HAVE_LIBPFM
OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", OPT_CALLBACK(0, "pfm-events", &evsel_list, "event",
"libpfm4 event selector. use 'perf list' to list available events", "libpfm4 event selector. use 'perf list' to list available events",
...@@ -2132,7 +2136,7 @@ int cmd_stat(int argc, const char **argv) ...@@ -2132,7 +2136,7 @@ int cmd_stat(int argc, const char **argv)
goto out; goto out;
} }
if (!output) { if (!output && !stat_config.quiet) {
struct timespec tm; struct timespec tm;
mode = append_file ? "a" : "w"; mode = append_file ? "a" : "w";
......
...@@ -122,6 +122,7 @@ struct perf_stat_config { ...@@ -122,6 +122,7 @@ struct perf_stat_config {
bool metric_no_group; bool metric_no_group;
bool metric_no_merge; bool metric_no_merge;
bool stop_read_counter; bool stop_read_counter;
bool quiet;
FILE *output; FILE *output;
unsigned int interval; unsigned int interval;
unsigned int timeout; unsigned int timeout;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册