@@ -531,6 +531,11 @@ bool get_instance_from_arg(PyObject *args, PyObject *kwargs,
return true;
}
+PyObject *PyTfsInstance_dir(PyTfsInstance *self)
+{
+ return PyUnicode_FromString(tracefs_instance_get_dir(self->ptrObj));
+}
+
PyObject *PyFtrace_dir(PyObject *self)
{
return PyUnicode_FromString(tracefs_tracing_dir());
@@ -22,6 +22,8 @@ C_OBJECT_WRAPPER_DECLARE(tep_event, PyTepEvent)
C_OBJECT_WRAPPER_DECLARE(tep_handle, PyTep)
+C_OBJECT_WRAPPER_DECLARE(tracefs_instance, PyTfsInstance)
+
PyObject *PyTepRecord_time(PyTepRecord* self);
PyObject *PyTepRecord_cpu(PyTepRecord* self);
@@ -44,6 +46,8 @@ PyObject *PyTep_init_local(PyTep *self, PyObject *args,
PyObject *PyTep_get_event(PyTep *self, PyObject *args,
PyObject *kwargs);
+PyObject *PyTfsInstance_dir(PyTfsInstance *self);
+
PyObject *PyFtrace_dir(PyObject *self);
PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs);
@@ -73,6 +73,19 @@ static PyMethodDef PyTep_methods[] = {
C_OBJECT_WRAPPER(tep_handle, PyTep, NO_DESTROY, tep_free)
+static PyMethodDef PyTfsInstance_methods[] = {
+ {"dir",
+ (PyCFunction) PyTfsInstance_dir,
+ METH_NOARGS,
+ "Get the absolute path to the instance directory."
+ },
+ {NULL, NULL, 0, NULL}
+};
+
+C_OBJECT_WRAPPER(tracefs_instance, PyTfsInstance,
+ tracefs_instance_destroy,
+ tracefs_instance_free)
+
static PyMethodDef ftracepy_methods[] = {
{"dir",
(PyCFunction) PyFtrace_dir,
@@ -326,6 +339,9 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
if (!PyTepRecordTypeInit())
return NULL;
+ if (!PyTfsInstanceTypeInit())
+ return NULL;
+
TFS_ERROR = PyErr_NewException("tracecruncher.ftracepy.tfs_error",
NULL, NULL);
@@ -340,6 +356,7 @@ PyMODINIT_FUNC PyInit_ftracepy(void)
PyModule_AddObject(module, "tep_handle", (PyObject *) &PyTepType);
PyModule_AddObject(module, "tep_event", (PyObject *) &PyTepEventType);
PyModule_AddObject(module, "tep_record", (PyObject *) &PyTepRecordType);
+ PyModule_AddObject(module, "tracefs_instance", (PyObject *) &PyTfsInstanceType);
PyModule_AddObject(module, "tfs_error", TFS_ERROR);
PyModule_AddObject(module, "tep_error", TEP_ERROR);
We add a custom Python type that wraps the 'tracefs_instance' object, defined in libtracefs. This is a preparation for a general refactorung of the way libtracefs instances are handled by trace-cruncher. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> --- src/ftracepy-utils.c | 5 +++++ src/ftracepy-utils.h | 4 ++++ src/ftracepy.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+)