linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cruncher: Always use get_instance_from_arg()
@ 2021-10-01 13:22 Yordan Karadzhov (VMware)
  0 siblings, 0 replies; only message in thread
From: Yordan Karadzhov (VMware) @ 2021-10-01 13:22 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

Avoid the code duplication in the case when the Python method takes
only a single 'instance' argument.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 36 +++---------------------------------
 1 file changed, 3 insertions(+), 33 deletions(-)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 7b1ff1b..ca7f914 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -1889,19 +1889,9 @@ PyObject *PyKprobe_clear_filter(PyKprobe *self, PyObject *args,
 						PyObject *kwargs)
 {
 	struct tracefs_instance *instance;
-	PyObject *py_inst = NULL;
 	char path[PATH_MAX];
 
-	static char *kwlist[] = {"instance", NULL};
-	if (!PyArg_ParseTupleAndKeywords(args,
-					 kwargs,
-					 "|O",
-					 kwlist,
-					 &py_inst)) {
-		return NULL;
-	}
-
-	if (!get_optional_instance(py_inst, &instance))
+	if (!get_instance_from_arg(args, kwargs, &instance))
 		return NULL;
 
 	sprintf(path, "events/%s/%s/filter", TC_SYS, self->ptrObj->event);
@@ -1916,19 +1906,9 @@ PyObject *PyKprobe_clear_filter(PyKprobe *self, PyObject *args,
 static bool enable_kprobe(PyKprobe *self, PyObject *args, PyObject *kwargs,
 			  bool enable)
 {
-	static char *kwlist[] = {"instance", NULL};
 	struct tracefs_instance *instance;
-	PyObject *py_inst = NULL;
-
-	if (!PyArg_ParseTupleAndKeywords(args,
-					 kwargs,
-					 "|O",
-					 kwlist,
-					 &py_inst)) {
-		return false;
-	}
 
-	if (!get_optional_instance(py_inst, &instance))
+	if (!get_instance_from_arg(args, kwargs, &instance))
 		return false;
 
 	return event_enable_disable(instance, TC_SYS, self->ptrObj->event,
@@ -1956,19 +1936,9 @@ PyObject *PyKprobe_disable(PyKprobe *self, PyObject *args,
 PyObject *PyKprobe_is_enabled(PyKprobe *self, PyObject *args,
 					      PyObject *kwargs)
 {
-	static char *kwlist[] = {"instance", NULL};
 	struct tracefs_instance *instance;
-	PyObject *py_inst = NULL;
-
-	if (!PyArg_ParseTupleAndKeywords(args,
-					 kwargs,
-					 "|O",
-					 kwlist,
-					 &py_inst)) {
-		return NULL;
-	}
 
-	if (!get_optional_instance(py_inst, &instance))
+	if (!get_instance_from_arg(args, kwargs, &instance))
 		return NULL;
 
 	return event_is_enabled(instance, TC_SYS, self->ptrObj->event);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-01 13:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 13:22 [PATCH] trace-cruncher: Always use get_instance_from_arg() Yordan Karadzhov (VMware)

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