@@ -1192,6 +1192,58 @@ PyObject *PySynthEvent_unregister(PySynthEvent *self)
Py_RETURN_NONE;
}
+PyObject *PySynthEvent_repr(PySynthEvent *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = {"event", "hist_start", "hist_end", NULL};
+ int event, hist_start, hist_end;
+ char buff[2048] = {0};
+ bool new_line = false;
+ const char *str = NULL;
+
+ event = hist_start = hist_end = true;
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kwargs,
+ "|ppp",
+ kwlist,
+ &event,
+ &hist_start,
+ &hist_end)) {
+ return NULL;
+ }
+
+ if (event) {
+ strcat(buff, "synth. event: ");
+ str = tracefs_synth_show_event(self->ptrObj);
+ if (str)
+ strcat(buff, str);
+ new_line = true;
+ }
+
+ if (hist_start) {
+ if (new_line)
+ strcat(buff, "\n");
+ else
+ new_line = true;
+
+ strcat(buff, "hist. start: ");
+ str = tracefs_synth_show_start_hist(self->ptrObj);
+ if (str)
+ strcat(buff, str);
+ }
+
+ if (hist_end) {
+ if (new_line)
+ strcat(buff, "\n");
+
+ strcat(buff, "hist. end: ");
+ str = tracefs_synth_show_end_hist(self->ptrObj);
+ if (str)
+ strcat(buff, str);
+ }
+
+ return PyUnicode_FromString(strdup(buff));
+}
+
PyObject *PyFtrace_dir(PyObject *self)
{
return PyUnicode_FromString(tracefs_tracing_dir());
@@ -161,6 +161,8 @@ PyObject *PySynthEvent_get_filter(PySynthEvent *self, PyObject *args,
PyObject *PySynthEvent_clear_filter(PySynthEvent *self, PyObject *args,
PyObject *kwargs);
+PyObject *PySynthEvent_repr(PySynthEvent *self, PyObject *args, PyObject *kwargs);
+
PyObject *PyFtrace_dir(PyObject *self);
PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs);
@@ -292,6 +292,11 @@ static PyMethodDef PySynthEvent_methods[] = {
METH_VARARGS | METH_KEYWORDS,
"Clear the filter of a synthetic event."
},
+ {"repr",
+ (PyCFunction) PySynthEvent_repr,
+ METH_VARARGS | METH_KEYWORDS,
+ "Show a representative descriptor of the synth. event."
+ },
{NULL, NULL, 0, NULL}
};
Here we add the following method to the Python type for synthetic events: repr() The new APIs provides a representative descriptor of the synth. event, including the dynamic event and the two histograms. It can be useful in the case where the user wants to check what exactly gets passed to the kernel as definition of a synth event. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> --- src/ftracepy-utils.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 2 ++ src/ftracepy.c | 5 +++++ 3 files changed, 59 insertions(+)