linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] perf scripting python: Add insn, srcline and srccode
@ 2021-05-30 19:22 Adrian Hunter
  2021-05-30 19:22 ` [PATCH 01/13] perf scripting python: Remove unnecessary 'static' Adrian Hunter
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Hi

Here are some patches to add insn, srcline and srccode to python scripting.
In addition, it is made possible for a script to set itrace options.

The first 2 patches are minor tidy-ups.  The next 3 are additions to
scripting_context. The next 5 add new methods that python scripts can call.

Then there is a patch to the perf scripting python documentation.

And finally 2 patches add to the intel-pt-events.py script as an example.


Adrian Hunter (13):
      perf scripting python: Remove unnecessary 'static'
      perf scripting python: Simplify perf-trace-context module functions
      perf scripting: Add scripting_context__update()
      perf scripting: Add perf_session to scripting_context
      perf scripting python: Assign perf_script_context
      perf script: Factor out script_fetch_insn()
      perf scripting python: Add perf_sample_insn()
      perf auxtrace: Factor out itrace_do_parse_synth_opts()
      perf scripting python: Add perf_set_itrace_options()
      perf scripting python: Add perf_sample_srcline() and perf_sample_srccode()
      perf scripting python: Update documentation for srcline etc
      perf scripting python: exported-sql-viewer.py: Factor out libxed.py
      perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace

 tools/perf/Documentation/perf-intel-pt.txt         |   6 +-
 tools/perf/Documentation/perf-script-python.txt    |  46 +++++-
 tools/perf/builtin-script.c                        |  12 +-
 .../perf/scripts/python/Perf-Trace-Util/Context.c  | 168 +++++++++++++++++---
 tools/perf/scripts/python/exported-sql-viewer.py   |  89 +----------
 tools/perf/scripts/python/intel-pt-events.py       | 176 ++++++++++++++++++---
 tools/perf/scripts/python/libxed.py                | 107 +++++++++++++
 tools/perf/util/auxtrace.c                         |  10 +-
 tools/perf/util/auxtrace.h                         |  10 ++
 .../perf/util/scripting-engines/trace-event-perl.c |  11 +-
 .../util/scripting-engines/trace-event-python.c    |  37 ++++-
 tools/perf/util/trace-event-scripting.c            |  27 +++-
 tools/perf/util/trace-event.h                      |  20 ++-
 13 files changed, 568 insertions(+), 151 deletions(-)
 create mode 100644 tools/perf/scripts/python/libxed.py


Regards
Adrian

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 01/13] perf scripting python: Remove unnecessary 'static'
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
@ 2021-05-30 19:22 ` Adrian Hunter
  2021-05-30 19:22 ` [PATCH 02/13] perf scripting python: Simplify perf-trace-context module functions Adrian Hunter
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

The variables are always assigned before use, making the 'static'
storage class unnecessary.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/scripts/python/Perf-Trace-Util/Context.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 0b7096847991..fdf692d1e8f3 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -22,7 +22,7 @@ PyMODINIT_FUNC PyInit_perf_trace_context(void);
 
 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
 {
-	static struct scripting_context *scripting_context;
+	struct scripting_context *scripting_context;
 	PyObject *context;
 	int retval;
 
@@ -38,7 +38,7 @@ static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
 static PyObject *perf_trace_context_common_flags(PyObject *obj,
 						 PyObject *args)
 {
-	static struct scripting_context *scripting_context;
+	struct scripting_context *scripting_context;
 	PyObject *context;
 	int retval;
 
@@ -54,7 +54,7 @@ static PyObject *perf_trace_context_common_flags(PyObject *obj,
 static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
 						      PyObject *args)
 {
-	static struct scripting_context *scripting_context;
+	struct scripting_context *scripting_context;
 	PyObject *context;
 	int retval;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 02/13] perf scripting python: Simplify perf-trace-context module functions
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
  2021-05-30 19:22 ` [PATCH 01/13] perf scripting python: Remove unnecessary 'static' Adrian Hunter
@ 2021-05-30 19:22 ` Adrian Hunter
  2021-05-30 19:22 ` [PATCH 03/13] perf scripting: Add scripting_context__update() Adrian Hunter
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Simplify perf-trace-context module functions by factoring out some
common code.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../scripts/python/Perf-Trace-Util/Context.c  | 39 ++++++++-----------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index fdf692d1e8f3..7cef02d75bc7 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -20,51 +20,46 @@ PyMODINIT_FUNC initperf_trace_context(void);
 PyMODINIT_FUNC PyInit_perf_trace_context(void);
 #endif
 
-static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
+static struct scripting_context *get_scripting_context(PyObject *args)
 {
-	struct scripting_context *scripting_context;
 	PyObject *context;
-	int retval;
 
 	if (!PyArg_ParseTuple(args, "O", &context))
 		return NULL;
 
-	scripting_context = _PyCapsule_GetPointer(context, NULL);
-	retval = common_pc(scripting_context);
+	return _PyCapsule_GetPointer(context, NULL);
+}
+
+static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
+{
+	struct scripting_context *c = get_scripting_context(args);
+
+	if (!c)
+		return NULL;
 
-	return Py_BuildValue("i", retval);
+	return Py_BuildValue("i", common_pc(c));
 }
 
 static PyObject *perf_trace_context_common_flags(PyObject *obj,
 						 PyObject *args)
 {
-	struct scripting_context *scripting_context;
-	PyObject *context;
-	int retval;
+	struct scripting_context *c = get_scripting_context(args);
 
-	if (!PyArg_ParseTuple(args, "O", &context))
+	if (!c)
 		return NULL;
 
-	scripting_context = _PyCapsule_GetPointer(context, NULL);
-	retval = common_flags(scripting_context);
-
-	return Py_BuildValue("i", retval);
+	return Py_BuildValue("i", common_flags(c));
 }
 
 static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
 						      PyObject *args)
 {
-	struct scripting_context *scripting_context;
-	PyObject *context;
-	int retval;
+	struct scripting_context *c = get_scripting_context(args);
 
-	if (!PyArg_ParseTuple(args, "O", &context))
+	if (!c)
 		return NULL;
 
-	scripting_context = _PyCapsule_GetPointer(context, NULL);
-	retval = common_lock_depth(scripting_context);
-
-	return Py_BuildValue("i", retval);
+	return Py_BuildValue("i", common_lock_depth(c));
 }
 
 static PyMethodDef ContextMethods[] = {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 03/13] perf scripting: Add scripting_context__update()
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
  2021-05-30 19:22 ` [PATCH 01/13] perf scripting python: Remove unnecessary 'static' Adrian Hunter
  2021-05-30 19:22 ` [PATCH 02/13] perf scripting python: Simplify perf-trace-context module functions Adrian Hunter
@ 2021-05-30 19:22 ` Adrian Hunter
  2021-05-30 19:22 ` [PATCH 04/13] perf scripting: Add perf_session to scripting_context Adrian Hunter
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Move scripting_context update to a separate function and add
the arguments of ->process_event() to it.

