diff mbox series

[05/10] trace-cruncher: APIs for enabling synth. events

Message ID 20220124085625.92297-6-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series trace-cruncher: Synthetic events | expand

Commit Message

Yordan Karadzhov Jan. 24, 2022, 8:56 a.m. UTC
Here we add the following methods to the Python type for synthetic
events:

enable()
disable()
is_enabled()

The 3 new APIs replicate the APIs available for kpobes.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 src/ftracepy-utils.h |  9 +++++++++
 src/ftracepy.c       | 15 +++++++++++++++
 3 files changed, 69 insertions(+)
diff mbox series

Patch

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 244bff9..8a0c3c3 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -2661,6 +2661,51 @@  PyObject *PyFtrace_synth(PyObject *self, PyObject *args,
 	return py_synth;
 }
 
+#define SYNTH_SYS "synthetic"
+
+static bool enable_synth(PySynthEvent *self, PyObject *args, PyObject *kwargs,
+			 bool enable)
+{
+	struct tracefs_instance *instance;
+
+	if (!get_instance_from_arg(args, kwargs, &instance))
+		return NULL;
+
+	return event_enable_disable(instance, SYNTH_SYS,
+				    tracefs_synth_get_name(self->ptrObj),
+				    enable);
+}
+
+PyObject *PySynthEvent_enable(PySynthEvent *self, PyObject *args,
+						  PyObject *kwargs)
+{
+	if (!enable_synth(self, args, kwargs, true))
+		return NULL;
+
+	Py_RETURN_NONE;
+}
+
+PyObject *PySynthEvent_disable(PySynthEvent *self, PyObject *args,
+						   PyObject *kwargs)
+{
+	if (!enable_synth(self, args, kwargs, false))
+		return NULL;
+
+	Py_RETURN_NONE;
+}
+
+PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args,
+						      PyObject *kwargs)
+{
+	struct tracefs_instance *instance;
+
+	if (!get_instance_from_arg(args, kwargs, &instance))
+		return NULL;
+
+	return event_is_enabled(instance, SYNTH_SYS,
+				tracefs_synth_get_name(self->ptrObj));
+}
+
 PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args,
 						       PyObject *kwargs)
 {
diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h
index 40b41d8..daf1a19 100644
--- a/src/ftracepy-utils.h
+++ b/src/ftracepy-utils.h
@@ -143,6 +143,15 @@  PyObject *PySynthEvent_register(PySynthEvent *self);
 
 PyObject *PySynthEvent_unregister(PySynthEvent *self);
 
+PyObject *PySynthEvent_enable(PySynthEvent *self, PyObject *args,
+						  PyObject *kwargs);
+
+PyObject *PySynthEvent_disable(PySynthEvent *self, PyObject *args,
+						   PyObject *kwargs);
+
+PyObject *PySynthEvent_is_enabled(PySynthEvent *self, PyObject *args,
+						      PyObject *kwargs);
+
 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 0314aa1..62c6de0 100644
--- a/src/ftracepy.c
+++ b/src/ftracepy.c
@@ -262,6 +262,21 @@  static PyMethodDef PySynthEvent_methods[] = {
 	 METH_NOARGS,
 	 "Unregister synth. event from a trace instance."
 	},
+	{"enable",
+	 (PyCFunction) PySynthEvent_enable,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Enable synth. event."
+	},
+	{"disable",
+	 (PyCFunction) PySynthEvent_disable,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Disable synth. event."
+	},
+	{"is_enabled",
+	 (PyCFunction) PySynthEvent_is_enabled,
+	 METH_VARARGS | METH_KEYWORDS,
+	 "Check if synth. event is enabled."
+	},
 	{NULL, NULL, 0, NULL}
 };