Skip to content

Commit

Permalink
perf_counter tools: Propagate signals properly
Browse files Browse the repository at this point in the history
Currently report and stat catch SIGINT (and others) without altering
their exit state. This means that things like:

   while :; do perf stat ./foo ; done

Loops become hard-to-interrupt, because bash never sees perf terminate
due to interruption. Fix this.

Signed-off-by: Peter Zijlstra <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Jun 10, 2009
1 parent 4502d77 commit f7b7c26
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,21 @@ static void mmap_read(struct mmap_data *md)
}

static volatile int done = 0;
static volatile int signr = -1;

static void sig_handler(int sig)
{
done = 1;
signr = sig;
}

static void sig_atexit(void)
{
if (signr == -1)
return;

signal(signr, SIG_DFL);
kill(getpid(), signr);
}

static void pid_synthesize_comm_event(pid_t pid, int full)
Expand Down Expand Up @@ -459,6 +470,7 @@ static int __cmd_record(int argc, const char **argv)
} else for (i = 0; i < nr_cpus; i++)
open_counters(i, target_pid);

atexit(sig_atexit);
signal(SIGCHLD, sig_handler);
signal(SIGINT, sig_handler);

Expand Down
13 changes: 13 additions & 0 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,20 @@ static int do_perf_stat(int argc, const char **argv)
return 0;
}

static volatile int signr = -1;

static void skip_signal(int signo)
{
signr = signo;
}

static void sig_atexit(void)
{
if (signr == -1)
return;

signal(signr, SIG_DFL);
kill(getpid(), signr);
}

static const char * const stat_usage[] = {
Expand Down Expand Up @@ -345,6 +357,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
* What we want is for Ctrl-C to work in the exec()-ed
* task, but being ignored by perf stat itself:
*/
atexit(sig_atexit);
signal(SIGINT, skip_signal);
signal(SIGALRM, skip_signal);
signal(SIGABRT, skip_signal);
Expand Down

0 comments on commit f7b7c26

Please sign in to comment.