Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
6337bd0c 4c62244e

+17 -22
+17 -22
tools/perf/scripts/python/Perf-Trace-Util/Context.c
··· 20 20 PyMODINIT_FUNC PyInit_perf_trace_context(void); 21 21 #endif 22 22 23 - static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) 23 + static struct scripting_context *get_scripting_context(PyObject *args) 24 24 { 25 - struct scripting_context *scripting_context; 26 25 PyObject *context; 27 - int retval; 28 26 29 27 if (!PyArg_ParseTuple(args, "O", &context)) 30 28 return NULL; 31 29 32 - scripting_context = _PyCapsule_GetPointer(context, NULL); 33 - retval = common_pc(scripting_context); 30 + return _PyCapsule_GetPointer(context, NULL); 31 + } 34 32 35 - return Py_BuildValue("i", retval); 33 + static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) 34 + { 35 + struct scripting_context *c = get_scripting_context(args); 36 + 37 + if (!c) 38 + return NULL; 39 + 40 + return Py_BuildValue("i", common_pc(c)); 36 41 } 37 42 38 43 static PyObject *perf_trace_context_common_flags(PyObject *obj, 39 44 PyObject *args) 40 45 { 41 - struct scripting_context *scripting_context; 42 - PyObject *context; 43 - int retval; 46 + struct scripting_context *c = get_scripting_context(args); 44 47 45 - if (!PyArg_ParseTuple(args, "O", &context)) 48 + if (!c) 46 49 return NULL; 47 50 48 - scripting_context = _PyCapsule_GetPointer(context, NULL); 49 - retval = common_flags(scripting_context); 50 - 51 - return Py_BuildValue("i", retval); 51 + return Py_BuildValue("i", common_flags(c)); 52 52 } 53 53 54 54 static PyObject *perf_trace_context_common_lock_depth(PyObject *obj, 55 55 PyObject *args) 56 56 { 57 - struct scripting_context *scripting_context; 58 - PyObject *context; 59 - int retval; 57 + struct scripting_context *c = get_scripting_context(args); 60 58 61 - if (!PyArg_ParseTuple(args, "O", &context)) 59 + if (!c) 62 60 return NULL; 63 61 64 - scripting_context = _PyCapsule_GetPointer(context, NULL); 65 - retval = common_lock_depth(scripting_context); 66 - 67 - return Py_BuildValue("i", retval); 62 + return Py_BuildValue("i", common_lock_depth(c)); 68 63 } 69 64 70 65 static PyMethodDef ContextMethods[] = {