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 08/10] perf scripting python: Add context switch
Date: Tue, 25 May 2021 12:51:10 +0300 [thread overview]
Message-ID: <20210525095112.1399-9-adrian.hunter@intel.com> (raw)
In-Reply-To: <20210525095112.1399-1-adrian.hunter@intel.com>
Add context_switch to general python scripting.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
.../scripting-engines/trace-event-python.c | 45 +++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index cb708669e02e..c422901d5344 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1019,6 +1019,11 @@ static int tuple_set_s32(PyObject *t, unsigned int pos, s32 val)
return PyTuple_SetItem(t, pos, _PyLong_FromLong(val));
}
+static int tuple_set_bool(PyObject *t, unsigned int pos, bool val)
+{
+ return PyTuple_SetItem(t, pos, PyBool_FromLong(val));
+}
+
static int tuple_set_string(PyObject *t, unsigned int pos, const char *s)
{
return PyTuple_SetItem(t, pos, _PyUnicode_FromString(s));
@@ -1406,6 +1411,44 @@ static void python_process_event(union perf_event *event,
}
}
+static void python_do_process_switch(union perf_event *event,
+ struct perf_sample *sample,
+ struct machine *machine)
+{
+ const char *handler_name = "context_switch";
+ bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT;
+ bool out_preempt = out && (event->header.misc & PERF_RECORD_MISC_SWITCH_OUT_PREEMPT);
+ pid_t np_pid = -1, np_tid = -1;
+ PyObject *handler, *t;
+
+ handler = get_handler(handler_name);
+ if (!handler)
+ return;
+
+ if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) {
+ np_pid = event->context_switch.next_prev_pid;
+ np_tid = event->context_switch.next_prev_tid;
+ }
+
+ t = tuple_new(9);
+ if (!t)
+ return;
+
+ tuple_set_u64(t, 0, sample->time);
+ tuple_set_s32(t, 1, sample->cpu);
+ tuple_set_s32(t, 2, sample->pid);
+ tuple_set_s32(t, 3, sample->tid);
+ tuple_set_s32(t, 4, np_pid);
+ tuple_set_s32(t, 5, np_tid);
+ tuple_set_s32(t, 6, machine->pid);
+ tuple_set_bool(t, 7, out);
+ tuple_set_bool(t, 8, out_preempt);
+
+ call_object(handler, t, handler_name);
+
+ Py_DECREF(t);
+}
+
static void python_process_switch(union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
@@ -1414,6 +1457,8 @@ static void python_process_switch(union perf_event *event,
if (tables->db_export_mode)
db_export__switch(&tables->dbe, event, sample, machine);
+ else
+ python_do_process_switch(event, sample, machine);
}
static void get_handler_name(char *str, size_t size,
--
2.17.1
next prev 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 ` Adrian Hunter [this message]
2021-05-25 9:51 ` [PATCH 09/10] perf scripting python: Add auxtrace error Adrian Hunter
2021-05-25 13:03 ` 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-9-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).