diff mbox series

[3/4] trace-cruncher: Add optional sort to available_event_systems()

Message ID 20210831125357.56862-3-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series [1/4] trace-cruncher: Add optional sort to tfs_list2py_list() | expand

Commit Message

Yordan Karadzhov Aug. 31, 2021, 12:53 p.m. UTC
An optional parameter 'sort' is added. If set to True, the returned
list of system names is sorted in alphabetical order. The default
value of 'sort' is False.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index f884106..b94745d 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -717,17 +717,29 @@  PyObject *PyFtrace_get_current_tracer(PyObject *self, PyObject *args,
 PyObject *PyFtrace_available_event_systems(PyObject *self, PyObject *args,
 							   PyObject *kwargs)
 {
+	static char *kwlist[] = {"instance", "sort", NULL};
 	struct tracefs_instance *instance;
+	PyObject *py_inst = NULL;
+	int sort = false;
 	char **list;
 
-	if (!get_instance_from_arg(args, kwargs, &instance))
+	if (!PyArg_ParseTupleAndKeywords(args,
+					 kwargs,
+					 "|Op",
+					 kwlist,
+					 &py_inst,
+					 &sort)) {
+		return false;
+	}
+
+	if (!get_optional_instance(py_inst, &instance))
 		return NULL;
 
 	list = tracefs_event_systems(tracefs_instance_get_dir(instance));
 	if (!list)
 		return NULL;
 
-	return tfs_list2py_list(list, false);
+	return tfs_list2py_list(list, sort);
 }
 
 PyObject *PyFtrace_available_system_events(PyObject *self, PyObject *args,