perf trace: Improve event processing exit
authorArnaldo Carvalho de Melo <[email protected]>
Wed, 16 Oct 2013 14:57:33 +0000 (11:57 -0300)
committerArnaldo Carvalho de Melo <[email protected]>
Wed, 16 Oct 2013 19:12:24 +0000 (16:12 -0300)
We need to differentiate SIGCHLD from SIGINT, the later should cause as
immediate as possible exit, while the former should wait to process the
events that may be perceived in the ring buffer after the SIGCHLD is
handled.

Cc: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/perf/builtin-trace.c

index 86d2b1f2399c579ea4ddcb05ed447d35fc05d0f1..ec8289570f4fbb3cd58eb7f325d05745cea7c293 100644 (file)
@@ -1098,10 +1098,12 @@ static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
 }
 
 static bool done = false;
+static bool interrupted = false;
 
-static void sig_handler(int sig __maybe_unused)
+static void sig_handler(int sig)
 {
        done = true;
+       interrupted = sig == SIGINT;
 }
 
 static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread,
@@ -1771,24 +1773,23 @@ again:
                        handler = evsel->handler.func;
                        handler(trace, evsel, &sample);
 
-                       if (done)
-                               goto out_unmap_evlist;
+                       if (interrupted)
+                               goto out_disable;
                }
        }
 
        if (trace->nr_events == before) {
-               if (done)
-                       goto out_unmap_evlist;
+               int timeout = done ? 100 : -1;
 
-               poll(evlist->pollfd, evlist->nr_fds, -1);
+               if (poll(evlist->pollfd, evlist->nr_fds, timeout) > 0)
+                       goto again;
+       } else {
+               goto again;
        }
 
-       if (done)
-               perf_evlist__disable(evlist);
-       else
-               goto again;
+out_disable:
+       perf_evlist__disable(evlist);
 
-out_unmap_evlist:
        if (!err) {
                if (trace->summary)
                        trace__fprintf_thread_summary(trace, trace->output);