blob: 1a0d27757eec4529539681fbf9018315b1429198 [file] [log] [blame]
Tom Zanussi7e4b21b2010-01-27 02:27:57 -06001/*
Ingo Molnar133dc4c2010-11-16 18:45:39 +01002 * Context.c. Python interfaces for perf script.
Tom Zanussi7e4b21b2010-01-27 02:27:57 -06003 *
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
Jaroslav Škarvada66dfdff2018-01-19 21:56:41 +010026#if PY_MAJOR_VERSION < 3
27#define _PyCapsule_GetPointer(arg1, arg2) \
28 PyCObject_AsVoidPtr(arg1)
29
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060030PyMODINIT_FUNC initperf_trace_context(void);
Jaroslav Škarvada66dfdff2018-01-19 21:56:41 +010031#else
32#define _PyCapsule_GetPointer(arg1, arg2) \
33 PyCapsule_GetPointer((arg1), (arg2))
34
35PyMODINIT_FUNC PyInit_perf_trace_context(void);
36#endif
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060037
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030038static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060039{
40 static struct scripting_context *scripting_context;
41 PyObject *context;
42 int retval;
43
44 if (!PyArg_ParseTuple(args, "O", &context))
45 return NULL;
46
Jaroslav Škarvada66dfdff2018-01-19 21:56:41 +010047 scripting_context = _PyCapsule_GetPointer(context, NULL);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060048 retval = common_pc(scripting_context);
49
50 return Py_BuildValue("i", retval);
51}
52
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030053static PyObject *perf_trace_context_common_flags(PyObject *obj,
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060054 PyObject *args)
55{
56 static struct scripting_context *scripting_context;
57 PyObject *context;
58 int retval;
59
60 if (!PyArg_ParseTuple(args, "O", &context))
61 return NULL;
62
Jaroslav Škarvada66dfdff2018-01-19 21:56:41 +010063 scripting_context = _PyCapsule_GetPointer(context, NULL);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060064 retval = common_flags(scripting_context);
65
66 return Py_BuildValue("i", retval);
67}
68
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -030069static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060070 PyObject *args)
71{
72 static struct scripting_context *scripting_context;
73 PyObject *context;
74 int retval;
75
76 if (!PyArg_ParseTuple(args, "O", &context))
77 return NULL;
78
Jaroslav Škarvada66dfdff2018-01-19 21:56:41 +010079 scripting_context = _PyCapsule_GetPointer(context, NULL);
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060080 retval = common_lock_depth(scripting_context);
81
82 return Py_BuildValue("i", retval);
83}
84
85static 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}
93};
94
Jaroslav Škarvada66dfdff2018-01-19 21:56:41 +010095#if PY_MAJOR_VERSION < 3
Tom Zanussi7e4b21b2010-01-27 02:27:57 -060096PyMODINIT_FUNC initperf_trace_context(void)
97{
98 (void) Py_InitModule("perf_trace_context", ContextMethods);
99}
Jaroslav Škarvada66dfdff2018-01-19 21:56:41 +0100100#else
101PyMODINIT_FUNC PyInit_perf_trace_context(void)
102{
103 static struct PyModuleDef moduledef = {
104 PyModuleDef_HEAD_INIT,
105 "perf_trace_context", /* m_name */
106 "", /* m_doc */
107 -1, /* m_size */
108 ContextMethods, /* m_methods */
109 NULL, /* m_reload */
110 NULL, /* m_traverse */
111 NULL, /* m_clear */
112 NULL, /* m_free */
113 };
114 return PyModule_Create(&moduledef);
115}
116#endif