[tip:perf/core] perf python: Add perf.tracepoint method

From: tip-bot for Jiri Olsa
Date: Wed Jul 13 2016 - 03:27:47 EST


Commit-ID: 1075fbb22f095c857930190e30fd3ae422d424b6
Gitweb: http://git.kernel.org/tip/1075fbb22f095c857930190e30fd3ae422d424b6
Author: Jiri Olsa <jolsa@xxxxxxxxxx>
AuthorDate: Sun, 10 Jul 2016 13:07:58 +0200
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Tue, 12 Jul 2016 16:17:54 -0300

perf python: Add perf.tracepoint method

To get id of the tracepoint from subsystem and name strings. The
interface is:

id = perf.tracepoint(sys, name)

In case of error -1 is returned.

It will be used to get python tracepoint event's config value for
tracepoint event.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Link: http://lkml.kernel.org/r/1468148882-10362-7-git-send-email-jolsa@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/python.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index fc277e4..45fdd4a 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -2,6 +2,7 @@
#include <structmember.h>
#include <inttypes.h>
#include <poll.h>
+#include <linux/err.h>
#include "evlist.h"
#include "evsel.h"
#include "event.h"
@@ -1076,7 +1077,32 @@ static struct {
{ .name = NULL, },
};

+static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel,
+ PyObject *args, PyObject *kwargs)
+{
+ struct event_format *tp_format;
+ static char *kwlist[] = { "sys", "name", NULL };
+ char *sys = NULL;
+ char *name = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss", kwlist,
+ &sys, &name))
+ return NULL;
+
+ tp_format = trace_event__tp_format(sys, name);
+ if (IS_ERR(tp_format))
+ return PyInt_FromLong(-1);
+
+ return PyInt_FromLong(tp_format->id);
+}
+
static PyMethodDef perf__methods[] = {
+ {
+ .ml_name = "tracepoint",
+ .ml_meth = (PyCFunction) pyrf__tracepoint,
+ .ml_flags = METH_VARARGS | METH_KEYWORDS,
+ .ml_doc = PyDoc_STR("Get tracepoint config.")
+ },
{ .ml_name = NULL, }
};