This prepares the way for adding more methods to the perf_trace_context
module, by providing the context information that they will need.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../util/scripting-engines/trace-event-perl.c |  6 ++----
 .../scripting-engines/trace-event-python.c    |  5 ++---
 tools/perf/util/trace-event-scripting.c       | 21 +++++++++++++++++++
 tools/perf/util/trace-event.h                 | 13 ++++++++++++
 4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index a837aee24674..5bbf00c1179f 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -371,9 +371,6 @@ static void perl_process_tracepoint(struct perf_sample *sample,
 	s = nsecs / NSEC_PER_SEC;
 	ns = nsecs - s * NSEC_PER_SEC;
 
-	scripting_context->event_data = data;
-	scripting_context->pevent = evsel->tp_format->tep;
-
 	ENTER;
 	SAVETMPS;
 	PUSHMARK(SP);
@@ -457,8 +454,9 @@ static void perl_process_event(union perf_event *event,
 			       struct perf_sample *sample,
 			       struct evsel *evsel,
 			       struct addr_location *al,
-			       struct addr_location *addr_al __maybe_unused)
+			       struct addr_location *addr_al)
 {
+	scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);
 	perl_process_tracepoint(sample, evsel, al);
 	perl_process_event_generic(event, sample, evsel);
 }
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index ffc5f4cffdba..d99f71916af7 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -897,9 +897,6 @@ static void python_process_tracepoint(struct perf_sample *sample,
 	s = nsecs / NSEC_PER_SEC;
 	ns = nsecs - s * NSEC_PER_SEC;
 
-	scripting_context->event_data = data;
-	scripting_context->pevent = evsel->tp_format->tep;
-
 	context = _PyCapsule_New(scripting_context, NULL, NULL);
 
 	PyTuple_SetItem(t, n++, _PyUnicode_FromString(handler_name));
@@ -1403,6 +1400,8 @@ static void python_process_event(union perf_event *event,
 {
 	struct tables *tables = &tables_global;
 
+	scripting_context__update(scripting_context, event, sample, evsel, al, addr_al);
+
 	switch (evsel->core.attr.type) {
 	case PERF_TYPE_TRACEPOINT:
 		python_process_tracepoint(sample, evsel, al, addr_al);
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 6c51fba70d49..a2f0c1e460a2 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -12,10 +12,31 @@
 
 #include "debug.h"
 #include "trace-event.h"
+#include "event.h"
+#include "evsel.h"
 #include <linux/zalloc.h>
 
 struct scripting_context *scripting_context;
 
+void scripting_context__update(struct scripting_context *c,
+			       union perf_event *event,
+			       struct perf_sample *sample,
+			       struct evsel *evsel,
+			       struct addr_location *al,
+			       struct addr_location *addr_al)
+{
+	c->event_data = sample->raw_data;
+	if (evsel->tp_format)
+		c->pevent = evsel->tp_format->tep;
+	else
+		c->pevent = NULL;
+	c->event = event;
+	c->sample = sample;
+	c->evsel = evsel;
+	c->al = al;
+	c->addr_al = addr_al;
+}
+
 static int flush_script_unsupported(void)
 {
 	return 0;
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 35c354a15c3a..a939318b88a6 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -11,6 +11,7 @@ union perf_event;
 struct perf_tool;
 struct thread;
 struct tep_plugin_list;
+struct evsel;
 
 struct trace_event {
 	struct tep_handle	*pevent;
@@ -101,8 +102,20 @@ void setup_python_scripting(void);
 struct scripting_context {
 	struct tep_handle *pevent;
 	void *event_data;
+	union perf_event *event;
+	struct perf_sample *sample;
+	struct evsel *evsel;
+	struct addr_location *al;
+	struct addr_location *addr_al;
 };
 
+void scripting_context__update(struct scripting_context *scripting_context,
+			       union perf_event *event,
+			       struct perf_sample *sample,
+			       struct evsel *evsel,
+			       struct addr_location *al,
+			       struct addr_location *addr_al);
+
 int common_pc(struct scripting_context *context);
 int common_flags(struct scripting_context *context);
 int common_lock_depth(struct scripting_context *context);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 04/13] perf scripting: Add perf_session to scripting_context
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (2 preceding siblings ...)
  2021-05-30 19:22 ` [PATCH 03/13] perf scripting: Add scripting_context__update() Adrian Hunter
@ 2021-05-30 19:22 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 05/13] perf scripting python: Assign perf_script_context Adrian Hunter
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:22 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

This is preparation for allowing a script to set the itrace options
for the session if they have not already been set.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-script.c                            | 2 +-
 tools/perf/util/scripting-engines/trace-event-perl.c   | 5 ++++-
 tools/perf/util/scripting-engines/trace-event-python.c | 4 +++-
 tools/perf/util/trace-event-scripting.c                | 6 ++++--
 tools/perf/util/trace-event.h                          | 4 +++-
 5 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 7a7a19f52db5..fd5c257d55a8 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -4017,7 +4017,7 @@ int cmd_script(int argc, const char **argv)
 	}
 
 	if (script_name) {
-		err = scripting_ops->start_script(script_name, argc, argv);
+		err = scripting_ops->start_script(script_name, argc, argv, session);
 		if (err)
 			goto out_delete;
 		pr_debug("perf script started with script %s\n\n", script_name);
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 5bbf00c1179f..32a721b3e9a5 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -473,11 +473,14 @@ static void run_start_sub(void)
 /*
  * Start trace script
  */
-static int perl_start_script(const char *script, int argc, const char **argv)
+static int perl_start_script(const char *script, int argc, const char **argv,
+			     struct perf_session *session)
 {
 	const char **command_line;
 	int i, err = 0;
 
+	scripting_context->session = session;
+
 	command_line = malloc((argc + 2) * sizeof(const char *));
 	command_line[0] = "";
 	command_line[1] = script;
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index d99f71916af7..02d134b6ba8d 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1746,7 +1746,8 @@ static void _free_command_line(wchar_t **command_line, int num)
 /*
  * Start trace script
  */
-static int python_start_script(const char *script, int argc, const char **argv)
+static int python_start_script(const char *script, int argc, const char **argv,
+			       struct perf_session *session)
 {
 	struct tables *tables = &tables_global;
 #if PY_MAJOR_VERSION < 3
@@ -1762,6 +1763,7 @@ static int python_start_script(const char *script, int argc, const char **argv)
 	int i, err = 0;
 	FILE *fp;
 
+	scripting_context->session = session;
 #if PY_MAJOR_VERSION < 3
 	command_line = malloc((argc + 1) * sizeof(const char *));
 	command_line[0] = script;
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index a2f0c1e460a2..7172ca05265f 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -66,7 +66,8 @@ static void print_python_unsupported_msg(void)
 
 static int python_start_script_unsupported(const char *script __maybe_unused,
 					   int argc __maybe_unused,
-					   const char **argv __maybe_unused)
+					   const char **argv __maybe_unused,
+					   struct perf_session *session __maybe_unused)
 {
 	print_python_unsupported_msg();
 
@@ -131,7 +132,8 @@ static void print_perl_unsupported_msg(void)
 
 static int perl_start_script_unsupported(const char *script __maybe_unused,
 					 int argc __maybe_unused,
-					 const char **argv __maybe_unused)
+					 const char **argv __maybe_unused,
+					 struct perf_session *session __maybe_unused)
 {
 	print_perl_unsupported_msg();
 
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index a939318b88a6..73f5b29472f7 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -73,7 +73,8 @@ struct perf_stat_config;
 struct scripting_ops {
 	const char *name;
 	const char *dirname; /* For script path .../scripts/<dirname>/... */
-	int (*start_script) (const char *script, int argc, const char **argv);
+	int (*start_script)(const char *script, int argc, const char **argv,
+			    struct perf_session *session);
 	int (*flush_script) (void);
 	int (*stop_script) (void);
 	void (*process_event) (union perf_event *event,
@@ -107,6 +108,7 @@ struct scripting_context {
 	struct evsel *evsel;
 	struct addr_location *al;
 	struct addr_location *addr_al;
+	struct perf_session *session;
 };
 
 void scripting_context__update(struct scripting_context *scripting_context,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 05/13] perf scripting python: Assign perf_script_context
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (3 preceding siblings ...)
  2021-05-30 19:22 ` [PATCH 04/13] perf scripting: Add perf_session to scripting_context Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 06/13] perf script: Factor out script_fetch_insn() Adrian Hunter
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

The scripting_context pointer itself does not change and nor does it need
to. Put it directly into the script as a variable at the start so it does
not have to be passed on each call into the script.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../scripts/python/Perf-Trace-Util/Context.c  |  8 +++++-
 .../scripting-engines/trace-event-python.c    | 28 +++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 7cef02d75bc7..26a45ae78be4 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -91,6 +91,12 @@ PyMODINIT_FUNC PyInit_perf_trace_context(void)
 		NULL,			/* m_clear */
 		NULL,			/* m_free */
 	};
-	return PyModule_Create(&moduledef);
+	PyObject *mod;
+
+	mod = PyModule_Create(&moduledef);
+	/* Add perf_script_context to the module so it can be imported */
+	PyObject_SetAttrString(mod, "perf_script_context", Py_None);
+
+	return mod;
 }
 #endif
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 02d134b6ba8d..164d2f45028c 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1599,6 +1599,31 @@ static void python_process_stat_interval(u64 tstamp)
 	Py_DECREF(t);
 }
 
+static int perf_script_context_init(void)
+{
+	PyObject *perf_script_context;
+	PyObject *perf_trace_context;
+	PyObject *dict;
+	int ret;
+
+	perf_trace_context = PyImport_AddModule("perf_trace_context");
+	if (!perf_trace_context)
+		return -1;
+	dict = PyModule_GetDict(perf_trace_context);
+	if (!dict)
+		return -1;
+
+	perf_script_context = _PyCapsule_New(scripting_context, NULL, NULL);
+	if (!perf_script_context)
+		return -1;
+
+	ret = PyDict_SetItemString(dict, "perf_script_context", perf_script_context);
+	if (!ret)
+		ret = PyDict_SetItemString(main_dict, "perf_script_context", perf_script_context);
+	Py_DECREF(perf_script_context);
+	return ret;
+}
+
 static int run_start_sub(void)
 {
 	main_module = PyImport_AddModule("__main__");
@@ -1611,6 +1636,9 @@ static int run_start_sub(void)
 		goto error;
 	Py_INCREF(main_dict);
 
+	if (perf_script_context_init())
+		goto error;
+
 	try_call_object("trace_begin", NULL);
 
 	return 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 06/13] perf script: Factor out script_fetch_insn()
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (4 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 05/13] perf scripting python: Assign perf_script_context Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 07/13] perf scripting python: Add perf_sample_insn() Adrian Hunter
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Factor out script_fetch_insn() so it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-script.c   | 10 ++++++++--
 tools/perf/util/trace-event.h |  3 +++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index fd5c257d55a8..57488d60b64a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1417,6 +1417,13 @@ __weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused,
 {
 }
 
