mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fb.com>
To: <rostedt@goodmis.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] trace-cmd: add helper to read *_stack ftrace events
Date: Thu, 25 Sep 2014 13:43:57 -0400	[thread overview]
Message-ID: <1411667037-27105-1-git-send-email-jbacik@fb.com> (raw)

The user_stack and kernel_stack events are special in that they are dynamic
arrays but aren't labeled as __data_loc like other dynamic arrays.  This isn't a
big deal since they look the same, they have a "caller" field which is an array
of unsigned longs.  This patch adds a helper to the python bindings to read
these arrays in, lookup the function and append them to a python list.

Signed-off-by: Josef Bacik <jbacik@fb.com>
---
NOTE:  This patch replaces the one I sent yesterday

trace-cmd: add helper to read kernel_stack functions

This is cleaner and gives us a nice list of the functions and works for both
kernel_stack and user_stack events.

 ctracecmd.i | 37 +++++++++++++++++++++++++++++++++++++
 tracecmd.py |  8 ++++++++
 2 files changed, 45 insertions(+)

diff --git a/ctracecmd.i b/ctracecmd.i
index 3970803..3b80f01 100644
--- a/ctracecmd.i
+++ b/ctracecmd.i
@@ -49,6 +49,43 @@ void py_pevent_register_event_handler(struct pevent *pevent, int id,
 				      python_callback, pyfunc);
 }
 
+static PyObject *py_field_get_stack(struct pevent *pevent,
+				    struct pevent_record *record,
+				    struct event_format *event,
+				    int long_size)
+{
+	PyObject *list;
+	struct format_field *field;
+	void *data = record->data;
+	const char *func = NULL;
+	unsigned long addr;
+
+	field = pevent_find_any_field(event, "caller");
+	if (!field) {
+		PyErr_SetString(PyExc_TypeError,
+				"Event doesn't have caller field");
+		return NULL;
+	}
+
+	list = PyList_New(0);
+
+	for (data += field->offset; data < record->data + record->size;
+	     data += long_size) {
+		addr = pevent_read_number(event->pevent, data, long_size);
+
+		if ((long_size == 8 && addr == (unsigned long long)-1) ||
+		    ((int)addr == -1))
+			break;
+		func = pevent_find_function(event->pevent, addr);
+		if (PyList_Append(list, PyString_FromString(func))) {
+			Py_DECREF(list);
+			return NULL;
+		}
+	}
+
+	return list;
+}
+
 static PyObject *py_field_get_data(struct format_field *f, struct pevent_record *r)
 {
 	if (!strncmp(f->type, "__data_loc ", 11)) {
diff --git a/tracecmd.py b/tracecmd.py
index cdd619b..358185b 100644
--- a/tracecmd.py
+++ b/tracecmd.py
@@ -117,6 +117,10 @@ class Event(object, DictMixin):
             return None
         return py_field_get_str(f, self._record)
 
+    def stack_field(self, long_size):
+        return py_field_get_stack(self._pevent, self._record, self._format,
+                                  long_size)
+
 class TraceSeq(object):
     def __init__(self, trace_seq):
         self._trace_seq = trace_seq
@@ -192,6 +196,10 @@ class Trace(object):
     def cpus(self):
         return tracecmd_cpus(self._handle)
 
+    @cached_property
+    def long_size(self):
+        return tracecmd_long_size(self._handle)
+
     def read_event(self, cpu):
         rec = tracecmd_read_data(self._handle, cpu)
         if rec:
-- 
1.9.3


                 reply	other threads:[~2014-09-25 17:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1411667037-27105-1-git-send-email-jbacik@fb.com \
    --to=jbacik@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®