linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>, Andi Kleen <ak@linux.intel.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 09/10] perf scripting python: Add auxtrace error
Date: Tue, 25 May 2021 12:51:11 +0300	[thread overview]
Message-ID: <20210525095112.1399-10-adrian.hunter@intel.com> (raw)
In-Reply-To: <20210525095112.1399-1-adrian.hunter@intel.com>

Add auxtrace_error to general python scripting.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-script.c                   | 13 ++++++
 .../scripting-engines/trace-event-python.c    | 42 +++++++++++++++++++
 tools/perf/util/trace-event.h                 |  2 +
 3 files changed, 57 insertions(+)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 69bce65ea430..7a7a19f52db5 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2432,6 +2432,17 @@ static int process_switch_event(struct perf_tool *tool,
 			   sample->tid);
 }
 
+static int process_auxtrace_error(struct perf_session *session,
+				  union perf_event *event)
+{
+	if (scripting_ops && scripting_ops->process_auxtrace_error) {
+		scripting_ops->process_auxtrace_error(session, event);
+		return 0;
+	}
+
+	return perf_event__process_auxtrace_error(session, event);
+}
+
 static int
 process_lost_event(struct perf_tool *tool,
 		   union perf_event *event,
@@ -2571,6 +2582,8 @@ static int __cmd_script(struct perf_script *script)
 	}
 	if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch))
 		script->tool.context_switch = process_switch_event;
+	if (scripting_ops && scripting_ops->process_auxtrace_error)
+		script->tool.auxtrace_error = process_auxtrace_error;
 	if (script->show_namespace_events)
 		script->tool.namespaces = process_namespaces_event;
 	if (script->show_cgroup_events)
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index c422901d5344..ffc5f4cffdba 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1014,6 +1014,11 @@ static int tuple_set_u64(PyObject *t, unsigned int pos, u64 val)
 #endif
 }
 
+static int tuple_set_u32(PyObject *t, unsigned int pos, u32 val)
+{
+	return PyTuple_SetItem(t, pos, PyLong_FromUnsignedLong(val));
+}
+
 static int tuple_set_s32(PyObject *t, unsigned int pos, s32 val)
 {
 	return PyTuple_SetItem(t, pos, _PyLong_FromLong(val));
@@ -1461,6 +1466,42 @@ static void python_process_switch(union perf_event *event,
 		python_do_process_switch(event, sample, machine);
 }
 
+static void python_process_auxtrace_error(struct perf_session *session __maybe_unused,
+					  union perf_event *event)
+{
+	struct perf_record_auxtrace_error *e = &event->auxtrace_error;
+	u8 cpumode = e->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+	const char *handler_name = "auxtrace_error";
+	unsigned long long tm = e->time;
+	const char *msg = e->msg;
+	PyObject *handler, *t;
+
+	handler = get_handler(handler_name);
+	if (!handler)
+		return;
+
+	if (!e->fmt) {
+		tm = 0;
+		msg = (const char *)&e->time;
+	}
+
+	t = tuple_new(9);
+
+	tuple_set_u32(t, 0, e->type);
+	tuple_set_u32(t, 1, e->code);
+	tuple_set_s32(t, 2, e->cpu);
+	tuple_set_s32(t, 3, e->pid);
+	tuple_set_s32(t, 4, e->tid);
+	tuple_set_u64(t, 5, e->ip);
+	tuple_set_u64(t, 6, tm);
+	tuple_set_string(t, 7, msg);
+	tuple_set_u32(t, 8, cpumode);
+
+	call_object(handler, t, handler_name);
+
+	Py_DECREF(t);
+}
+
 static void get_handler_name(char *str, size_t size,
 			     struct evsel *evsel)
 {
@@ -1999,6 +2040,7 @@ struct scripting_ops python_scripting_ops = {
 	.stop_script		= python_stop_script,
 	.process_event		= python_process_event,
 	.process_switch		= python_process_switch,
+	.process_auxtrace_error	= python_process_auxtrace_error,
 	.process_stat		= python_process_stat,
 	.process_stat_interval	= python_process_stat_interval,
 	.generate_script	= python_generate_script,
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 7276674e2971..35c354a15c3a 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -83,6 +83,8 @@ struct scripting_ops {
 	void (*process_switch)(union perf_event *event,
 			       struct perf_sample *sample,
 			       struct machine *machine);
+	void (*process_auxtrace_error)(struct perf_session *session,
+				       union perf_event *event);
 	void (*process_stat)(struct perf_stat_config *config,
 			     struct evsel *evsel, u64 tstamp);
 	void (*process_stat_interval)(u64 tstamp);
-- 
2.17.1


  parent reply	other threads:[~2021-05-25  9:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25  9:51 [PATCH 00/10] perf scripting python: Improve general scripting for Intel PT Adrian Hunter
2021-05-25  9:51 ` [PATCH 01/10] perf scripting python: Fix tuple_set_u64() Adrian Hunter
2021-05-25  9:51 ` [PATCH 02/10] perf scripting python: Factor out set_sym_in_dict() Adrian Hunter
2021-05-25  9:51 ` [PATCH 03/10] perf scripting python: Add 'addr_location' for 'addr' Adrian Hunter
2021-05-25  9:51 ` [PATCH 04/10] perf script: Factor out perf_sample__sprintf_flags() Adrian Hunter
2021-05-25  9:51 ` [PATCH 05/10] perf scripting python: Add sample flags Adrian Hunter
2021-05-25  9:51 ` [PATCH 06/10] perf scripting python: Add IPC Adrian Hunter
2021-05-25  9:51 ` [PATCH 07/10] perf scripting python: Add cpumode Adrian Hunter
2021-05-25  9:51 ` [PATCH 08/10] perf scripting python: Add context switch Adrian Hunter
2021-05-25  9:51 ` Adrian Hunter [this message]
2021-05-25 13:03   ` [PATCH 09/10] perf scripting python: Add auxtrace error Arnaldo Carvalho de Melo
2021-05-25 18:30     ` Adrian Hunter
2021-05-25 19:54       ` Arnaldo Carvalho de Melo
2021-05-25  9:51 ` [PATCH 10/10] perf scripts python: intel-pt-events.py: Add branches to script Adrian Hunter
2021-05-25 12:58 ` [PATCH 00/10] perf scripting python: Improve general scripting for Intel PT Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210525095112.1399-10-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).