+void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
+		       struct machine *machine)
+{
+	if (sample->insn_len == 0 && native_arch)
+		arch_fetch_insn(sample, thread, machine);
+}
+
 static int perf_sample__fprintf_insn(struct perf_sample *sample,
 				     struct perf_event_attr *attr,
 				     struct thread *thread,
@@ -1424,8 +1431,7 @@ static int perf_sample__fprintf_insn(struct perf_sample *sample,
 {
 	int printed = 0;
 
-	if (sample->insn_len == 0 && native_arch)
-		arch_fetch_insn(sample, thread, machine);
+	script_fetch_insn(sample, thread, machine);
 
 	if (PRINT_FIELD(INSNLEN))
 		printed += fprintf(fp, " ilen: %d", sample->insn_len);
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 73f5b29472f7..54aadeedf28c 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -97,6 +97,9 @@ extern unsigned int scripting_max_stack;
 
 int script_spec_register(const char *spec, struct scripting_ops *ops);
 
+void script_fetch_insn(struct perf_sample *sample, struct thread *thread,
+		       struct machine *machine);
+
 void setup_perl_scripting(void);
 void setup_python_scripting(void);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 07/13] perf scripting python: Add perf_sample_insn()
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (5 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 06/13] perf script: Factor out script_fetch_insn() Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 08/13] perf auxtrace: Factor out itrace_do_parse_synth_opts() Adrian Hunter
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

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>
---
 .../scripts/python/Perf-Trace-Util/Context.c  | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 26a45ae78be4..d7f044259f9b 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -7,15 +7,23 @@
 
 #include <Python.h>
 #include "../../../util/trace-event.h"
+#include "../../../util/event.h"
+#include "../../../util/symbol.h"
+#include "../../../util/thread.h"
+#include "../../../util/maps.h"
 
 #if PY_MAJOR_VERSION < 3
 #define _PyCapsule_GetPointer(arg1, arg2) \
   PyCObject_AsVoidPtr(arg1)
+#define _PyBytes_FromStringAndSize(arg1, arg2) \
+  PyString_FromStringAndSize((arg1), (arg2))
 
 PyMODINIT_FUNC initperf_trace_context(void);
 #else
 #define _PyCapsule_GetPointer(arg1, arg2) \
   PyCapsule_GetPointer((arg1), (arg2))
+#define _PyBytes_FromStringAndSize(arg1, arg2) \
+  PyBytes_FromStringAndSize((arg1), (arg2))
 
 PyMODINIT_FUNC PyInit_perf_trace_context(void);
 #endif
@@ -62,6 +70,23 @@ static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
 	return Py_BuildValue("i", common_lock_depth(c));
 }
 
+static PyObject *perf_sample_insn(PyObject *obj, PyObject *args)
+{
+	struct scripting_context *c = get_scripting_context(args);
+
+	if (!c)
+		return NULL;
+
+	if (c->sample->ip && !c->sample->insn_len &&
+	    c->al->thread->maps && c->al->thread->maps->machine)
+		script_fetch_insn(c->sample, c->al->thread, c->al->thread->maps->machine);
+
+	if (!c->sample->insn_len)
+		Py_RETURN_NONE; /* N.B. This is a return statement */
+
+	return _PyBytes_FromStringAndSize(c->sample->insn, c->sample->insn_len);
+}
+
 static PyMethodDef ContextMethods[] = {
 	{ "common_pc", perf_trace_context_common_pc, METH_VARARGS,
 	  "Get the common preempt count event field value."},
@@ -69,6 +94,8 @@ static PyMethodDef ContextMethods[] = {
 	  "Get the common flags event field value."},
 	{ "common_lock_depth", perf_trace_context_common_lock_depth,
 	  METH_VARARGS,	"Get the common lock depth event field value."},
+	{ "perf_sample_insn", perf_sample_insn,
+	  METH_VARARGS,	"Get the machine code instruction."},
 	{ NULL, NULL, 0, NULL}
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 08/13] perf auxtrace: Factor out itrace_do_parse_synth_opts()
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (6 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 07/13] perf scripting python: Add perf_sample_insn() Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 09/13] perf scripting python: Add perf_set_itrace_options() Adrian Hunter
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Factor out itrace_do_parse_synth_opts() so that it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/auxtrace.c | 10 +++++++---
 tools/perf/util/auxtrace.h | 10 ++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 62268f8b6c4f..9350eeb3a3fc 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -1405,10 +1405,9 @@ static int get_flags(const char **ptr, unsigned int *plus_flags, unsigned int *m
  * about the options parsed here, which is introduced after this cset,
  * when support in 'perf script' for these options is introduced.
  */
-int itrace_parse_synth_opts(const struct option *opt, const char *str,
-			    int unset)
+int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
+			       const char *str, int unset)
 {
-	struct itrace_synth_opts *synth_opts = opt->value;
 	const char *p;
 	char *endptr;
 	bool period_type_set = false;
@@ -1596,6 +1595,11 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,
 	return -EINVAL;
 }
 
