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
2020 PyMODINIT_FUNC PyInit_perf_trace_context(void);
2121 #endif
2222
23−static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
23+static struct scripting_context *get_scripting_context(PyObject *args)
2424 {
25− struct scripting_context *scripting_context;
2625 PyObject *context;
27− int retval;
2826
2927 if (!PyArg_ParseTuple(args, "O", &context))
3028 return NULL;
3129
32− scripting_context = _PyCapsule_GetPointer(context, NULL);
33− retval = common_pc(scripting_context);
30+ return _PyCapsule_GetPointer(context, NULL);
31+}
32+
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;
3439
35− return Py_BuildValue("i", retval);
40+ return Py_BuildValue("i", common_pc(c));
3641 }
3742
3843 static PyObject *perf_trace_context_common_flags(PyObject *obj,
3944 PyObject *args)
4045 {
41− struct scripting_context *scripting_context;
42− PyObject *context;
43− int retval;
46+ struct scripting_context *c = get_scripting_context(args);
4447
45− if (!PyArg_ParseTuple(args, "O", &context))
48+ if (!c)
4649 return NULL;
4750
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));
5252 }
5353
5454 static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
5555 PyObject *args)
5656 {
57− struct scripting_context *scripting_context;
58− PyObject *context;
59− int retval;
57+ struct scripting_context *c = get_scripting_context(args);
6058
61− if (!PyArg_ParseTuple(args, "O", &context))
59+ if (!c)
6260 return NULL;
6361
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));
6863 }
6964
7065 static 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