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

Configure Feed

Select the types of activity you want to include in your feed.

perf scripting python: Add perf_sample_insn()

Add perf_sample_insn() to the perf_trace_context module so that a script
can get the instruction bytes.

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-8-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
13c71b92 d9ae9c97

+27
+27
tools/perf/scripts/python/Perf-Trace-Util/Context.c
··· 7 7 8 8 #include <Python.h> 9 9 #include "../../../util/trace-event.h" 10 + #include "../../../util/event.h" 11 + #include "../../../util/symbol.h" 12 + #include "../../../util/thread.h" 13 + #include "../../../util/maps.h" 10 14 11 15 #if PY_MAJOR_VERSION < 3 12 16 #define _PyCapsule_GetPointer(arg1, arg2) \ 13 17 PyCObject_AsVoidPtr(arg1) 18 + #define _PyBytes_FromStringAndSize(arg1, arg2) \ 19 + PyString_FromStringAndSize((arg1), (arg2)) 14 20 15 21 PyMODINIT_FUNC initperf_trace_context(void); 16 22 #else 17 23 #define _PyCapsule_GetPointer(arg1, arg2) \ 18 24 PyCapsule_GetPointer((arg1), (arg2)) 25 + #define _PyBytes_FromStringAndSize(arg1, arg2) \ 26 + PyBytes_FromStringAndSize((arg1), (arg2)) 19 27 20 28 PyMODINIT_FUNC PyInit_perf_trace_context(void); 21 29 #endif ··· 70 62 return Py_BuildValue("i", common_lock_depth(c)); 71 63 } 72 64 65 + static PyObject *perf_sample_insn(PyObject *obj, PyObject *args) 66 + { 67 + struct scripting_context *c = get_scripting_context(args); 68 + 69 + if (!c) 70 + return NULL; 71 + 72 + if (c->sample->ip && !c->sample->insn_len && 73 + c->al->thread->maps && c->al->thread->maps->machine) 74 + script_fetch_insn(c->sample, c->al->thread, c->al->thread->maps->machine); 75 + 76 + if (!c->sample->insn_len) 77 + Py_RETURN_NONE; /* N.B. This is a return statement */ 78 + 79 + return _PyBytes_FromStringAndSize(c->sample->insn, c->sample->insn_len); 80 + } 81 + 73 82 static PyMethodDef ContextMethods[] = { 74 83 { "common_pc", perf_trace_context_common_pc, METH_VARARGS, 75 84 "Get the common preempt count event field value."}, ··· 94 69 "Get the common flags event field value."}, 95 70 { "common_lock_depth", perf_trace_context_common_lock_depth, 96 71 METH_VARARGS, "Get the common lock depth event field value."}, 72 + { "perf_sample_insn", perf_sample_insn, 73 + METH_VARARGS, "Get the machine code instruction."}, 97 74 { NULL, NULL, 0, NULL} 98 75 }; 99 76