+int itrace_parse_synth_opts(const struct option *opt, const char *str, int unset)
+{
+	return itrace_do_parse_synth_opts(opt->value, str, unset);
+}
+
 static const char * const auxtrace_error_type_name[] = {
 	[PERF_AUXTRACE_ERROR_ITRACE] = "instruction trace",
 };
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 4283a4befcb6..efca761e8b84 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -607,6 +607,8 @@ s64 perf_event__process_auxtrace(struct perf_session *session,
 				 union perf_event *event);
 int perf_event__process_auxtrace_error(struct perf_session *session,
 				       union perf_event *event);
+int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
+			       const char *str, int unset);
 int itrace_parse_synth_opts(const struct option *opt, const char *str,
 			    int unset);
 void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
@@ -738,6 +740,14 @@ void events_stats__auxtrace_error_warn(const struct events_stats *stats
 {
 }
 
+static inline
+int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts __maybe_unused,
+			       const char *str __maybe_unused, int unset __maybe_unused)
+{
+	pr_err("AUX area tracing not supported\n");
+	return -EINVAL;
+}
+
 static inline
 int itrace_parse_synth_opts(const struct option *opt __maybe_unused,
 			    const char *str __maybe_unused,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 09/13] perf scripting python: Add perf_set_itrace_options()
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (7 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 08/13] perf auxtrace: Factor out itrace_do_parse_synth_opts() Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 10/13] perf scripting python: Add perf_sample_srcline() and perf_sample_srccode() Adrian Hunter
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

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>
---
 .../scripts/python/Perf-Trace-Util/Context.c  | 44 ++++++++++++++++++-
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index d7f044259f9b..3c9bc12a1332 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -11,12 +11,16 @@
 #include "../../../util/symbol.h"
 #include "../../../util/thread.h"
 #include "../../../util/maps.h"
+#include "../../../util/auxtrace.h"
+#include "../../../util/session.h"
 
 #if PY_MAJOR_VERSION < 3
 #define _PyCapsule_GetPointer(arg1, arg2) \
   PyCObject_AsVoidPtr(arg1)
 #define _PyBytes_FromStringAndSize(arg1, arg2) \
   PyString_FromStringAndSize((arg1), (arg2))
+#define _PyUnicode_AsUTF8(arg) \
+  PyString_AsString(arg)
 
 PyMODINIT_FUNC initperf_trace_context(void);
 #else
@@ -24,20 +28,28 @@ PyMODINIT_FUNC initperf_trace_context(void);
   PyCapsule_GetPointer((arg1), (arg2))
 #define _PyBytes_FromStringAndSize(arg1, arg2) \
   PyBytes_FromStringAndSize((arg1), (arg2))
+#define _PyUnicode_AsUTF8(arg) \
+  PyUnicode_AsUTF8(arg)
 
 PyMODINIT_FUNC PyInit_perf_trace_context(void);
 #endif
 
-static struct scripting_context *get_scripting_context(PyObject *args)
+static struct scripting_context *get_args(PyObject *args, const char *name, PyObject **arg2)
 {
+	int cnt = 1 + !!arg2;
 	PyObject *context;
 
-	if (!PyArg_ParseTuple(args, "O", &context))
+	if (!PyArg_UnpackTuple(args, name, 1, cnt, &context, arg2))
 		return NULL;
 
 	return _PyCapsule_GetPointer(context, NULL);
 }
 
+static struct scripting_context *get_scripting_context(PyObject *args)
+{
+	return get_args(args, "context", NULL);
+}
+
 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
 {
 	struct scripting_context *c = get_scripting_context(args);
@@ -87,6 +99,32 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject *args)
 	return _PyBytes_FromStringAndSize(c->sample->insn, c->sample->insn_len);
 }
 
+static PyObject *perf_set_itrace_options(PyObject *obj, PyObject *args)
+{
+	struct scripting_context *c;
+	const char *itrace_options;
+	int retval = -1;
+	PyObject *str;
+
+	c = get_args(args, "itrace_options", &str);
+	if (!c)
+		return NULL;
+
+	if (!c->session || !c->session->itrace_synth_opts)
+		goto out;
+
+	if (c->session->itrace_synth_opts->set) {
+		retval = 1;
+		goto out;
+	}
+
+	itrace_options = _PyUnicode_AsUTF8(str);
+
+	retval = itrace_do_parse_synth_opts(c->session->itrace_synth_opts, itrace_options, 0);
+out:
+	return Py_BuildValue("i", retval);
+}
+
 static PyMethodDef ContextMethods[] = {
 	{ "common_pc", perf_trace_context_common_pc, METH_VARARGS,
 	  "Get the common preempt count event field value."},
@@ -96,6 +134,8 @@ static PyMethodDef ContextMethods[] = {
 	  METH_VARARGS,	"Get the common lock depth event field value."},
 	{ "perf_sample_insn", perf_sample_insn,
 	  METH_VARARGS,	"Get the machine code instruction."},
+	{ "perf_set_itrace_options", perf_set_itrace_options,
+	  METH_VARARGS,	"Set --itrace options."},
 	{ NULL, NULL, 0, NULL}
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 10/13] perf scripting python: Add perf_sample_srcline() and perf_sample_srccode()
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (8 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 09/13] perf scripting python: Add perf_set_itrace_options() Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 11/13] perf scripting python: Update documentation for srcline etc Adrian Hunter
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Add perf_sample_srcline() and perf_sample_srccode() to the
perf_trace_context module so that a script can get the srcline or srccode
information.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../scripts/python/Perf-Trace-Util/Context.c  | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
index 3c9bc12a1332..895f5fc23965 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c
@@ -5,14 +5,23 @@
  * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com>
  */
 
+/*
+ * Use Py_ssize_t for '#' formats to avoid DeprecationWarning: PY_SSIZE_T_CLEAN
+ * will be required for '#' formats.
+ */
+#define PY_SSIZE_T_CLEAN
+
 #include <Python.h>
 #include "../../../util/trace-event.h"
 #include "../../../util/event.h"
 #include "../../../util/symbol.h"
 #include "../../../util/thread.h"
+#include "../../../util/map.h"
 #include "../../../util/maps.h"
 #include "../../../util/auxtrace.h"
 #include "../../../util/session.h"
+#include "../../../util/srcline.h"
+#include "../../../util/srccode.h"
 
 #if PY_MAJOR_VERSION < 3
 #define _PyCapsule_GetPointer(arg1, arg2) \
@@ -125,6 +134,49 @@ static PyObject *perf_set_itrace_options(PyObject *obj, PyObject *args)
 	return Py_BuildValue("i", retval);
 }
 
