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

perf scripting python: Add perf_set_itrace_options()

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.

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-10-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
7d00540d e621b8ff

+42 -2
+42 -2
tools/perf/scripts/python/Perf-Trace-Util/Context.c
··· 11 11 #include "../../../util/symbol.h" 12 12 #include "../../../util/thread.h" 13 13 #include "../../../util/maps.h" 14 + #include "../../../util/auxtrace.h" 15 + #include "../../../util/session.h" 14 16 15 17 #if PY_MAJOR_VERSION < 3 16 18 #define _PyCapsule_GetPointer(arg1, arg2) \ 17 19 PyCObject_AsVoidPtr(arg1) 18 20 #define _PyBytes_FromStringAndSize(arg1, arg2) \ 19 21 PyString_FromStringAndSize((arg1), (arg2)) 22 + #define _PyUnicode_AsUTF8(arg) \ 23 + PyString_AsString(arg) 20 24 21 25 PyMODINIT_FUNC initperf_trace_context(void); 22 26 #else ··· 28 24 PyCapsule_GetPointer((arg1), (arg2)) 29 25 #define _PyBytes_FromStringAndSize(arg1, arg2) \ 30 26 PyBytes_FromStringAndSize((arg1), (arg2)) 27 + #define _PyUnicode_AsUTF8(arg) \ 28 + PyUnicode_AsUTF8(arg) 31 29 32 30 PyMODINIT_FUNC PyInit_perf_trace_context(void); 33 31 #endif 34 32 35 - static struct scripting_context *get_scripting_context(PyObject *args) 33 + static struct scripting_context *get_args(PyObject *args, const char *name, PyObject **arg2) 36 34 { 35 + int cnt = 1 + !!arg2; 37 36 PyObject *context; 38 37 39 - if (!PyArg_ParseTuple(args, "O", &context)) 38 + if (!PyArg_UnpackTuple(args, name, 1, cnt, &context, arg2)) 40 39 return NULL; 41 40 42 41 return _PyCapsule_GetPointer(context, NULL); 42 + } 43 + 44 + static struct scripting_context *get_scripting_context(PyObject *args) 45 + { 46 + return get_args(args, "context", NULL); 43 47 } 44 48 45 49 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) ··· 99 87 return _PyBytes_FromStringAndSize(c->sample->insn, c->sample->insn_len); 100 88 } 101 89 90 + static PyObject *perf_set_itrace_options(PyObject *obj, PyObject *args) 91 + { 92 + struct scripting_context *c; 93 + const char *itrace_options; 94 + int retval = -1; 95 + PyObject *str; 96 + 97 + c = get_args(args, "itrace_options", &str); 98 + if (!c) 99 + return NULL; 100 + 101 + if (!c->session || !c->session->itrace_synth_opts) 102 + goto out; 103 + 104 + if (c->session->itrace_synth_opts->set) { 105 + retval = 1; 106 + goto out; 107 + } 108 + 109 + itrace_options = _PyUnicode_AsUTF8(str); 110 + 111 + retval = itrace_do_parse_synth_opts(c->session->itrace_synth_opts, itrace_options, 0); 112 + out: 113 + return Py_BuildValue("i", retval); 114 + } 115 + 102 116 static PyMethodDef ContextMethods[] = { 103 117 { "common_pc", perf_trace_context_common_pc, METH_VARARGS, 104 118 "Get the common preempt count event field value."}, ··· 134 96 METH_VARARGS, "Get the common lock depth event field value."}, 135 97 { "perf_sample_insn", perf_sample_insn, 136 98 METH_VARARGS, "Get the machine code instruction."}, 99 + { "perf_set_itrace_options", perf_set_itrace_options, 100 + METH_VARARGS, "Set --itrace options."}, 137 101 { NULL, NULL, 0, NULL} 138 102 }; 139 103