aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/Documentation/perf-stat.txt5
-rw-r--r--tools/perf/builtin-stat.c42
2 files changed, 41 insertions, 6 deletions
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 2fa173b51970..cf0c3107e06e 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -108,6 +108,11 @@ with it. --append may be used here. Examples:
108 3>results perf stat --log-fd 3 -- $cmd 108 3>results perf stat --log-fd 3 -- $cmd
109 3>>results perf stat --log-fd 3 --append -- $cmd 109 3>>results perf stat --log-fd 3 --append -- $cmd
110 110
111--pre::
112--post::
113 Pre and post measurement hooks, e.g.:
114
115perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' -- make -s -j64 O=defconfig-build/ bzImage
111 116
112 117
113EXAMPLES 118EXAMPLES
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 93b9011fa3e2..6888960ef8b8 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -57,6 +57,7 @@
57#include "util/thread.h" 57#include "util/thread.h"
58#include "util/thread_map.h" 58#include "util/thread_map.h"
59 59
60#include <stdlib.h>
60#include <sys/prctl.h> 61#include <sys/prctl.h>
61#include <locale.h> 62#include <locale.h>
62 63
@@ -83,6 +84,9 @@ static const char *csv_sep = NULL;
83static bool csv_output = false; 84static bool csv_output = false;
84static bool group = false; 85static bool group = false;
85static FILE *output = NULL; 86static FILE *output = NULL;
87static const char *pre_cmd = NULL;
88static const char *post_cmd = NULL;
89static bool sync_run = false;
86 90
87static volatile int done = 0; 91static volatile int done = 0;
88 92
@@ -265,7 +269,7 @@ static int read_counter(struct perf_evsel *counter)
265 return 0; 269 return 0;
266} 270}
267 271
268static int run_perf_stat(int argc __maybe_unused, const char **argv) 272static int __run_perf_stat(int argc __maybe_unused, const char **argv)
269{ 273{
270 unsigned long long t0, t1; 274 unsigned long long t0, t1;
271 struct perf_evsel *counter, *first; 275 struct perf_evsel *counter, *first;
@@ -405,6 +409,32 @@ static int run_perf_stat(int argc __maybe_unused, const char **argv)
405 return WEXITSTATUS(status); 409 return WEXITSTATUS(status);
406} 410}
407 411
412static int run_perf_stat(int argc __maybe_unused, const char **argv)
413{
414 int ret;
415
416 if (pre_cmd) {
417 ret = system(pre_cmd);
418 if (ret)
419 return ret;
420 }
421
422 if (sync_run)
423 sync();
424
425 ret = __run_perf_stat(argc, argv);
426 if (ret)
427 return ret;
428
429 if (post_cmd) {
430 ret = system(post_cmd);
431 if (ret)
432 return ret;
433 }
434
435 return ret;
436}
437
408static void print_noise_pct(double total, double avg) 438static void print_noise_pct(double total, double avg)
409{ 439{
410 double pct = rel_stddev_stats(total, avg); 440 double pct = rel_stddev_stats(total, avg);
@@ -1069,8 +1099,7 @@ static int add_default_attributes(void)
1069 1099
1070int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) 1100int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1071{ 1101{
1072 bool append_file = false, 1102 bool append_file = false;
1073 sync_run = false;
1074 int output_fd = 0; 1103 int output_fd = 0;
1075 const char *output_name = NULL; 1104 const char *output_name = NULL;
1076 const struct option options[] = { 1105 const struct option options[] = {
@@ -1114,6 +1143,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1114 OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), 1143 OPT_BOOLEAN(0, "append", &append_file, "append to the output file"),
1115 OPT_INTEGER(0, "log-fd", &output_fd, 1144 OPT_INTEGER(0, "log-fd", &output_fd,
1116 "log output to fd, instead of stderr"), 1145 "log output to fd, instead of stderr"),
1146 OPT_STRING(0, "pre", &pre_cmd, "command",
1147 "command to run prior to the measured command"),
1148 OPT_STRING(0, "post", &post_cmd, "command",
1149 "command to run after to the measured command"),
1117 OPT_END() 1150 OPT_END()
1118 }; 1151 };
1119 const char * const stat_usage[] = { 1152 const char * const stat_usage[] = {
@@ -1238,9 +1271,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
1238 fprintf(output, "[ perf stat: executing run #%d ... ]\n", 1271 fprintf(output, "[ perf stat: executing run #%d ... ]\n",
1239 run_idx + 1); 1272 run_idx + 1);
1240 1273
1241 if (sync_run)
1242 sync();
1243
1244 status = run_perf_stat(argc, argv); 1274 status = run_perf_stat(argc, argv);
1245 } 1275 }
1246 1276