+static PyObject *perf_sample_src(PyObject *obj, PyObject *args, bool get_srccode)
+{
+	struct scripting_context *c = get_scripting_context(args);
+	unsigned int line = 0;
+	char *srcfile = NULL;
+	char *srccode = NULL;
+	PyObject *result;
+	struct map *map;
+	int len = 0;
+	u64 addr;
+
+	if (!c)
+		return NULL;
+
+	map = c->al->map;
+	addr = c->al->addr;
+
+	if (map && map->dso)
+		srcfile = get_srcline_split(map->dso, map__rip_2objdump(map, addr), &line);
+
+	if (get_srccode) {
+		if (srcfile)
+			srccode = find_sourceline(srcfile, line, &len);
+		result = Py_BuildValue("(sIs#)", srcfile, line, srccode, (Py_ssize_t)len);
+	} else {
+		result = Py_BuildValue("(sI)", srcfile, line);
+	}
+
+	free(srcfile);
+
+	return result;
+}
+
+static PyObject *perf_sample_srcline(PyObject *obj, PyObject *args)
+{
+	return perf_sample_src(obj, args, false);
+}
+
+static PyObject *perf_sample_srccode(PyObject *obj, PyObject *args)
+{
+	return perf_sample_src(obj, args, true);
+}
+
 static PyMethodDef ContextMethods[] = {
 	{ "common_pc", perf_trace_context_common_pc, METH_VARARGS,
 	  "Get the common preempt count event field value."},
@@ -136,6 +188,10 @@ static PyMethodDef ContextMethods[] = {
 	  METH_VARARGS,	"Get the machine code instruction."},
 	{ "perf_set_itrace_options", perf_set_itrace_options,
 	  METH_VARARGS,	"Set --itrace options."},
+	{ "perf_sample_srcline", perf_sample_srcline,
+	  METH_VARARGS,	"Get source file name and line number."},
+	{ "perf_sample_srccode", perf_sample_srccode,
+	  METH_VARARGS,	"Get source file name, line number and line."},
 	{ NULL, NULL, 0, NULL}
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 11/13] perf scripting python: Update documentation for srcline etc
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (9 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 10/13] perf scripting python: Add perf_sample_srcline() and perf_sample_srccode() Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 12/13] perf scripting python: exported-sql-viewer.py: Factor out libxed.py Adrian Hunter
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Add new fields and functions to the perf-script-python documentation.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../perf/Documentation/perf-script-python.txt | 46 +++++++++++++++++--
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-script-python.txt b/tools/perf/Documentation/perf-script-python.txt
index 0fb9eda3cbca..5e43cfa5ea1e 100644
--- a/tools/perf/Documentation/perf-script-python.txt
+++ b/tools/perf/Documentation/perf-script-python.txt
@@ -550,6 +550,27 @@ def trace_unhandled(event_name, context, event_fields_dict):
     pass
 ----
 
+*process_event*, if defined, is called for any non-tracepoint event
+
+----
+def process_event(param_dict):
+    pass
+----
+
+*context_switch*, if defined, is called for any context switch
+
+----
+def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):
+    pass
+----
+
+*auxtrace_error*, if defined, is called for any AUX area tracing error
+
+----
+def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x):
+    pass
+----
+
 The remaining sections provide descriptions of each of the available
 built-in perf script Python modules and their associated functions.
 
@@ -592,12 +613,18 @@ common, but need to be made accessible to user scripts nonetheless.
 perf_trace_context defines a set of functions that can be used to
 access this data in the context of the current event.  Each of these
 functions expects a context variable, which is the same as the
-context variable passed into every event handler as the second
-argument.
+context variable passed into every tracepoint event handler as the second
+argument. For non-tracepoint events, the context variable is also present
+as perf_trace_context.perf_script_context .
 
  common_pc(context) - returns common_preempt count for the current event
  common_flags(context) - returns common_flags for the current event
  common_lock_depth(context) - returns common_lock_depth for the current event
+ perf_sample_insn(context) - returns the machine code instruction
+ perf_set_itrace_options(context, itrace_options) - set --itrace options if they have not been set already
+ perf_sample_srcline(context) - returns source_file_name, line_number
+ perf_sample_srccode(context) - returns source_file_name, line_number, source_line
+
 
 Util.py Module
 ~~~~~~~~~~~~~~
@@ -616,9 +643,20 @@ SUPPORTED FIELDS
 Currently supported fields:
 
 ev_name, comm, pid, tid, cpu, ip, time, period, phys_addr, addr,
-symbol, dso, time_enabled, time_running, values, callchain,
+symbol, symoff, dso, time_enabled, time_running, values, callchain,
 brstack, brstacksym, datasrc, datasrc_decode, iregs, uregs,
