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@xxxxxxxxx> --- src/ftracepy-utils.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 9 +++++++++ src/ftracepy.c | 15 +++++++++++++++ 3 files changed, 69 insertions(+) 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} }; -- 2.32.0