History

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

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

Adrian Hunter committed 5 years ago

Commit 6337bd01 parent 4c622441 file · +17 −22Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t