-weight, transaction, raw_buf, attr.
+weight, transaction, raw_buf, attr, cpumode.
+
+Fields that may also be present:
+
+ flags - sample flags
+ flags_disp - sample flags display
+ insn_cnt - instruction count for determining instructions-per-cycle (IPC)
+ cyc_cnt - cycle count for determining IPC
+ addr_correlates_sym - addr can correlate to a symbol
+ addr_dso - addr dso
+ addr_symbol - addr symbol
+ addr_symoff - addr symbol offset
 
 Some fields have sub items:
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 12/13] perf scripting python: exported-sql-viewer.py: Factor out libxed.py
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (10 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 11/13] perf scripting python: Update documentation for srcline etc Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-05-30 19:23 ` [PATCH 13/13] perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace Adrian Hunter
  2021-06-01 13:06 ` [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Arnaldo Carvalho de Melo
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Factor out libxed.py so it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../scripts/python/exported-sql-viewer.py     |  89 +--------------
 tools/perf/scripts/python/libxed.py           | 107 ++++++++++++++++++
 2 files changed, 108 insertions(+), 88 deletions(-)
 create mode 100644 tools/perf/scripts/python/libxed.py

diff --git a/tools/perf/scripts/python/exported-sql-viewer.py b/tools/perf/scripts/python/exported-sql-viewer.py
index 711d4f9f5645..13f2d8a81610 100755
--- a/tools/perf/scripts/python/exported-sql-viewer.py
+++ b/tools/perf/scripts/python/exported-sql-viewer.py
@@ -113,6 +113,7 @@ import os
 import random
 import copy
 import math
+from libxed import LibXED
 
 pyside_version_1 = True
 if not "--pyside-version-1" in sys.argv:
@@ -4747,94 +4748,6 @@ class MainWindow(QMainWindow):
 		dialog = AboutDialog(self.glb, self)
 		dialog.exec_()
 
-# XED Disassembler
-
-class xed_state_t(Structure):
-
-	_fields_ = [
-		("mode", c_int),
-		("width", c_int)
-	]
-
-class XEDInstruction():
-
-	def __init__(self, libxed):
-		# Current xed_decoded_inst_t structure is 192 bytes. Use 512 to allow for future expansion
-		xedd_t = c_byte * 512
-		self.xedd = xedd_t()
-		self.xedp = addressof(self.xedd)
-		libxed.xed_decoded_inst_zero(self.xedp)
-		self.state = xed_state_t()
-		self.statep = addressof(self.state)
-		# Buffer for disassembled instruction text
-		self.buffer = create_string_buffer(256)
-		self.bufferp = addressof(self.buffer)
-
-class LibXED():
-
-	def __init__(self):
-		try:
-			self.libxed = CDLL("libxed.so")
-		except:
-			self.libxed = None
-		if not self.libxed:
-			self.libxed = CDLL("/usr/local/lib/libxed.so")
-
-		self.xed_tables_init = self.libxed.xed_tables_init
-		self.xed_tables_init.restype = None
-		self.xed_tables_init.argtypes = []
-
-		self.xed_decoded_inst_zero = self.libxed.xed_decoded_inst_zero
-		self.xed_decoded_inst_zero.restype = None
-		self.xed_decoded_inst_zero.argtypes = [ c_void_p ]
-
-		self.xed_operand_values_set_mode = self.libxed.xed_operand_values_set_mode
-		self.xed_operand_values_set_mode.restype = None
-		self.xed_operand_values_set_mode.argtypes = [ c_void_p, c_void_p ]
-
-		self.xed_decoded_inst_zero_keep_mode = self.libxed.xed_decoded_inst_zero_keep_mode
-		self.xed_decoded_inst_zero_keep_mode.restype = None
-		self.xed_decoded_inst_zero_keep_mode.argtypes = [ c_void_p ]
-
-		self.xed_decode = self.libxed.xed_decode
-		self.xed_decode.restype = c_int
-		self.xed_decode.argtypes = [ c_void_p, c_void_p, c_uint ]
-
-		self.xed_format_context = self.libxed.xed_format_context
-		self.xed_format_context.restype = c_uint
-		self.xed_format_context.argtypes = [ c_int, c_void_p, c_void_p, c_int, c_ulonglong, c_void_p, c_void_p ]
-
-		self.xed_tables_init()
-
-	def Instruction(self):
-		return XEDInstruction(self)
-
-	def SetMode(self, inst, mode):
-		if mode:
-			inst.state.mode = 4 # 32-bit
-			inst.state.width = 4 # 4 bytes
-		else:
-			inst.state.mode = 1 # 64-bit
-			inst.state.width = 8 # 8 bytes
-		self.xed_operand_values_set_mode(inst.xedp, inst.statep)
-
-	def DisassembleOne(self, inst, bytes_ptr, bytes_cnt, ip):
-		self.xed_decoded_inst_zero_keep_mode(inst.xedp)
-		err = self.xed_decode(inst.xedp, bytes_ptr, bytes_cnt)
-		if err:
-			return 0, ""
-		# Use AT&T mode (2), alternative is Intel (3)
-		ok = self.xed_format_context(2, inst.xedp, inst.bufferp, sizeof(inst.buffer), ip, 0, 0)
-		if not ok:
-			return 0, ""
-		if sys.version_info[0] == 2:
-			result = inst.buffer.value
-		else:
-			result = inst.buffer.value.decode()
-		# Return instruction length and the disassembled instruction text
-		# For now, assume the length is in byte 166
-		return inst.xedd[166], result
-
 def TryOpen(file_name):
 	try:
 		return open(file_name, "rb")
diff --git a/tools/perf/scripts/python/libxed.py b/tools/perf/scripts/python/libxed.py
new file mode 100644
index 000000000000..2c70a5a7eb9c
--- /dev/null
+++ b/tools/perf/scripts/python/libxed.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: GPL-2.0
+# libxed.py: Python wrapper for libxed.so
+# Copyright (c) 2014-2021, Intel Corporation.
+
+# To use Intel XED, libxed.so must be present. To build and install
+# libxed.so:
+#            git clone https://github.com/intelxed/mbuild.git mbuild
+#            git clone https://github.com/intelxed/xed
+#            cd xed
+#            ./mfile.py --share
+#            sudo ./mfile.py --prefix=/usr/local install
+#            sudo ldconfig
+#
+
+import sys
+
+from ctypes import CDLL, Structure, create_string_buffer, addressof, sizeof, \
+		   c_void_p, c_bool, c_byte, c_char, c_int, c_uint, c_longlong, c_ulonglong
+
+# XED Disassembler
+
+class xed_state_t(Structure):
+
+	_fields_ = [
+		("mode", c_int),
+		("width", c_int)
+	]
+
+class XEDInstruction():
+
+	def __init__(self, libxed):
+		# Current xed_decoded_inst_t structure is 192 bytes. Use 512 to allow for future expansion
+		xedd_t = c_byte * 512
+		self.xedd = xedd_t()
+		self.xedp = addressof(self.xedd)
+		libxed.xed_decoded_inst_zero(self.xedp)
+		self.state = xed_state_t()
+		self.statep = addressof(self.state)
+		# Buffer for disassembled instruction text
+		self.buffer = create_string_buffer(256)
+		self.bufferp = addressof(self.buffer)
+
+class LibXED():
+
+	def __init__(self):
+		try:
+			self.libxed = CDLL("libxed.so")
+		except:
+			self.libxed = None
+		if not self.libxed:
+			self.libxed = CDLL("/usr/local/lib/libxed.so")
+
+		self.xed_tables_init = self.libxed.xed_tables_init
+		self.xed_tables_init.restype = None
+		self.xed_tables_init.argtypes = []
+
+		self.xed_decoded_inst_zero = self.libxed.xed_decoded_inst_zero
+		self.xed_decoded_inst_zero.restype = None
+		self.xed_decoded_inst_zero.argtypes = [ c_void_p ]
+
+		self.xed_operand_values_set_mode = self.libxed.xed_operand_values_set_mode
+		self.xed_operand_values_set_mode.restype = None
+		self.xed_operand_values_set_mode.argtypes = [ c_void_p, c_void_p ]
+
+		self.xed_decoded_inst_zero_keep_mode = self.libxed.xed_decoded_inst_zero_keep_mode
+		self.xed_decoded_inst_zero_keep_mode.restype = None
+		self.xed_decoded_inst_zero_keep_mode.argtypes = [ c_void_p ]
+
+		self.xed_decode = self.libxed.xed_decode
+		self.xed_decode.restype = c_int
+		self.xed_decode.argtypes = [ c_void_p, c_void_p, c_uint ]
+
+		self.xed_format_context = self.libxed.xed_format_context
+		self.xed_format_context.restype = c_uint
+		self.xed_format_context.argtypes = [ c_int, c_void_p, c_void_p, c_int, c_ulonglong, c_void_p, c_void_p ]
+
+		self.xed_tables_init()
+
+	def Instruction(self):
+		return XEDInstruction(self)
+
+	def SetMode(self, inst, mode):
+		if mode:
+			inst.state.mode = 4 # 32-bit
+			inst.state.width = 4 # 4 bytes
+		else:
+			inst.state.mode = 1 # 64-bit
+			inst.state.width = 8 # 8 bytes
+		self.xed_operand_values_set_mode(inst.xedp, inst.statep)
+
+	def DisassembleOne(self, inst, bytes_ptr, bytes_cnt, ip):
+		self.xed_decoded_inst_zero_keep_mode(inst.xedp)
+		err = self.xed_decode(inst.xedp, bytes_ptr, bytes_cnt)
+		if err:
+			return 0, ""
+		# Use AT&T mode (2), alternative is Intel (3)
+		ok = self.xed_format_context(2, inst.xedp, inst.bufferp, sizeof(inst.buffer), ip, 0, 0)
+		if not ok:
+			return 0, ""
+		if sys.version_info[0] == 2:
+			result = inst.buffer.value
+		else:
+			result = inst.buffer.value.decode()
+		# Return instruction length and the disassembled instruction text
+		# For now, assume the length is in byte 166
+		return inst.xedd[166], result
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 13/13] perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (11 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 12/13] perf scripting python: exported-sql-viewer.py: Factor out libxed.py Adrian Hunter
@ 2021-05-30 19:23 ` Adrian Hunter
  2021-06-01 13:06 ` [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Arnaldo Carvalho de Melo
  13 siblings, 0 replies; 15+ messages in thread
From: Adrian Hunter @ 2021-05-30 19:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa, Andi Kleen; +Cc: linux-kernel

Add an instruction trace and a source trace to the intel-pt-events.py
script.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-intel-pt.txt   |   6 +-
 tools/perf/scripts/python/intel-pt-events.py | 176 +++++++++++++++++--
 2 files changed, 163 insertions(+), 19 deletions(-)

diff --git a/tools/perf/Documentation/perf-intel-pt.txt b/tools/perf/Documentation/perf-intel-pt.txt
index e382dbd4ff0a..184ba62420f0 100644
--- a/tools/perf/Documentation/perf-intel-pt.txt
+++ b/tools/perf/Documentation/perf-intel-pt.txt
@@ -174,7 +174,11 @@ Refer to script export-to-sqlite.py or export-to-postgresql.py for more details,
 and to script exported-sql-viewer.py for an example of using the database.
 
 There is also script intel-pt-events.py which provides an example of how to
-unpack the raw data for power events and PTWRITE.
+unpack the raw data for power events and PTWRITE. The script also displays
+branches, and supports 2 additional modes selected by option:
+
+ --insn-trace - instruction trace
+ --src-trace - source trace
 
 As mentioned above, it is easy to capture too much data.  One way to limit the
 data captured is to use 'snapshot' mode which is explained further below.
diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py
index fcfae1de731b..1d3a189a9a54 100644
--- a/tools/perf/scripts/python/intel-pt-events.py
+++ b/tools/perf/scripts/python/intel-pt-events.py
@@ -16,21 +16,30 @@ from __future__ import print_function
 import os
 import sys
 import struct
+import argparse
+
+from libxed import LibXED
+from ctypes import create_string_buffer, addressof
 
 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
 	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
 
-# These perf imports are not used at present
-#from perf_trace_context import *
-#from Core import *
+from perf_trace_context import perf_set_itrace_options, \
+	perf_sample_insn, perf_sample_srccode
 
 try:
 	broken_pipe_exception = BrokenPipeError
 except:
 	broken_pipe_exception = IOError
 
-glb_switch_str = None
-glb_switch_printed = True
+glb_switch_str		= None
+glb_switch_printed	= True
+glb_insn		= False
+glb_disassembler	= None
+glb_src			= False
+glb_source_file_name	= None
+glb_line_number		= None
+glb_dso			= None
 
 def get_optional_null(perf_dict, field):
 	if field in perf_dict:
@@ -42,6 +51,11 @@ def get_optional_zero(perf_dict, field):
 		return perf_dict[field]
 	return 0
 
+def get_optional_bytes(perf_dict, field):
+	if field in perf_dict:
+		return perf_dict[field]
+	return bytes()
+
 def get_optional(perf_dict, field):
 	if field in perf_dict:
 		return perf_dict[field]
@@ -53,7 +67,31 @@ def get_offset(perf_dict, field):
 	return ""
 
 def trace_begin():
-	print("Intel PT Branch Trace, Power Events and PTWRITE")
+	ap = argparse.ArgumentParser(usage = "", add_help = False)
+	ap.add_argument("--insn-trace", action='store_true')
+	ap.add_argument("--src-trace", action='store_true')
+	global glb_args
+	global glb_insn
+	global glb_src
+	glb_args = ap.parse_args()
+	if glb_args.insn_trace:
+		print("Intel PT Instruction Trace")
+		itrace = "i0nsepwx"
+		glb_insn = True
+	elif glb_args.src_trace:
+		print("Intel PT Source Trace")
+		itrace = "i0nsepwx"
+		glb_insn = True
+		glb_src = True
+	else:
+		print("Intel PT Branch Trace, Power Events and PTWRITE")
+		itrace = "bepwx"
+	global glb_disassembler
+	try:
+		glb_disassembler = LibXED()
+	except:
+		glb_disassembler = None
+	perf_set_itrace_options(perf_script_context, itrace)
 
 def trace_end():
 	print("End")
@@ -111,11 +149,14 @@ def print_psb(raw_buf):
 	offset = data[1]
 	print("offset: %#x" % (offset), end=' ')
 
-def print_common_start(comm, sample, name):
+def common_start_str(comm, sample):
 	ts = sample["time"]
 	cpu = sample["cpu"]
 	pid = sample["pid"]
 	tid = sample["tid"]
+	return "%16s %5u/%-5u [%03u] %9u.%09u  " % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000)
+
+def print_common_start(comm, sample, name):
 	flags_disp = get_optional_null(sample, "flags_disp")
 	# Unused fields:
 	# period      = sample["period"]
