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@xxxxxxxxx> --- src/ftracepy-utils.c | 5 +++++ src/ftracepy-utils.h | 4 ++++ src/ftracepy.c | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 6739db7..6b2f879 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -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()); diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 5d7c19c..cf75e0b 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -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_create_instance(PyObject *self, PyObject *args, diff --git a/src/ftracepy.c b/src/ftracepy.c index e3fec7b..628a53a 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -73,6 +73,17 @@ static PyMethodDef PyTep_methods[] = { C_OBJECT_WRAPPER(tep_handle, PyTep, 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) + static PyMethodDef ftracepy_methods[] = { {"dir", (PyCFunction) PyFtrace_dir, @@ -321,6 +332,9 @@ PyMODINIT_FUNC PyInit_ftracepy(void) if (!PyTepRecordTypeInit()) return NULL; + if (!PyTfsInstanceTypeInit()) + return NULL; + TFS_ERROR = PyErr_NewException("tracecruncher.ftracepy.tfs_error", NULL, NULL); @@ -335,6 +349,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); -- 2.30.2