1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Context.c. Python interfaces for perf script.
5 * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com>
9 #include "../../../perf.h"
10 #include "../../../util/trace-event.h"
12 #if PY_MAJOR_VERSION < 3
13 #define _PyCapsule_GetPointer(arg1, arg2) \
14 PyCObject_AsVoidPtr(arg1)
16 PyMODINIT_FUNC
initperf_trace_context(void);
18 #define _PyCapsule_GetPointer(arg1, arg2) \
19 PyCapsule_GetPointer((arg1), (arg2))
21 PyMODINIT_FUNC
PyInit_perf_trace_context(void);
24 static PyObject
*perf_trace_context_common_pc(PyObject
*obj
, PyObject
*args
)
26 static struct scripting_context
*scripting_context
;
30 if (!PyArg_ParseTuple(args
, "O", &context
))
33 scripting_context
= _PyCapsule_GetPointer(context
, NULL
);
34 retval
= common_pc(scripting_context
);
36 return Py_BuildValue("i", retval
);
39 static PyObject
*perf_trace_context_common_flags(PyObject
*obj
,
42 static struct scripting_context
*scripting_context
;
46 if (!PyArg_ParseTuple(args
, "O", &context
))
49 scripting_context
= _PyCapsule_GetPointer(context
, NULL
);
50 retval
= common_flags(scripting_context
);
52 return Py_BuildValue("i", retval
);
55 static PyObject
*perf_trace_context_common_lock_depth(PyObject
*obj
,
58 static struct scripting_context
*scripting_context
;
62 if (!PyArg_ParseTuple(args
, "O", &context
))
65 scripting_context
= _PyCapsule_GetPointer(context
, NULL
);
66 retval
= common_lock_depth(scripting_context
);
68 return Py_BuildValue("i", retval
);
71 static PyMethodDef ContextMethods
[] = {
72 { "common_pc", perf_trace_context_common_pc
, METH_VARARGS
,
73 "Get the common preempt count event field value."},
74 { "common_flags", perf_trace_context_common_flags
, METH_VARARGS
,
75 "Get the common flags event field value."},
76 { "common_lock_depth", perf_trace_context_common_lock_depth
,
77 METH_VARARGS
, "Get the common lock depth event field value."},
78 { NULL
, NULL
, 0, NULL
}
81 #if PY_MAJOR_VERSION < 3
82 PyMODINIT_FUNC
initperf_trace_context(void)
84 (void) Py_InitModule("perf_trace_context", ContextMethods
);
87 PyMODINIT_FUNC
PyInit_perf_trace_context(void)
89 static struct PyModuleDef moduledef
= {
90 PyModuleDef_HEAD_INIT
,
91 "perf_trace_context", /* m_name */
94 ContextMethods
, /* m_methods */
96 NULL
, /* m_traverse */
100 return PyModule_Create(&moduledef
);