@@ -123,22 +164,96 @@ def print_common_start(comm, sample, name):
 	# weight      = sample["weight"]
 	# transaction = sample["transaction"]
 	# cpumode     = get_optional_zero(sample, "cpumode")
-	print("%16s %5u/%-5u [%03u] %9u.%09u  %7s  %19s" %
-		(comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name, flags_disp),
-		end=' ')
+	print(common_start_str(comm, sample) + "%7s  %19s" % (name, flags_disp), end=' ')
+
+def print_instructions_start(comm, sample):
+	if "x" in get_optional_null(sample, "flags"):
+		print(common_start_str(comm, sample) + "x", end=' ')
+	else:
+		print(common_start_str(comm, sample), end='  ')
+
+def disassem(insn, ip):
+	inst = glb_disassembler.Instruction()
+	glb_disassembler.SetMode(inst, 0) # Assume 64-bit
+	buf = create_string_buffer(64)
+	buf.value = insn
+	return glb_disassembler.DisassembleOne(inst, addressof(buf), len(insn), ip)
 
 def print_common_ip(param_dict, sample, symbol, dso):
 	ip   = sample["ip"]
 	offs = get_offset(param_dict, "symoff")
-	print("%16x %s%s (%s)" % (ip, symbol, offs, dso), end=' ')
+	if "cyc_cnt" in sample:
+		cyc_cnt = sample["cyc_cnt"]
+		insn_cnt = get_optional_zero(sample, "insn_cnt")
+		ipc_str = "  IPC: %#.2f (%u/%u)" % (insn_cnt / cyc_cnt, insn_cnt, cyc_cnt)
+	else:
+		ipc_str = ""
+	if glb_insn and glb_disassembler is not None:
+		insn = perf_sample_insn(perf_script_context)
+		if insn and len(insn):
+			cnt, text = disassem(insn, ip)
+			byte_str = ("%x" % ip).rjust(16)
+			if sys.version_info.major >= 3:
+				for k in range(cnt):
+					byte_str += " %02x" % insn[k]
+			else:
+				for k in xrange(cnt):
+					byte_str += " %02x" % ord(insn[k])
+			print("%-40s  %-30s" % (byte_str, text), end=' ')
+		print("%s%s (%s)" % (symbol, offs, dso), end=' ')
+	else:
+		print("%16x %s%s (%s)" % (ip, symbol, offs, dso), end=' ')
 	if "addr_correlates_sym" in sample:
 		addr   = sample["addr"]
 		dso    = get_optional(sample, "addr_dso")
 		symbol = get_optional(sample, "addr_symbol")
 		offs   = get_offset(sample, "addr_symoff")
-		print("=> %x %s%s (%s)" % (addr, symbol, offs, dso))
+		print("=> %x %s%s (%s)%s" % (addr, symbol, offs, dso, ipc_str))
+	else:
+		print(ipc_str)
+
+def print_srccode(comm, param_dict, sample, symbol, dso, with_insn):
+	ip = sample["ip"]
+	if symbol == "[unknown]":
+		start_str = common_start_str(comm, sample) + ("%x" % ip).rjust(16).ljust(40)
 	else:
