linux-trace-devel.vger.kernel.org archive mirror
 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 v2 6/7] trace-cruncher: Define Python type for kprobes
Date: Thu, 19 Aug 2021 16:08:26 +0300	[thread overview]
Message-ID: <20210819130827.12327-7-y.karadz@gmail.com> (raw)
In-Reply-To: <20210819130827.12327-1-y.karadz@gmail.com>

Adding this new Python type is a preparation for a general
refactorung of the way kprobes are handled by trace-cruncher.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 34 ++++++++++++++++++++++++++++++++++
 src/ftracepy-utils.h | 14 ++++++++++++++
 src/ftracepy.c       | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 5d7d9af..b8bcb4c 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -1366,6 +1366,40 @@ PyObject *PyFtrace_tc_event_system(PyObject *self)
 	return PyUnicode_FromString(TC_SYS);
 }
 
+struct ftracepy_kprobe {
+	char *event;
+	char *function;
+	char *probe;
+};
+
+PyObject *PyKprobe_event(PyKprobe *self)
+{
+	return PyUnicode_FromString(self->ptrObj->event);
+}
+
+PyObject *PyKprobe_system(PyKprobe *self)
+{
+	return PyUnicode_FromString(TC_SYS);
+}
+
+PyObject *PyKprobe_function(PyKprobe *self)
+{
+	return PyUnicode_FromString(self->ptrObj->function);
+}
+
+PyObject *PyKprobe_probe(PyKprobe *self)
+{
+	return PyUnicode_FromString(self->ptrObj->probe);
+}
+
+void ftracepy_kprobe_free(struct ftracepy_kprobe *kp)
+{
+	free(kp->event);
+	free(kp->function);
+	free(kp->probe);
+	free(kp);
+}
+
 static int unregister_kprobe(const char *event)
 {
 	return tracefs_kprobe_clear_probe(TC_SYS, event, true);
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index 04de1f3..17e07e5 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -24,6 +24,12 @@ C_OBJECT_WRAPPER_DECLARE(tep_handle, PyTep)
 
 C_OBJECT_WRAPPER_DECLARE(tracefs_instance, PyTfsInstance)
 
+struct ftracepy_kprobe;
+
+void ftracepy_kprobe_free(struct ftracepy_kprobe *kp);
+
+C_OBJECT_WRAPPER_DECLARE(ftracepy_kprobe, PyKprobe);
+
 PyObject *PyTepRecord_time(PyTepRecord* self);
 
 PyObject *PyTepRecord_cpu(PyTepRecord* self);
@@ -48,6 +54,14 @@ PyObject *PyTep_get_event(PyTep *self, PyObject *args,
 
 PyObject *PyTfsInstance_dir(PyTfsInstance *self);
 
+PyObject *PyKprobe_event(PyKprobe *self);
+
+PyObject *PyKprobe_system(PyKprobe *self);
+
+PyObject *PyKprobe_function(PyKprobe *self);
+
+PyObject *PyKprobe_probe(PyKprobe *self);
+
 PyObject *PyFtrace_dir(PyObject *self);
 
 PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs);
diff --git a/src/ftracepy.c b/src/ftracepy.c
index 3c55e50..c434af9 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -86,6 +86,34 @@ C_OBJECT_WRAPPER(tracefs_instance, PyTfsInstance,
 		 tracefs_instance_destroy,
 		 tracefs_instance_free)
 
+static PyMethodDef PyKprobe_methods[] = {
+	{"event",
+	 (PyCFunction) PyKprobe_event,
+	 METH_NOARGS,
+	 "Get the name of the kprobe event."
+	},
+	{"system",
+	 (PyCFunction) PyKprobe_system,
+	 METH_NOARGS,
+	 "Get the system name of the kprobe event."
+	},
+	{"function",
+	 (PyCFunction) PyKprobe_function,
+	 METH_NOARGS,
+	 "Get the function name of the kprobe event."
+	},
+	{"probe",
+	 (PyCFunction) PyKprobe_probe,
+	 METH_NOARGS,
+	 "Get the kprobe event definition."
+	},
+	{NULL, NULL, 0, NULL}
+};
+
+C_OBJECT_WRAPPER(ftracepy_kprobe, PyKprobe,
+		 NO_DESTROY,
+		 ftracepy_kprobe_free)
+
 static PyMethodDef ftracepy_methods[] = {
 	{"dir",
 	 (PyCFunction) PyFtrace_dir,
@@ -322,6 +350,9 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
 	if (!PyTfsInstanceTypeInit())
 		return NULL;
 
+	if (!PyKprobeTypeInit())
+		return NULL;
+
 	TFS_ERROR = PyErr_NewException("tracecruncher.ftracepy.tfs_error",
 				       NULL, NULL);
 
@@ -337,6 +368,7 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
 	PyModule_AddObject(module, "tep_event", (PyObject *) &PyTepEventType);
 	PyModule_AddObject(module, "tep_record", (PyObject *) &PyTepRecordType);
 	PyModule_AddObject(module, "tracefs_instance", (PyObject *) &PyTfsInstanceType);
+	PyModule_AddObject(module, "ftracepy_kprobe", (PyObject *) &PyKprobeType);
 
 	PyModule_AddObject(module, "tfs_error", TFS_ERROR);
 	PyModule_AddObject(module, "tep_error", TEP_ERROR);
-- 
2.30.2


  parent reply	other threads:[~2021-08-19 13:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 13:08 [PATCH v2 0/7] trace-cruncher: Refactor instances and kprobes Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 1/7] trace-cruncher: Use proper naming in common.h Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 2/7] trace-cruncher: Add type checking for the custom Python types Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 3/7] trace-cruncher: Allow for detachable custom objects Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 4/7] trace-cruncher: Define Python type for instances Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 5/7] trace-cruncher: Refactor the way libtracefs instances are handled Yordan Karadzhov (VMware)
2021-08-19 13:08 ` Yordan Karadzhov (VMware) [this message]
2021-08-19 13:08 ` [PATCH v2 7/7] trace-cruncher: Refactor the way kprobes " Yordan Karadzhov (VMware)
2021-08-19 19:54 ` [PATCH v2 0/7] trace-cruncher: Refactor instances and kprobes Steven Rostedt

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=20210819130827.12327-7-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 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).