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 "../../../util/trace-event.h"
11 #if PY_MAJOR_VERSION < 3
12 #define _PyCapsule_GetPointer(arg1, arg2) \
13 PyCObject_AsVoidPtr(arg1)
15 PyMODINIT_FUNC initperf_trace_context(void);
17 #define _PyCapsule_GetPointer(arg1, arg2) \
18 PyCapsule_GetPointer((arg1), (arg2))
20 PyMODINIT_FUNC PyInit_perf_trace_context(void);
23 static struct scripting_context *get_scripting_context(PyObject *args)
27 if (!PyArg_ParseTuple(args, "O", &context))
30 return _PyCapsule_GetPointer(context, NULL);
33 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
35 struct scripting_context *c = get_scripting_context(args);
40 return Py_BuildValue("i", common_pc(c));
43 static PyObject *perf_trace_context_common_flags(PyObject *obj,
46 struct scripting_context *c = get_scripting_context(args);
51 return Py_BuildValue("i", common_flags(c));
54 static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
57 struct scripting_context *c = get_scripting_context(args);
62 return Py_BuildValue("i", common_lock_depth(c));
65 static PyMethodDef ContextMethods[] = {
66 { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
67 "Get the common preempt count event field value."},
68 { "common_flags", perf_trace_context_common_flags, METH_VARARGS,
69 "Get the common flags event field value."},
70 { "common_lock_depth", perf_trace_context_common_lock_depth,
71 METH_VARARGS, "Get the common lock depth event field value."},
72 { NULL, NULL, 0, NULL}
75 #if PY_MAJOR_VERSION < 3
76 PyMODINIT_FUNC initperf_trace_context(void)
78 (void) Py_InitModule("perf_trace_context", ContextMethods);
81 PyMODINIT_FUNC PyInit_perf_trace_context(void)
83 static struct PyModuleDef moduledef = {
84 PyModuleDef_HEAD_INIT,
85 "perf_trace_context", /* m_name */
88 ContextMethods, /* m_methods */
90 NULL, /* m_traverse */
96 mod = PyModule_Create(&moduledef);
97 /* Add perf_script_context to the module so it can be imported */
98 PyObject_SetAttrString(mod, "perf_script_context", Py_None);