History

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.

Adrian Hunter committed 5 years ago

Commit 7d005401 parent e621b8f1 file · +42 −2Browse 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+42−2
@@ -11,12 +11,16 @@ · 10 unmodified lines
1111 #include "../../../util/symbol.h"
1212 #include "../../../util/thread.h"
1313 #include "../../../util/maps.h"
14+#include "../../../util/auxtrace.h"
15+#include "../../../util/session.h"
1416
1517 #if PY_MAJOR_VERSION < 3
1618 #define _PyCapsule_GetPointer(arg1, arg2) \
1719 PyCObject_AsVoidPtr(arg1)
1820 #define _PyBytes_FromStringAndSize(arg1, arg2) \
1921 PyString_FromStringAndSize((arg1), (arg2))
22+#define _PyUnicode_AsUTF8(arg) \
23+ PyString_AsString(arg)
2024
2125 PyMODINIT_FUNC initperf_trace_context(void);
2226 #else
@@ -24,20 +28,28 @@ PyMODINIT_FUNC initperf_trace_context(void); · 1 unmodified line
2428 PyCapsule_GetPointer((arg1), (arg2))
2529 #define _PyBytes_FromStringAndSize(arg1, arg2) \
2630 PyBytes_FromStringAndSize((arg1), (arg2))
31+#define _PyUnicode_AsUTF8(arg) \
32+ PyUnicode_AsUTF8(arg)
2733
2834 PyMODINIT_FUNC PyInit_perf_trace_context(void);
2935 #endif
3036
31−static struct scripting_context *get_scripting_context(PyObject *args)
37+static struct scripting_context *get_args(PyObject *args, const char *name, PyObject **arg2)
3238 {
39+ int cnt = 1 + !!arg2;
3340 PyObject *context;
3441
35− if (!PyArg_ParseTuple(args, "O", &context))
42+ if (!PyArg_UnpackTuple(args, name, 1, cnt, &context, arg2))
3643 return NULL;
3744
3845 return _PyCapsule_GetPointer(context, NULL);
3946 }
4047
48+static struct scripting_context *get_scripting_context(PyObject *args)
49+{
50+ return get_args(args, "context", NULL);
51+}
52+
4153 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
4254 {
4355 struct scripting_context *c = get_scripting_context(args);
@@ -87,6 +99,32 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject *args) · 43 unmodified lines
8799 return _PyBytes_FromStringAndSize(c->sample->insn, c->sample->insn_len);
88100 }
89101
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+
90128 static PyMethodDef ContextMethods[] = {
91129 { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
92130 "Get the common preempt count event field value."},
@@ -96,6 +134,8 @@ static PyMethodDef ContextMethods[] = { · 3 unmodified lines
96134 METH_VARARGS, "Get the common lock depth event field value."},
97135 { "perf_sample_insn", perf_sample_insn,
98136 METH_VARARGS, "Get the machine code instruction."},
137+ { "perf_set_itrace_options", perf_set_itrace_options,
138+ METH_VARARGS, "Set --itrace options."},
99139 { NULL, NULL, 0, NULL}
100140 };
101141