2 * Context.c. Python interfaces for perf script.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "../../../perf.h"
24 #include "../../../util/trace-event.h"
26 #if PY_MAJOR_VERSION < 3
27 #define _PyCapsule_GetPointer(arg1, arg2) \
28 PyCObject_AsVoidPtr(arg1)
30 PyMODINIT_FUNC initperf_trace_context(void);
32 #define _PyCapsule_GetPointer(arg1, arg2) \
33 PyCapsule_GetPointer((arg1), (arg2))
35 PyMODINIT_FUNC PyInit_perf_trace_context(void);
38 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
40 static struct scripting_context *scripting_context;
44 if (!PyArg_ParseTuple(args, "O", &context))
47 scripting_context = _PyCapsule_GetPointer(context, NULL);
48 retval = common_pc(scripting_context);
50 return Py_BuildValue("i", retval);
53 static PyObject *perf_trace_context_common_flags(PyObject *obj,
56 static struct scripting_context *scripting_context;
60 if (!PyArg_ParseTuple(args, "O", &context))
63 scripting_context = _PyCapsule_GetPointer(context, NULL);
64 retval = common_flags(scripting_context);
66 return Py_BuildValue("i", retval);
69 static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
72 static struct scripting_context *scripting_context;
76 if (!PyArg_ParseTuple(args, "O", &context))
79 scripting_context = _PyCapsule_GetPointer(context, NULL);
80 retval = common_lock_depth(scripting_context);
82 return Py_BuildValue("i", retval);
85 static PyMethodDef ContextMethods[] = {
86 { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
87 "Get the common preempt count event field value."},
88 { "common_flags", perf_trace_context_common_flags, METH_VARARGS,
89 "Get the common flags event field value."},
90 { "common_lock_depth", perf_trace_context_common_lock_depth,
91 METH_VARARGS, "Get the common lock depth event field value."},
92 { NULL, NULL, 0, NULL}
95 #if PY_MAJOR_VERSION < 3
96 PyMODINIT_FUNC initperf_trace_context(void)
98 (void) Py_InitModule("perf_trace_context", ContextMethods);
101 PyMODINIT_FUNC PyInit_perf_trace_context(void)
103 static struct PyModuleDef moduledef = {
104 PyModuleDef_HEAD_INIT,
105 "perf_trace_context", /* m_name */
108 ContextMethods, /* m_methods */
110 NULL, /* m_traverse */
114 return PyModule_Create(&moduledef);