[PATCH 17/20] perf trace: Add support to see event's ERR and HUP poll errors

From: Jiri Olsa
Date: Mon Aug 11 2014 - 04:52:24 EST


Adding trace command support to see when all events
are down and forcing it to stop in that case.

Like following trace session will stop if the
monitored pid (1234) exits:

$ perf trace -p 1234

Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Jean Pihet <jean.pihet@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/builtin-trace.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 36ae51d61be2..d465f4519a66 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2011,6 +2011,18 @@ static int perf_evlist__add_pgfault(struct perf_evlist *evlist,
return 0;
}

+static int data_error(struct poller *p, struct poller_item *item)
+{
+ pr_debug("got HUP/ERROR on fd %d\n", item->fd);
+
+ poller__del(p, item);
+ if (poller__empty(p)) {
+ pr_debug("All events closed, shutting down.\n");
+ done = true;
+ }
+ return 0;
+}
+
static int trace__run(struct trace *trace, int argc, const char **argv)
{
struct perf_evlist *evlist = perf_evlist__new();
@@ -2018,6 +2030,11 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
int err = -1, i;
unsigned long before;
const bool forks = argc > 0;
+ struct poller *poller = &evlist->poller;
+ struct poller_ops poller_ops = {
+ .error = data_error,
+ .hup = data_error,
+ };

trace->live = true;

@@ -2077,6 +2094,10 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (err < 0)
goto out_error_open;

+ err = perf_evlist__set_poller(evlist);
+ if (err < 0)
+ goto out_delete_evlist;
+
err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
if (err < 0) {
fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno));
@@ -2088,6 +2109,8 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (forks)
perf_evlist__start_workload(evlist);

+ poller__set_ops(poller, &poller_ops);
+
trace->multiple_threads = evlist->threads->map[0] == -1 || evlist->threads->nr > 1;
again:
before = trace->nr_events;
@@ -2143,7 +2166,7 @@ next_event:
if (trace->nr_events == before) {
int timeout = done ? 100 : -1;

- if (poll(evlist->pollfd, evlist->nr_fds, timeout) > 0)
+ if (poller__poll(poller, timeout) > 0)
goto again;
} else {
goto again;
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/