-		print()
+		offs = get_offset(param_dict, "symoff")
+		start_str = common_start_str(comm, sample) + (symbol + offs).ljust(40)
+
+	if with_insn and glb_insn and glb_disassembler is not None:
+		insn = perf_sample_insn(perf_script_context)
+		if insn and len(insn):
+			cnt, text = disassem(insn, ip)
+		start_str += text.ljust(30)
+
+	global glb_source_file_name
+	global glb_line_number
+	global glb_dso
+
+	source_file_name, line_number, source_line = perf_sample_srccode(perf_script_context)
+	if source_file_name:
+		if glb_line_number == line_number and glb_source_file_name == source_file_name:
+			src_str = ""
+		else:
+			if len(source_file_name) > 40:
+				src_file = ("..." + source_file_name[-37:]) + " "
+			else:
+				src_file = source_file_name.ljust(41)
+			if source_line is None:
+				src_str = src_file + str(line_number).rjust(4) + " <source not found>"
+			else:
+				src_str = src_file + str(line_number).rjust(4) + " " + source_line
+		glb_dso = None
+	elif dso == glb_dso:
+		src_str = ""
+	else:
+		src_str = dso
+		glb_dso = dso
+
+	glb_line_number = line_number
+	glb_source_file_name = source_file_name
+
+	print(start_str, src_str)
 
 def do_process_event(param_dict):
 	global glb_switch_printed
@@ -159,24 +274,49 @@ def do_process_event(param_dict):
 	dso    = get_optional(param_dict, "dso")
 	symbol = get_optional(param_dict, "symbol")
 
-	print_common_start(comm, sample, name)
-
-	if name == "ptwrite":
+	if name[0:12] == "instructions":
+		if glb_src:
+			print_srccode(comm, param_dict, sample, symbol, dso, True)
+		else:
+			print_instructions_start(comm, sample)
+			print_common_ip(param_dict, sample, symbol, dso)
+	elif name[0:8] == "branches":
+		if glb_src:
+			print_srccode(comm, param_dict, sample, symbol, dso, False)
+		else:
+			print_common_start(comm, sample, name)
+			print_common_ip(param_dict, sample, symbol, dso)
+	elif name == "ptwrite":
+		print_common_start(comm, sample, name)
 		print_ptwrite(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	elif name == "cbr":
+		print_common_start(comm, sample, name)
 		print_cbr(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	elif name == "mwait":
+		print_common_start(comm, sample, name)
 		print_mwait(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	elif name == "pwre":
+		print_common_start(comm, sample, name)
 		print_pwre(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	elif name == "exstop":
+		print_common_start(comm, sample, name)
 		print_exstop(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	elif name == "pwrx":
+		print_common_start(comm, sample, name)
 		print_pwrx(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	elif name == "psb":
+		print_common_start(comm, sample, name)
 		print_psb(raw_buf)
-
-	print_common_ip(param_dict, sample, symbol, dso)
+		print_common_ip(param_dict, sample, symbol, dso)
+	else:
+		print_common_start(comm, sample, name)
+		print_common_ip(param_dict, sample, symbol, dso)
 
 def process_event(param_dict):
 	try:
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 00/13] perf scripting python: Add insn, srcline and srccode
  2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
                   ` (12 preceding siblings ...)
  2021-05-30 19:23 ` [PATCH 13/13] perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace Adrian Hunter
@ 2021-06-01 13:06 ` Arnaldo Carvalho de Melo
  13 siblings, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-06-01 13:06 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Jiri Olsa, Andi Kleen, linux-kernel

Em Sun, May 30, 2021 at 10:22:55PM +0300, Adrian Hunter escreveu:
> Hi
> 
> Here are some patches to add insn, srcline and srccode to python scripting.
> In addition, it is made possible for a script to set itrace options.
> 
> The first 2 patches are minor tidy-ups.  The next 3 are additions to
> scripting_context. The next 5 add new methods that python scripts can call.
> 
> Then there is a patch to the perf scripting python documentation.
> 
> And finally 2 patches add to the intel-pt-events.py script as an example.

Thanks, applied.

- Arnaldo

 
> 
> Adrian Hunter (13):
>       perf scripting python: Remove unnecessary 'static'
>       perf scripting python: Simplify perf-trace-context module functions
>       perf scripting: Add scripting_context__update()
>       perf scripting: Add perf_session to scripting_context
>       perf scripting python: Assign perf_script_context
>       perf script: Factor out script_fetch_insn()
>       perf scripting python: Add perf_sample_insn()
>       perf auxtrace: Factor out itrace_do_parse_synth_opts()
>       perf scripting python: Add perf_set_itrace_options()
>       perf scripting python: Add perf_sample_srcline() and perf_sample_srccode()
>       perf scripting python: Update documentation for srcline etc
>       perf scripting python: exported-sql-viewer.py: Factor out libxed.py
>       perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace
> 
>  tools/perf/Documentation/perf-intel-pt.txt         |   6 +-
>  tools/perf/Documentation/perf-script-python.txt    |  46 +++++-
>  tools/perf/builtin-script.c                        |  12 +-
>  .../perf/scripts/python/Perf-Trace-Util/Context.c  | 168 +++++++++++++++++---
>  tools/perf/scripts/python/exported-sql-viewer.py   |  89 +----------
>  tools/perf/scripts/python/intel-pt-events.py       | 176 ++++++++++++++++++---
>  tools/perf/scripts/python/libxed.py                | 107 +++++++++++++
>  tools/perf/util/auxtrace.c                         |  10 +-
>  tools/perf/util/auxtrace.h                         |  10 ++
>  .../perf/util/scripting-engines/trace-event-perl.c |  11 +-
>  .../util/scripting-engines/trace-event-python.c    |  37 ++++-
>  tools/perf/util/trace-event-scripting.c            |  27 +++-
>  tools/perf/util/trace-event.h                      |  20 ++-
>  13 files changed, 568 insertions(+), 151 deletions(-)
>  create mode 100644 tools/perf/scripts/python/libxed.py
> 
> 
> Regards
> Adrian

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-06-01 13:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-30 19:22 [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Adrian Hunter
2021-05-30 19:22 ` [PATCH 01/13] perf scripting python: Remove unnecessary 'static' Adrian Hunter
2021-05-30 19:22 ` [PATCH 02/13] perf scripting python: Simplify perf-trace-context module functions Adrian Hunter
2021-05-30 19:22 ` [PATCH 03/13] perf scripting: Add scripting_context__update() Adrian Hunter
2021-05-30 19:22 ` [PATCH 04/13] perf scripting: Add perf_session to scripting_context Adrian Hunter
2021-05-30 19:23 ` [PATCH 05/13] perf scripting python: Assign perf_script_context Adrian Hunter
2021-05-30 19:23 ` [PATCH 06/13] perf script: Factor out script_fetch_insn() Adrian Hunter
2021-05-30 19:23 ` [PATCH 07/13] perf scripting python: Add perf_sample_insn() Adrian Hunter
2021-05-30 19:23 ` [PATCH 08/13] perf auxtrace: Factor out itrace_do_parse_synth_opts() Adrian Hunter
2021-05-30 19:23 ` [PATCH 09/13] perf scripting python: Add perf_set_itrace_options() Adrian Hunter
2021-05-30 19:23 ` [PATCH 10/13] perf scripting python: Add perf_sample_srcline() and perf_sample_srccode() Adrian Hunter
2021-05-30 19:23 ` [PATCH 11/13] perf scripting python: Update documentation for srcline etc Adrian Hunter
2021-05-30 19:23 ` [PATCH 12/13] perf scripting python: exported-sql-viewer.py: Factor out libxed.py Adrian Hunter
2021-05-30 19:23 ` [PATCH 13/13] perf scripting python: intel-pt-events.py: Add --insn-trace and --src-trace Adrian Hunter
2021-06-01 13:06 ` [PATCH 00/13] perf scripting python: Add insn, srcline and srccode Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).