perf_counter tools: Propagate signals properly
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 <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
Родитель
4502d77c1d
Коммит
f7b7c26e01
|
@ -169,10 +169,21 @@ static void mmap_read(struct mmap_data *md)
|
||||||
}
|
}
|
||||||
|
|
||||||
static volatile int done = 0;
|
static volatile int done = 0;
|
||||||
|
static volatile int signr = -1;
|
||||||
|
|
||||||
static void sig_handler(int sig)
|
static void sig_handler(int sig)
|
||||||
{
|
{
|
||||||
done = 1;
|
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)
|
static void pid_synthesize_comm_event(pid_t pid, int full)
|
||||||
|
@ -459,6 +470,7 @@ static int __cmd_record(int argc, const char **argv)
|
||||||
} else for (i = 0; i < nr_cpus; i++)
|
} else for (i = 0; i < nr_cpus; i++)
|
||||||
open_counters(i, target_pid);
|
open_counters(i, target_pid);
|
||||||
|
|
||||||
|
atexit(sig_atexit);
|
||||||
signal(SIGCHLD, sig_handler);
|
signal(SIGCHLD, sig_handler);
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
|
|
@ -296,8 +296,20 @@ static int do_perf_stat(int argc, const char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static volatile int signr = -1;
|
||||||
|
|
||||||
static void skip_signal(int signo)
|
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[] = {
|
static const char * const stat_usage[] = {
|
||||||
|
@ -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
|
* What we want is for Ctrl-C to work in the exec()-ed
|
||||||
* task, but being ignored by perf stat itself:
|
* task, but being ignored by perf stat itself:
|
||||||
*/
|
*/
|
||||||
|
atexit(sig_atexit);
|
||||||
signal(SIGINT, skip_signal);
|
signal(SIGINT, skip_signal);
|
||||||
signal(SIGALRM, skip_signal);
|
signal(SIGALRM, skip_signal);
|
||||||
signal(SIGABRT, skip_signal);
|
signal(SIGABRT, skip_signal);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче