perf scripting python: Simplify perf-trace-context module functions

Simplify perf-trace-context module functions by factoring out some
common code.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20210530192308.7382-3-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Adrian Hunter 2021-05-30 22:22:57 +03:00 committed by Arnaldo Carvalho de Melo
parent 4c62244e03
commit 6337bd0c91
1 changed files with 17 additions and 22 deletions

View File

@ -20,51 +20,46 @@ PyMODINIT_FUNC initperf_trace_context(void);
PyMODINIT_FUNC PyInit_perf_trace_context(void); PyMODINIT_FUNC PyInit_perf_trace_context(void);
#endif #endif
static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) static struct scripting_context *get_scripting_context(PyObject *args)
{ {
struct scripting_context *scripting_context;
PyObject *context; PyObject *context;
int retval;
if (!PyArg_ParseTuple(args, "O", &context)) if (!PyArg_ParseTuple(args, "O", &context))
return NULL; return NULL;
scripting_context = _PyCapsule_GetPointer(context, NULL); return _PyCapsule_GetPointer(context, NULL);
retval = common_pc(scripting_context); }
return Py_BuildValue("i", retval); static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
{
struct scripting_context *c = get_scripting_context(args);
if (!c)
return NULL;
return Py_BuildValue("i", common_pc(c));
} }
static PyObject *perf_trace_context_common_flags(PyObject *obj, static PyObject *perf_trace_context_common_flags(PyObject *obj,
PyObject *args) PyObject *args)
{ {
struct scripting_context *scripting_context; struct scripting_context *c = get_scripting_context(args);
PyObject *context;
int retval;
if (!PyArg_ParseTuple(args, "O", &context)) if (!c)
return NULL; return NULL;
scripting_context = _PyCapsule_GetPointer(context, NULL); return Py_BuildValue("i", common_flags(c));
retval = common_flags(scripting_context);
return Py_BuildValue("i", retval);
} }
static PyObject *perf_trace_context_common_lock_depth(PyObject *obj, static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
PyObject *args) PyObject *args)
{ {
struct scripting_context *scripting_context; struct scripting_context *c = get_scripting_context(args);
PyObject *context;
int retval;
if (!PyArg_ParseTuple(args, "O", &context)) if (!c)
return NULL; return NULL;
scripting_context = _PyCapsule_GetPointer(context, NULL); return Py_BuildValue("i", common_lock_depth(c));
retval = common_lock_depth(scripting_context);
return Py_BuildValue("i", retval);
} }
static PyMethodDef ContextMethods[] = { static PyMethodDef ContextMethods[] = {