--- tools/perf/builtin-stat.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) Index: linux/tools/perf/builtin-stat.c =================================================================== --- linux.orig/tools/perf/builtin-stat.c +++ linux/tools/perf/builtin-stat.c @@ -44,6 +44,7 @@ #include "util/parse-events.h" #include "util/event.h" #include "util/debug.h" +#include "util/run-command.h" #include #include @@ -458,7 +459,7 @@ static const struct option options[] = { int cmd_stat(int argc, const char **argv, const char *prefix __used) { - int status; + int status, j, cleanup, cleanup_argc; argc = parse_options(argc, argv, options, stat_usage, PARSE_OPT_STOP_AT_NON_OPTION); @@ -467,6 +468,19 @@ int cmd_stat(int argc, const char **argv if (run_count <= 0) usage_with_options(stat_usage, options); + // quick ugly hack: if a "--" appears in the command, treat is as + // a delimiter and use remaining part as a "cleanup command", + // not affecting performance counters. + cleanup = cleanup_argc = 0; + for (j = 1; j < (argc-1); j ++) { + if (!strcmp (argv[j], "--")) { + cleanup = j + 1; + cleanup_argc = argc - j - 1; + argv[j] = NULL; + argc = j; + } + } + /* Set attrs and nr_counters if no event is selected and !null_run */ if (!null_run && !nr_counters) { memcpy(attrs, default_attrs, sizeof(default_attrs)); @@ -493,6 +507,8 @@ int cmd_stat(int argc, const char **argv if (run_count != 1 && verbose) fprintf(stderr, "[ perf stat: executing run #%d ... ]\n", run_idx + 1); status = run_perf_stat(argc, argv); + if (cleanup) + run_command_v_opt (&argv [cleanup], 0); } print_stat(argc, argv);