[PATCH 18/20] perf python: Use poller object for polling

From: Jiri Olsa
Date: Mon Aug 11 2014 - 04:51:26 EST


Change python polling guts using evlist->pollfd for
poller object.

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/util/python-ext-sources | 2 ++
tools/perf/util/python.c | 19 +++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 16a475a7d492..a2d584126eb1 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -20,3 +20,5 @@ util/strlist.c
../lib/api/fs/fs.c
util/trace-event.c
../../lib/rbtree.c
+util/poller.c
+util/string.c
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 12aa9b0d0ba1..5903b6c30c16 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -7,6 +7,7 @@
#include "event.h"
#include "cpumap.h"
#include "thread_map.h"
+#include "poller.h"

/*
* Support debug printing even though util/debug.c is not linked. That means
@@ -730,13 +731,22 @@ static PyObject *pyrf_evlist__poll(struct pyrf_evlist *pevlist,
PyObject *args, PyObject *kwargs)
{
struct perf_evlist *evlist = &pevlist->evlist;
+ struct poller *poller = &evlist->poller;
static char *kwlist[] = { "timeout", NULL };
- int timeout = -1, n;
+ int timeout = -1, n, err;

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &timeout))
return NULL;

- n = poll(evlist->pollfd, evlist->nr_fds, timeout);
+ if (poller__empty(poller)) {
+ err = perf_evlist__set_poller(evlist);
+ if (err) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+ }
+
+ n = poller__poll(poller, timeout);
if (n < 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
@@ -750,12 +760,13 @@ static PyObject *pyrf_evlist__get_pollfd(struct pyrf_evlist *pevlist,
PyObject *kwargs __maybe_unused)
{
struct perf_evlist *evlist = &pevlist->evlist;
+ struct poller *poller = &evlist->poller;
PyObject *list = PyList_New(0);
int i;

- for (i = 0; i < evlist->nr_fds; ++i) {
+ for (i = 0; i < poller->n; ++i) {
PyObject *file;
- FILE *fp = fdopen(evlist->pollfd[i].fd, "r");
+ FILE *fp = fdopen(poller->ptr[i].fd, "r");

if (fp == NULL)
goto free_list;
--
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/