Skip to content

Commit

Permalink
perf stat: handle Ctrl-C
Browse files Browse the repository at this point in the history
Before this change, if a long-running perf stat workload was Ctrl-C-ed,
the utility exited without displaying statistics.

After the change, the Ctrl-C gets propagated into the workload (and
causes its early exit there), but perf stat itself will still continue
to run and will display counter results.

This is useful to run open-ended workloads, let them run for
a while, then Ctrl-C them to get the stats.

[ Impact: extend perf stat with new functionality ]

Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ingo Molnar committed May 15, 2009
1 parent 251e8e3 commit 58d7e99
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Documentation/perf_counter/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,14 @@ static void process_options(int argc, char **argv)
}
}

static void skip_signal(int signo)
{
}

int cmd_stat(int argc, char **argv, const char *prefix)
{
sigset_t blocked;

page_size = sysconf(_SC_PAGE_SIZE);

process_options(argc, argv);
Expand All @@ -548,5 +554,15 @@ int cmd_stat(int argc, char **argv, const char *prefix)
assert(nr_cpus <= MAX_NR_CPUS);
assert(nr_cpus >= 0);

/*
* We dont want to block the signals - that would cause
* child tasks to inherit that and Ctrl-C would not work.
* What we want is for Ctrl-C to work in the exec()-ed
* task, but being ignored by perf stat itself:
*/
signal(SIGINT, skip_signal);
signal(SIGALRM, skip_signal);
signal(SIGABRT, skip_signal);

return do_perfstat(argc, argv);
}

0 comments on commit 58d7e99

Please sign in to comment.