Skip to content

Commit 58d7e99

Browse files
author
Ingo Molnar
committed
perf stat: handle Ctrl-C
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 <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Corey Ashford <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> LKML-Reference: <new-submission> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 251e8e3 commit 58d7e99

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Documentation/perf_counter/builtin-stat.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,14 @@ static void process_options(int argc, char **argv)
538538
}
539539
}
540540

541+
static void skip_signal(int signo)
542+
{
543+
}
544+
541545
int cmd_stat(int argc, char **argv, const char *prefix)
542546
{
547+
sigset_t blocked;
548+
543549
page_size = sysconf(_SC_PAGE_SIZE);
544550

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

557+
/*
558+
* We dont want to block the signals - that would cause
559+
* child tasks to inherit that and Ctrl-C would not work.
560+
* What we want is for Ctrl-C to work in the exec()-ed
561+
* task, but being ignored by perf stat itself:
562+
*/
563+
signal(SIGINT, skip_signal);
564+
signal(SIGALRM, skip_signal);
565+
signal(SIGABRT, skip_signal);
566+
551567
return do_perfstat(argc, argv);
552568
}

0 commit comments

Comments
 (0)