@@ -2426,6 +2426,64 @@ PyObject *PyFtrace_hist(PyObject *self, PyObject *args,
return NULL;
}
+PyObject *PyFtrace_synth(PyObject *self, PyObject *args,
+ PyObject *kwargs)
+{
+ const char *name, *start_match, *end_match, *match_name=NULL;
+ const char *start_sys, *start_evt, *end_sys, *end_evt;
+ static char *kwlist[] = {"name",
+ "start_sys",
+ "start_evt",
+ "end_sys",
+ "end_evt",
+ "start_match",
+ "end_match",
+ "match_name",
+ NULL};
+ static struct tracefs_synth *synth;
+ struct tep_handle *tep;
+ PyObject *py_synth;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kwargs,
+ "sssssss|s",
+ kwlist,
+ &name,
+ &start_sys,
+ &start_evt,
+ &end_sys,
+ &end_evt,
+ &start_match,
+ &end_match,
+ &match_name)) {
+ return NULL;
+ }
+
+ tep = get_tep(NULL, NULL);
+ if (!tep)
+ return NULL;
+
+ synth = tracefs_synth_alloc(tep, name,
+ start_sys, start_evt,
+ end_sys, end_evt,
+ start_match, end_match,
+ match_name);
+ tep_free(tep);
+ if (!synth) {
+ MEM_ERROR;
+ return NULL;
+ }
+
+ py_synth = PySynthEvent_New(synth);
+ /*
+ * Here we only allocated and initializes a synthetic event object.
+ * However, no synthetic event is added to the system yet. Hence,
+ * there is no need to 'destroy' this event at exit.
+ */
+ set_destroy_flag(py_synth, false);
+ return py_synth;
+}
+
PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args,
PyObject *kwargs)
{
@@ -30,6 +30,8 @@ C_OBJECT_WRAPPER_DECLARE(tracefs_dynevent, PyDynevent);
C_OBJECT_WRAPPER_DECLARE(tracefs_hist, PyTraceHist)
+C_OBJECT_WRAPPER_DECLARE(tracefs_synth, PySynthEvent)
+
PyObject *PyTepRecord_time(PyTepRecord* self);
PyObject *PyTepRecord_cpu(PyTepRecord* self);
@@ -210,6 +212,9 @@ PyObject *PyFtrace_register_kretprobe(PyObject *self, PyObject *args,
PyObject *PyFtrace_hist(PyObject *self, PyObject *args,
PyObject *kwargs);
+PyObject *PyFtrace_synth(PyObject *self, PyObject *args,
+ PyObject *kwargs);
+
PyObject *PyFtrace_set_ftrace_loglevel(PyObject *self, PyObject *args,
PyObject *kwargs);
@@ -221,6 +221,14 @@ C_OBJECT_WRAPPER(tracefs_hist, PyTraceHist,
NO_DESTROY,
tracefs_hist_free)
+static PyMethodDef PySynthEvent_methods[] = {
+ {NULL, NULL, 0, NULL}
+};
+
+C_OBJECT_WRAPPER(tracefs_synth, PySynthEvent,
+ tracefs_synth_destroy,
+ tracefs_synth_free)
+
static PyMethodDef ftracepy_methods[] = {
{"dir",
(PyCFunction) PyFtrace_dir,
@@ -382,6 +390,11 @@ static PyMethodDef ftracepy_methods[] = {
METH_VARARGS | METH_KEYWORDS,
"Define a histogram."
},
+ {"synth",
+ (PyCFunction) PyFtrace_synth,
+ METH_VARARGS | METH_KEYWORDS,
+ "Define a synthetic event."
+ },
{"set_ftrace_loglevel",
(PyCFunction) PyFtrace_set_ftrace_loglevel,
METH_VARARGS | METH_KEYWORDS,
@@ -453,6 +466,9 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
if (!PyTraceHistTypeInit())
return NULL;
+ if (!PySynthEventTypeInit())
+ return NULL;
+
TFS_ERROR = PyErr_NewException("tracecruncher.ftracepy.tfs_error",
NULL, NULL);
@@ -470,6 +486,7 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
PyModule_AddObject(module, "tracefs_instance", (PyObject *) &PyTfsInstanceType);
PyModule_AddObject(module, "tracefs_dynevent", (PyObject *) &PyDyneventType);
PyModule_AddObject(module, "tracefs_hist", (PyObject *) &PyTraceHistType);
+ PyModule_AddObject(module, "tracefs_synth", (PyObject *) &PySynthEventType);
PyModule_AddObject(module, "tfs_error", TFS_ERROR);
PyModule_AddObject(module, "tep_error", TEP_ERROR);
Addind new Python type and constructor for it: synth() The new type 'PySynthEvent will be used to implement APIs for working with synthetic events. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> --- src/ftracepy-utils.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/ftracepy-utils.h | 5 ++++ src/ftracepy.c | 17 +++++++++++++ 3 files changed, 80 insertions(+)