diff options
author | Peter Zijlstra <peterz@infradead.org> | 2012-10-23 07:40:14 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-10-26 09:22:25 -0400 |
commit | 1f16c5754d3a4008c29f3bf67b4f1271313ba385 (patch) | |
tree | 365f7e0630b149593d81f56edc5b3f34cf2a3081 /tools/perf/builtin-stat.c | |
parent | 54a3cf59b53b3f01989a28344ecf4cb68217a6f6 (diff) |
perf stat: Add --pre and --post command
In order to measure kernel builds, one has to do some pre/post cleanup
work in order to do the repeat build.
So provide --pre and --post command hooks to allow doing just that.
perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' \
-- make -s -j64 O=defconfig-build/ bzImage
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: Stephane Eranian <eranian@gmail.com>
Link: http://lkml.kernel.org/r/1350992414.13456.5.camel@twins
[ committer note: Added respective entries in Documentation/perf-stat.txt ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r-- | tools/perf/builtin-stat.c | 42 |
1 files changed, 36 insertions, 6 deletions
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; | |||
83 | static bool csv_output = false; | 84 | static bool csv_output = false; |
84 | static bool group = false; | 85 | static bool group = false; |
85 | static FILE *output = NULL; | 86 | static FILE *output = NULL; |
87 | static const char *pre_cmd = NULL; | ||
88 | static const char *post_cmd = NULL; | ||
89 | static bool sync_run = false; | ||
86 | 90 | ||
87 | static volatile int done = 0; | 91 | static 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 | ||
268 | static int run_perf_stat(int argc __maybe_unused, const char **argv) | 272 | static 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 | ||
412 | static 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 | |||
408 | static void print_noise_pct(double total, double avg) | 438 | static 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 | ||
1070 | int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | 1100 | int 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 | ||