Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Context.c. Python interfaces for perf script.
4 *
5 * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com>
6 */
7
8#include <Python.h>
9#include "../../../util/trace-event.h"
10
11#if PY_MAJOR_VERSION < 3
12#define _PyCapsule_GetPointer(arg1, arg2) \
13 PyCObject_AsVoidPtr(arg1)
14
15PyMODINIT_FUNC initperf_trace_context(void);
16#else
17#define _PyCapsule_GetPointer(arg1, arg2) \
18 PyCapsule_GetPointer((arg1), (arg2))
19
20PyMODINIT_FUNC PyInit_perf_trace_context(void);
21#endif
22
23static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
24{
25 static struct scripting_context *scripting_context;
26 PyObject *context;
27 int retval;
28
29 if (!PyArg_ParseTuple(args, "O", &context))
30 return NULL;
31
32 scripting_context = _PyCapsule_GetPointer(context, NULL);
33 retval = common_pc(scripting_context);
34
35 return Py_BuildValue("i", retval);
36}
37
38static PyObject *perf_trace_context_common_flags(PyObject *obj,
39 PyObject *args)
40{
41 static struct scripting_context *scripting_context;
42 PyObject *context;
43 int retval;
44
45 if (!PyArg_ParseTuple(args, "O", &context))
46 return NULL;
47
48 scripting_context = _PyCapsule_GetPointer(context, NULL);
49 retval = common_flags(scripting_context);
50
51 return Py_BuildValue("i", retval);
52}
53
54static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
55 PyObject *args)
56{
57 static struct scripting_context *scripting_context;
58 PyObject *context;
59 int retval;
60
61 if (!PyArg_ParseTuple(args, "O", &context))
62 return NULL;
63
64 scripting_context = _PyCapsule_GetPointer(context, NULL);
65 retval = common_lock_depth(scripting_context);
66
67 return Py_BuildValue("i", retval);
68}
69
70static PyMethodDef ContextMethods[] = {
71 { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
72 "Get the common preempt count event field value."},
73 { "common_flags", perf_trace_context_common_flags, METH_VARARGS,
74 "Get the common flags event field value."},
75 { "common_lock_depth", perf_trace_context_common_lock_depth,
76 METH_VARARGS, "Get the common lock depth event field value."},
77 { NULL, NULL, 0, NULL}
78};
79
80#if PY_MAJOR_VERSION < 3
81PyMODINIT_FUNC initperf_trace_context(void)
82{
83 (void) Py_InitModule("perf_trace_context", ContextMethods);
84}
85#else
86PyMODINIT_FUNC PyInit_perf_trace_context(void)
87{
88 static struct PyModuleDef moduledef = {
89 PyModuleDef_HEAD_INIT,
90 "perf_trace_context", /* m_name */
91 "", /* m_doc */
92 -1, /* m_size */
93 ContextMethods, /* m_methods */
94 NULL, /* m_reload */
95 NULL, /* m_traverse */
96 NULL, /* m_clear */
97 NULL, /* m_free */
98 };
99 return PyModule_Create(&moduledef);
100}
101#endif
1/*
2 * Context.c. Python interfaces for perf script.
3 *
4 * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com>
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
22#include <Python.h>
23#include "../../../perf.h"
24#include "../../../util/trace-event.h"
25
26PyMODINIT_FUNC initperf_trace_context(void);
27
28static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
29{
30 static struct scripting_context *scripting_context;
31 PyObject *context;
32 int retval;
33
34 if (!PyArg_ParseTuple(args, "O", &context))
35 return NULL;
36
37 scripting_context = PyCObject_AsVoidPtr(context);
38 retval = common_pc(scripting_context);
39
40 return Py_BuildValue("i", retval);
41}
42
43static PyObject *perf_trace_context_common_flags(PyObject *obj,
44 PyObject *args)
45{
46 static struct scripting_context *scripting_context;
47 PyObject *context;
48 int retval;
49
50 if (!PyArg_ParseTuple(args, "O", &context))
51 return NULL;
52
53 scripting_context = PyCObject_AsVoidPtr(context);
54 retval = common_flags(scripting_context);
55
56 return Py_BuildValue("i", retval);
57}
58
59static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
60 PyObject *args)
61{
62 static struct scripting_context *scripting_context;
63 PyObject *context;
64 int retval;
65
66 if (!PyArg_ParseTuple(args, "O", &context))
67 return NULL;
68
69 scripting_context = PyCObject_AsVoidPtr(context);
70 retval = common_lock_depth(scripting_context);
71
72 return Py_BuildValue("i", retval);
73}
74
75static PyMethodDef ContextMethods[] = {
76 { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
77 "Get the common preempt count event field value."},
78 { "common_flags", perf_trace_context_common_flags, METH_VARARGS,
79 "Get the common flags event field value."},
80 { "common_lock_depth", perf_trace_context_common_lock_depth,
81 METH_VARARGS, "Get the common lock depth event field value."},
82 { NULL, NULL, 0, NULL}
83};
84
85PyMODINIT_FUNC initperf_trace_context(void)
86{
87 (void) Py_InitModule("perf_trace_context", ContextMethods);
88}