From c8644c38c34d6f1c34c980a41acbe6df6e55690b Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Tue, 23 Oct 2012 13:40:14 +0200 Subject: [PATCH] --- yaml --- r: 338911 b: refs/heads/master c: 1f16c5754d3a4008c29f3bf67b4f1271313ba385 h: refs/heads/master i: 338909: d3074818d86d4ebfa78bb2747357bbc5fed3f5f4 338907: cda80581be4ef9b8b1f691e153803f5df0606b81 338903: 191d18651ea92aa6d327f9a151f4778f971d8cae 338895: 4c5eb4d26c22ab0631e47e0f92f444c5e6ee8ef3 338879: e7b0dad5eae38393d3ee6abe27f063f785d0151f v: v3 --- [refs] | 2 +- trunk/tools/perf/Documentation/perf-stat.txt | 5 +++ trunk/tools/perf/builtin-stat.c | 42 +++++++++++++++++--- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/[refs] b/[refs] index fbe0cb648743..18c7e25b4897 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 54a3cf59b53b3f01989a28344ecf4cb68217a6f6 +refs/heads/master: 1f16c5754d3a4008c29f3bf67b4f1271313ba385 diff --git a/trunk/tools/perf/Documentation/perf-stat.txt b/trunk/tools/perf/Documentation/perf-stat.txt index 2fa173b51970..cf0c3107e06e 100644 --- a/trunk/tools/perf/Documentation/perf-stat.txt +++ b/trunk/tools/perf/Documentation/perf-stat.txt @@ -108,6 +108,11 @@ with it. --append may be used here. Examples: 3>results perf stat --log-fd 3 -- $cmd 3>>results perf stat --log-fd 3 --append -- $cmd +--pre:: +--post:: + Pre and post measurement hooks, e.g.: + +perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' -- make -s -j64 O=defconfig-build/ bzImage EXAMPLES diff --git a/trunk/tools/perf/builtin-stat.c b/trunk/tools/perf/builtin-stat.c index 93b9011fa3e2..6888960ef8b8 100644 --- a/trunk/tools/perf/builtin-stat.c +++ b/trunk/tools/perf/builtin-stat.c @@ -57,6 +57,7 @@ #include "util/thread.h" #include "util/thread_map.h" +#include #include #include @@ -83,6 +84,9 @@ static const char *csv_sep = NULL; static bool csv_output = false; static bool group = false; static FILE *output = NULL; +static const char *pre_cmd = NULL; +static const char *post_cmd = NULL; +static bool sync_run = false; static volatile int done = 0; @@ -265,7 +269,7 @@ static int read_counter(struct perf_evsel *counter) return 0; } -static int run_perf_stat(int argc __maybe_unused, const char **argv) +static int __run_perf_stat(int argc __maybe_unused, const char **argv) { unsigned long long t0, t1; struct perf_evsel *counter, *first; @@ -405,6 +409,32 @@ static int run_perf_stat(int argc __maybe_unused, const char **argv) return WEXITSTATUS(status); } +static int run_perf_stat(int argc __maybe_unused, const char **argv) +{ + int ret; + + if (pre_cmd) { + ret = system(pre_cmd); + if (ret) + return ret; + } + + if (sync_run) + sync(); + + ret = __run_perf_stat(argc, argv); + if (ret) + return ret; + + if (post_cmd) { + ret = system(post_cmd); + if (ret) + return ret; + } + + return ret; +} + static void print_noise_pct(double total, double avg) { double pct = rel_stddev_stats(total, avg); @@ -1069,8 +1099,7 @@ static int add_default_attributes(void) int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) { - bool append_file = false, - sync_run = false; + bool append_file = false; int output_fd = 0; const char *output_name = NULL; const struct option options[] = { @@ -1114,6 +1143,10 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) OPT_BOOLEAN(0, "append", &append_file, "append to the output file"), OPT_INTEGER(0, "log-fd", &output_fd, "log output to fd, instead of stderr"), + OPT_STRING(0, "pre", &pre_cmd, "command", + "command to run prior to the measured command"), + OPT_STRING(0, "post", &post_cmd, "command", + "command to run after to the measured command"), OPT_END() }; const char * const stat_usage[] = { @@ -1238,9 +1271,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) fprintf(output, "[ perf stat: executing run #%d ... ]\n", run_idx + 1); - if (sync_run) - sync(); - status = run_perf_stat(argc, argv); }