All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 2/2] trace-cruncher: Provide short kprobe info print
Date: Mon, 13 Sep 2021 16:56:38 +0300	[thread overview]
Message-ID: <20210913135638.395855-2-y.karadz@gmail.com> (raw)
In-Reply-To: <20210913135638.395855-1-y.karadz@gmail.com>

The default event handler for parsing ("info print") includes
the address of the probe. This address can be valuable for kernel
developers, but is meaningless if you only care for userspace.
Here we add a method that allows the user to register an alternative
event handler that doesn't show the address.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 examples/kprobe_open.py   |  1 +
 src/ftracepy-utils.c      | 38 ++++++++++++++++++++++++++++++++++++++
 src/ftracepy-utils.h      |  3 +++
 src/ftracepy.c            |  5 +++++
 tracecruncher/ft_utils.py |  8 ++++++++
 5 files changed, 55 insertions(+)

diff --git a/examples/kprobe_open.py b/examples/kprobe_open.py
index 99f6c8c..dff4861 100755
--- a/examples/kprobe_open.py
+++ b/examples/kprobe_open.py
@@ -27,6 +27,7 @@ open_probe.add_ptr_arg(name='mode',
 open_probe.register()
 
 tep = tc.local_tep()
+tc.short_kprobe_print(tep, [open_probe])
 
 def callback(event, record):
     print(tep.info(event, record))
diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index c076d3b..bddc4fc 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -533,6 +533,44 @@ PyObject *PyTep_process(PyTep *self, PyObject *args,
 	return PyUnicode_FromString(seq.buffer);
 }
 
+static int kprobe_info_short(struct trace_seq *s,
+			     struct tep_record *record,
+			     struct tep_event *event,
+			     void *context)
+{
+	/* Do not print the address of the probe (first field). */
+	unsigned long long select_mask = ~0x1;
+
+	tep_record_print_selected_fields(s, record, event, select_mask);
+
+	return 0;
+}
+
+PyObject *PyTep_short_kprobe_print(PyTep *self, PyObject *args,
+						PyObject *kwargs)
+{
+	static char *kwlist[] = {"system", "event", "id", NULL};
+	const char *system, *event;
+	int ret, id = -1;
+
+	system = event = NO_ARG;
+
+	if(!PyArg_ParseTupleAndKeywords(args,
+					kwargs,
+					"ss|i",
+					kwlist,
+					&system,
+					&event,
+					&id)) {
+		return false;
+	}
+
+	ret = tep_register_event_handler(self->ptrObj, id, system, event,
+					 kprobe_info_short, NULL);
+
+	return PyLong_FromLong(ret);
+}
+
 static bool check_file(struct tracefs_instance *instance, const char *file)
 {
 	if (!tracefs_file_exists(instance, file)) {
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index 6c4a109..9f4c4ba 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -63,6 +63,9 @@ PyObject *PyTep_info(PyTep *self, PyObject *args,
 PyObject *PyTep_process(PyTep *self, PyObject *args,
 				     PyObject *kwargs);
 
+PyObject *PyTep_short_kprobe_print(PyTep *self, PyObject *args,
+						PyObject *kwargs);
+
 PyObject *PyTfsInstance_dir(PyTfsInstance *self);
 
 PyObject *PyKprobe_event(PyKprobe *self);
diff --git a/src/ftracepy.c b/src/ftracepy.c
index c4458f0..cbf0ce0 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -83,6 +83,11 @@ static PyMethodDef PyTep_methods[] = {
 	 METH_VARARGS | METH_KEYWORDS,
 	 "Generic print of a trace event info."
 	},
+	{"short_kprobe_print",
+	 (PyCFunction) PyTep_short_kprobe_print,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Do not print the address of the probe."
+	},
 	{NULL}
 };
 
diff --git a/tracecruncher/ft_utils.py b/tracecruncher/ft_utils.py
index 5caaa76..1fc0648 100644
--- a/tracecruncher/ft_utils.py
+++ b/tracecruncher/ft_utils.py
@@ -29,6 +29,14 @@ def find_event_id(system, event):
     return tep.get_event(system=system, name=event).id()
 
 
+def short_kprobe_print(tep, events):
+    """ Register short (no probe address) print for these kprobe events.
+    """
+    for e in events:
+        if len(e.fields):
+            tep.short_kprobe_print(id=e.evt_id, system=e.system, event=e.name)
+
+
 class event:
     def __init__(self, system, name, static=True):
         """ Constructor.
-- 
2.30.2


      reply	other threads:[~2021-09-13 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 13:56 [PATCH 1/2] trace-cruncher: Add generic methods for printing Yordan Karadzhov (VMware)
2021-09-13 13:56 ` Yordan Karadzhov (VMware) [this message]

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=20210913135638.395855-2-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.