perf trace: Filter out POLLHUP'ed file descriptors
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 22 Sep 2014 17:39:48 +0000 (14:39 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 25 Sep 2014 19:46:56 +0000 (16:46 -0300)
So that we don't continue polling on vanished file descriptors, i.e.
file descriptors for events monitoring threads that exited.

I.e. the following 'trace' command now exits as expected, instead
of staying in an eternal loop:

      $ sleep 5s &
      $ trace -p `pidof sleep`

Reported-by: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-6qegv786zbf6i8us6t4rxug9@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c

index b8fedf3f99215589b80a276bb74d8af43dbf6002..fe39dc620179a6fd1061899f7d6efd5c225ef4f7 100644 (file)
@@ -2044,6 +2044,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
        int err = -1, i;
        unsigned long before;
        const bool forks = argc > 0;
+       bool draining = false;
        char sbuf[STRERR_BUFSIZE];
 
        trace->live = true;
@@ -2171,8 +2172,12 @@ next_event:
        if (trace->nr_events == before) {
                int timeout = done ? 100 : -1;
 
-               if (perf_evlist__poll(evlist, timeout) > 0)
+               if (!draining && perf_evlist__poll(evlist, timeout) > 0) {
+                       if (perf_evlist__filter_pollfd(evlist, POLLERR | POLLHUP) == 0)
+                               draining = true;
+
                        goto again;
+               }
        } else {
                goto again;
        }