From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Arun Kalyanasundaram <arunkaly@google.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Daniel Borkmann <daniel@iogearbox.net>,
David Carrillo-Cisneros <davidcc@google.com>,
"David S . Miller" <davem@davemloft.net>,
Peter Zijlstra <peterz@infradead.org>,
Seongjae Park <sj38.park@gmail.com>,
Stephane Eranian <eranian@google.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 34/40] perf script python: Add perf_sample dict to tracepoint handlers
Date: Wed, 26 Jul 2017 11:17:24 -0300 [thread overview]
Message-ID: <20170726141730.30750-35-acme@kernel.org> (raw)
In-Reply-To: <20170726141730.30750-1-acme@kernel.org>
From: Arun Kalyanasundaram <arunkaly@google.com>
The process_event python hook receives a dict with all perf_sample
entries, but the tracepoint specific and trace_unhandled hooks predate
the introduction of this dict, and do not receive it.
Add the aforementioned dict as an additional argument to the affected
handlers. To keep backwards compatibility (and avoid unnecessary work),
do not pass the dict if the number of arguments signals that handler
version predates this change.
Signed-off-by: Arun Kalyanasundaram <arunkaly@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Carrillo-Cisneros <davidcc@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Seongjae Park <sj38.park@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20170721220422.63962-5-arunkaly@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
.../util/scripting-engines/trace-event-python.c | 41 +++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 55a45784c910..938b39f6ad31 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -116,6 +116,34 @@ static PyObject *get_handler(const char *handler_name)
return handler;
}
+static int get_argument_count(PyObject *handler)
+{
+ int arg_count = 0;
+
+ /*
+ * The attribute for the code object is func_code in Python 2,
+ * whereas it is __code__ in Python 3.0+.
+ */
+ PyObject *code_obj = PyObject_GetAttrString(handler,
+ "func_code");
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ code_obj = PyObject_GetAttrString(handler,
+ "__code__");
+ }
+ PyErr_Clear();
+ if (code_obj) {
+ PyObject *arg_count_obj = PyObject_GetAttrString(code_obj,
+ "co_argcount");
+ if (arg_count_obj) {
+ arg_count = (int) PyInt_AsLong(arg_count_obj);
+ Py_DECREF(arg_count_obj);
+ }
+ Py_DECREF(code_obj);
+ }
+ return arg_count;
+}
+
static void call_object(PyObject *handler, PyObject *args, const char *die_msg)
{
PyObject *retval;
@@ -499,7 +527,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
{
struct event_format *event = evsel->tp_format;
PyObject *handler, *context, *t, *obj = NULL, *callchain;
- PyObject *dict = NULL;
+ PyObject *dict = NULL, *all_entries_dict = NULL;
static char handler_name[256];
struct format_field *field;
unsigned long s, ns;
@@ -552,6 +580,8 @@ static void python_process_tracepoint(struct perf_sample *sample,
/* ip unwinding */
callchain = python_process_callchain(sample, evsel, al);
+ /* Need an additional reference for the perf_sample dict */
+ Py_INCREF(callchain);
if (!dict) {
PyTuple_SetItem(t, n++, PyInt_FromLong(cpu));
@@ -602,6 +632,14 @@ static void python_process_tracepoint(struct perf_sample *sample,
if (dict)
PyTuple_SetItem(t, n++, dict);
+ if (get_argument_count(handler) == (int) n + 1) {
+ all_entries_dict = get_perf_sample_dict(sample, evsel, al,
+ callchain);
+ PyTuple_SetItem(t, n++, all_entries_dict);
+ } else {
+ Py_DECREF(callchain);
+ }
+
if (_PyTuple_Resize(&t, n) == -1)
Py_FatalError("error resizing Python tuple");
@@ -612,6 +650,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
Py_DECREF(dict);
}
+ Py_XDECREF(all_entries_dict);
Py_DECREF(t);
}
--
2.9.4
next prev parent reply other threads:[~2017-07-26 14:20 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-26 14:16 [GIT PULL 00/40] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 01/40] perf intel-pt: Set no_aux_samples for the tracking event Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 02/40] perf intel-pt: Always set no branch for dummy event Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 03/40] perf trace: Add missing ' = ' in the default formatting of syscall returns Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 04/40] perf trace beauty mmap: Ignore 'fd' and 'offset' args for MAP_ANONYMOUS Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 05/40] perf trace: Allow allocating sc->arg_fmt even without the syscall tracepoint Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 06/40] perf trace: Use the syscall_fmt formatters without a tracepoint Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 07/40] perf trace: Ditch __syscall__arg_val() variant, not needed anymore Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 08/40] perf trace: Allow specifying number of syscall args for tracepointless syscalls Arnaldo Carvalho de Melo
2017-07-26 14:16 ` [PATCH 09/40] perf trace: Allow specifying names to syscall arguments formatters Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 10/40] tools include uapi: Grab a copy of linux/sched.h Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 11/40] perf trace beauty clone: Beautify syscall arguments Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 12/40] perf trace beauty clone: Suppress unused args according to 'flags' arg Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 13/40] perf trace: Introduce filter_loop_pids() Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 14/40] perf trace: Filter out 'sshd' in the tracer ancestry in syswide tracing Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 15/40] tools include: Adopt strstarts() from the kernel Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 16/40] tools lib: Update copy of strtobool from the kernel sources Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 17/40] perf annotate: Introduce struct sym_hist_entry Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 18/40] perf annotate: Rename 'sum' to 'nr_samples' in struct sym_hist Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 19/40] perf hists: Pass perf_sample to __symbol__inc_addr_samples() Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 20/40] perf annotate: Store the sample period in each histogram bucket Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 21/40] perf annotate: Do not overwrite sample->period Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 22/40] perf annotate stdio: Fix --show-total-period Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 23/40] perf report: Fix kernel symbol adjustment for s390x Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 24/40] perf cgroup: Fix refcount usage Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 25/40] perf tools: Add EXCLUDE_EXTLIBS and EXTRA_PERFLIBS to makefile Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 26/40] perf annotate: Process tracing data in pipe mode Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 27/40] perf jvmti: Fix linker error when libelf config is disabled Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 28/40] perf evsel: Add verbose output for sys_perf_event_open fallback Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 29/40] perf top: Support lookup of symbols in other mount namespaces Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 30/40] perf script: Remove some bogus error handling Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 31/40] perf script python: Allocate memory only if handler exists Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 32/40] perf script python: Refactor creation of perf sample dict Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 33/40] perf script python: Add sample_read to dict Arnaldo Carvalho de Melo
2017-07-26 14:17 ` Arnaldo Carvalho de Melo [this message]
2017-07-26 14:17 ` [PATCH 35/40] perf script python: Generate hooks with additional argument Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 36/40] perf report: Make --branch-history work without callgraphs(-g) option in perf record Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 37/40] perf report: Tag branch type/flag on "to" and tag cycles on "from" Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 38/40] perf jevents: Make build fail on JSON parse error Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 39/40] perf annotate stdio: Fix column header when using --show-total-period Arnaldo Carvalho de Melo
2017-07-26 14:17 ` [PATCH 40/40] perf tools: Add tools/include/uapi/asm-generic/fcntl.h to the MANIFEST Arnaldo Carvalho de Melo
2017-07-26 17:10 ` [GIT PULL 00/40] perf/core improvements and fixes Ingo Molnar
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=20170726141730.30750-35-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=arunkaly@google.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=davidcc@google.com \
--cc=eranian@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=sj38.park@gmail.com \
/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
Powered by JetHome