Add perf_set_itrace_options() to the perf_trace_context module so that a script can set the itrace options for a session if they have not been set already.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -11,12 +11,16 @@ · 10 unmodified lines | |||
| 11 | #include "../../../util/symbol.h" | 11 | #include "../../../util/symbol.h" |
| 12 | #include "../../../util/thread.h" | 12 | #include "../../../util/thread.h" |
| 13 | #include "../../../util/maps.h" | 13 | #include "../../../util/maps.h" |
| 14 | #include "../../../util/auxtrace.h" | ||
| 15 | #include "../../../util/session.h" | ||
| 14 | 16 | ||
| 15 | #if PY_MAJOR_VERSION < 3 | 17 | #if PY_MAJOR_VERSION < 3 |
| 16 | #define _PyCapsule_GetPointer(arg1, arg2) \ | 18 | #define _PyCapsule_GetPointer(arg1, arg2) \ |
| 17 | PyCObject_AsVoidPtr(arg1) | 19 | PyCObject_AsVoidPtr(arg1) |
| 18 | #define _PyBytes_FromStringAndSize(arg1, arg2) \ | 20 | #define _PyBytes_FromStringAndSize(arg1, arg2) \ |
| 19 | PyString_FromStringAndSize((arg1), (arg2)) | 21 | PyString_FromStringAndSize((arg1), (arg2)) |
| 22 | #define _PyUnicode_AsUTF8(arg) \ | ||
| 23 | PyString_AsString(arg) | ||
| 20 | 24 | ||
| 21 | PyMODINIT_FUNC initperf_trace_context(void); | 25 | PyMODINIT_FUNC initperf_trace_context(void); |
| 22 | #else | 26 | #else |
| @@ -24,20 +28,28 @@ PyMODINIT_FUNC initperf_trace_context(void); · 1 unmodified line | |||
| 24 | PyCapsule_GetPointer((arg1), (arg2)) | 28 | PyCapsule_GetPointer((arg1), (arg2)) |
| 25 | #define _PyBytes_FromStringAndSize(arg1, arg2) \ | 29 | #define _PyBytes_FromStringAndSize(arg1, arg2) \ |
| 26 | PyBytes_FromStringAndSize((arg1), (arg2)) | 30 | PyBytes_FromStringAndSize((arg1), (arg2)) |
| 31 | #define _PyUnicode_AsUTF8(arg) \ | ||
| 32 | PyUnicode_AsUTF8(arg) | ||
| 27 | 33 | ||
| 28 | PyMODINIT_FUNC PyInit_perf_trace_context(void); | 34 | PyMODINIT_FUNC PyInit_perf_trace_context(void); |
| 29 | #endif | 35 | #endif |
| 30 | 36 | ||
| 31 | static struct scripting_context *get_scripting_context(PyObject *args) | 37 | static struct scripting_context *get_args(PyObject *args, const char *name, PyObject **arg2) |
| 32 | { | 38 | { |
| 39 | int cnt = 1 + !!arg2; | ||
| 33 | PyObject *context; | 40 | PyObject *context; |
| 34 | 41 | ||
| 35 | if (!PyArg_ParseTuple(args, "O", &context)) | 42 | if (!PyArg_UnpackTuple(args, name, 1, cnt, &context, arg2)) |
| 36 | return NULL; | 43 | return NULL; |
| 37 | 44 | ||
| 38 | return _PyCapsule_GetPointer(context, NULL); | 45 | return _PyCapsule_GetPointer(context, NULL); |
| 39 | } | 46 | } |
| 40 | 47 | ||
| 48 | static struct scripting_context *get_scripting_context(PyObject *args) | ||
| 49 | { | ||
| 50 | return get_args(args, "context", NULL); | ||
| 51 | } | ||
| 52 | |||
| 41 | static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) | 53 | static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) |
| 42 | { | 54 | { |
| 43 | struct scripting_context *c = get_scripting_context(args); | 55 | struct scripting_context *c = get_scripting_context(args); |
| @@ -87,6 +99,32 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject *args) · 43 unmodified lines | |||
| 87 | return _PyBytes_FromStringAndSize(c->sample->insn, c->sample->insn_len); | 99 | return _PyBytes_FromStringAndSize(c->sample->insn, c->sample->insn_len); |
| 88 | } | 100 | } |
| 89 | 101 | ||
| 102 | static PyObject *perf_set_itrace_options(PyObject *obj, PyObject *args) | ||
| 103 | { | ||
| 104 | struct scripting_context *c; | ||
| 105 | const char *itrace_options; | ||
| 106 | int retval = -1; | ||
| 107 | PyObject *str; | ||
| 108 | |||
| 109 | c = get_args(args, "itrace_options", &str); | ||
| 110 | if (!c) | ||
| 111 | return NULL; | ||
| 112 | |||
| 113 | if (!c->session || !c->session->itrace_synth_opts) | ||
| 114 | goto out; | ||
| 115 | |||
| 116 | if (c->session->itrace_synth_opts->set) { | ||
| 117 | retval = 1; | ||
| 118 | goto out; | ||
| 119 | } | ||
| 120 | |||
| 121 | itrace_options = _PyUnicode_AsUTF8(str); | ||
| 122 | |||
| 123 | retval = itrace_do_parse_synth_opts(c->session->itrace_synth_opts, itrace_options, 0); | ||
| 124 | out: | ||
| 125 | return Py_BuildValue("i", retval); | ||
| 126 | } | ||
| 127 | |||
| 90 | static PyMethodDef ContextMethods[] = { | 128 | static PyMethodDef ContextMethods[] = { |
| 91 | { "common_pc", perf_trace_context_common_pc, METH_VARARGS, | 129 | { "common_pc", perf_trace_context_common_pc, METH_VARARGS, |
| 92 | "Get the common preempt count event field value."}, | 130 | "Get the common preempt count event field value."}, |
| @@ -96,6 +134,8 @@ static PyMethodDef ContextMethods[] = { · 3 unmodified lines | |||
| 96 | METH_VARARGS, "Get the common lock depth event field value."}, | 134 | METH_VARARGS, "Get the common lock depth event field value."}, |
| 97 | { "perf_sample_insn", perf_sample_insn, | 135 | { "perf_sample_insn", perf_sample_insn, |
| 98 | METH_VARARGS, "Get the machine code instruction."}, | 136 | METH_VARARGS, "Get the machine code instruction."}, |
| 137 | { "perf_set_itrace_options", perf_set_itrace_options, | ||
| 138 | METH_VARARGS, "Set --itrace options."}, | ||
| 99 | { NULL, NULL, 0, NULL} | 139 | { NULL, NULL, 0, NULL} |
| 100 | }; | 140 | }; |
| 101 | 141 | ||