linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] trace-cruncher: Cleanup in class event
@ 2022-01-26 12:31 Yordan Karadzhov (VMware)
  2022-01-26 12:31 ` [PATCH 2/2] trace-cruncher: Add no_arg() Yordan Karadzhov (VMware)
  0 siblings, 1 reply; 2+ messages in thread
From: Yordan Karadzhov (VMware) @ 2022-01-26 12:31 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

The 'instance_list' field of the class event is a legacy from an old
implementation of the cleanup that was done in the destructor of the
class. Currently this field is useless and has to be removed.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 tracecruncher/ft_utils.py | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/tracecruncher/ft_utils.py b/tracecruncher/ft_utils.py
index ed4bdcd..e1126ad 100644
--- a/tracecruncher/ft_utils.py
+++ b/tracecruncher/ft_utils.py
@@ -43,7 +43,6 @@ class event:
         """
         self.system = system
         self.name = name
-        self.instance_list = []
         if static:
             self.evt_id = find_event_id(system, name)
             if self.evt_id < 0:
@@ -61,22 +60,16 @@ class event:
         """
         if instance is None:
             ft.enable_event(system=self.system, event=self.name)
-            self.instance_list.append('top')
         else:
             ft.enable_event(instance=instance, system=self.system, event=self.name)
-            self.instance_list.append(instance)
-
-        self.instance_list = list(set(self.instance_list))
 
     def disable(self, instance=None):
         """ Disable this event.
         """
         if instance is None:
             ft.disable_event(system=self.system, event=self.name)
-            self.instance_list.remove('top')
         else:
             ft.disable_event(instance=instance,system=self.system, event=self.name)
-            self.instance_list.remove(instance)
 
     def set_filter(self, filter, instance=None):
         """ Define a filter for this event.
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] trace-cruncher: Add no_arg()
  2022-01-26 12:31 [PATCH 1/2] trace-cruncher: Cleanup in class event Yordan Karadzhov (VMware)
@ 2022-01-26 12:31 ` Yordan Karadzhov (VMware)
  0 siblings, 0 replies; 2+ messages in thread
From: Yordan Karadzhov (VMware) @ 2022-01-26 12:31 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

In the implementation of the low-level APIs wrapping libtracefs,
a special string is used as a default value of the optional function
arguments. Here we make this string available for the high-level
APIs. This simplifies the implementation of the cases when optional
arguments are used.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c      |  5 +++++
 src/ftracepy-utils.h      |  2 ++
 src/ftracepy.c            |  5 +++++
 tracecruncher/ft_utils.py | 41 +++++++++++++--------------------------
 4 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 8c46590..8ff6601 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -2178,6 +2178,11 @@ PyObject *PyFtrace_tc_event_system(PyObject *self)
 	return PyUnicode_FromString(TC_SYS);
 }
 
+PyObject *PyFtrace_no_arg(PyObject *self)
+{
+	return PyUnicode_FromString(NO_ARG);
+}
+
 static PyObject *dynevent_info2py(char *buff, int type)
 {
 	PyObject *ret;
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index 7612df6..29a7312 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -245,6 +245,8 @@ PyObject *PyFtrace_enabled_options(PyObject *self, PyObject *args,
 
 PyObject *PyFtrace_tc_event_system(PyObject *self);
 
+PyObject *PyFtrace_no_arg(PyObject *self);
+
 PyObject *PyFtrace_register_kprobe(PyObject *self, PyObject *args,
 						   PyObject *kwargs);
 
diff --git a/src/ftracepy.c b/src/ftracepy.c
index 3f71b5e..82057ed 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -450,6 +450,11 @@ static PyMethodDef ftracepy_methods[] = {
 	 METH_NOARGS,
 	 "Get the name of the event system used by trace-cruncher."
 	},
+	{"no_arg",
+	 (PyCFunction) PyFtrace_no_arg,
+	 METH_NOARGS,
+	 "Returns a default value for an optional function argument."
+	},
 	{"register_kprobe",
 	 (PyCFunction) PyFtrace_register_kprobe,
 	 METH_VARARGS | METH_KEYWORDS,
diff --git a/tracecruncher/ft_utils.py b/tracecruncher/ft_utils.py
index e1126ad..39faaed 100644
--- a/tracecruncher/ft_utils.py
+++ b/tracecruncher/ft_utils.py
@@ -55,45 +55,30 @@ class event:
         """
         return int(self.evt_id)
 
-    def enable(self, instance=None):
+    def enable(self, instance=ft.no_arg()):
         """ Enable this event.
         """
-        if instance is None:
-            ft.enable_event(system=self.system, event=self.name)
-        else:
-            ft.enable_event(instance=instance, system=self.system, event=self.name)
+        ft.enable_event(instance=instance, system=self.system, event=self.name)
 
-    def disable(self, instance=None):
+    def disable(self, instance=ft.no_arg()):
         """ Disable this event.
         """
-        if instance is None:
-            ft.disable_event(system=self.system, event=self.name)
-        else:
-            ft.disable_event(instance=instance,system=self.system, event=self.name)
+        ft.disable_event(instance=instance,system=self.system, event=self.name)
 
-    def set_filter(self, filter, instance=None):
+    def set_filter(self, filter, instance=ft.no_arg()):
         """ Define a filter for this event.
         """
-        if instance is None:
-            ft.set_event_filter(system=self.system,
-                                event=self.name,
-                                filter=filter)
-        else:
-            ft.set_event_filter(instance=instance,
-                                system=self.system,
-                                event=self.name,
-                                filter=filter)
+        ft.set_event_filter(instance=instance,
+                            system=self.system,
+                            event=self.name,
+                            filter=filter)
 
-    def clear_filter(self, instance=None):
+    def clear_filter(self, instance=ft.no_arg()):
         """ Define the filter for this event.
         """
-        if instance is None:
-            ft.clear_event_filter(system=self.system,
-                                  event=self.name)
-        else:
-            ft.clear_event_filter(instance=instance,
-                                  system=self.system,
-                                  event=self.name)
+        ft.clear_event_filter(instance=instance,
+                              system=self.system,
+                              event=self.name)
 
 
 class kprobe_base(event):
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-26 12:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-26 12:31 [PATCH 1/2] trace-cruncher: Cleanup in class event Yordan Karadzhov (VMware)
2022-01-26 12:31 ` [PATCH 2/2] trace-cruncher: Add no_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).