Here we add the following methods to the Python type for synthetic events: register() unregister() The constructor only creates the objects that describe the new synthetic event. We need to use those new APIs in order to actually create/destroy the event into the system. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- src/ftracepy-utils.c | 42 +++++++++++++++++++++++++++++++++++++----- src/ftracepy-utils.h | 4 ++++ src/ftracepy.c | 10 ++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 9245b07..244bff9 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1154,17 +1154,49 @@ PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args, Py_RETURN_NONE; } -PyObject *PyFtrace_dir(PyObject *self) -{ - return PyUnicode_FromString(tracefs_tracing_dir()); -} - static void set_destroy_flag(PyObject *py_obj, bool val) { PyFtrace_Object_HEAD *obj_head = (PyFtrace_Object_HEAD *)py_obj; obj_head->destroy = val; } +PyObject *PySynthEvent_register(PySynthEvent *self) +{ + if (tracefs_synth_create(self->ptrObj) < 0) { + TfsError_fmt(NULL, "Failed to register synth. event %s", + tracefs_synth_get_name(self->ptrObj)); + return NULL; + } + + /* + * Here the synthetic event gets added to the system. + * Hence we need to 'destroy' this event at exit. + */ + set_destroy_flag((PyObject *)self, true); + Py_RETURN_NONE; +} + +PyObject *PySynthEvent_unregister(PySynthEvent *self) +{ + if (tracefs_synth_destroy(self->ptrObj) < 0) { + TfsError_fmt(NULL, "Failed to unregister synth. event %s", + tracefs_synth_get_name(self->ptrObj)); + return NULL; + } + + /* + * Here the synthetic event gets removed from the system. + * Hence we no loger need to 'destroy' this event at exit. + */ + set_destroy_flag((PyObject *)self, false); + Py_RETURN_NONE; +} + +PyObject *PyFtrace_dir(PyObject *self) +{ + return PyUnicode_FromString(tracefs_tracing_dir()); +} + static PyObject *set_destroy(PyObject *args, PyObject *kwargs, bool destroy) { static char *kwlist[] = {"object", NULL}; diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 7b798fc..40b41d8 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -139,6 +139,10 @@ PyObject *PySynthEvent_add_delta_T(PySynthEvent *self, PyObject *args, PyObject *PySynthEvent_add_sum(PySynthEvent *self, PyObject *args, PyObject *kwargs); +PyObject *PySynthEvent_register(PySynthEvent *self); + +PyObject *PySynthEvent_unregister(PySynthEvent *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 066fc65..0314aa1 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -252,6 +252,16 @@ static PyMethodDef PySynthEvent_methods[] = { METH_VARARGS | METH_KEYWORDS, "Add 'start + end' field." }, + {"register", + (PyCFunction) PySynthEvent_register, + METH_NOARGS, + "Register synth. event to a trace instance." + }, + {"unregister", + (PyCFunction) PySynthEvent_unregister, + METH_NOARGS, + "Unregister synth. event from a trace instance." + }, {NULL, NULL, 0, NULL} }; -- 2.32.0
![]() |