[PATCH 1/4] trace-cruncher: Add optional sort to tfs_list2py_list()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This helper function is used to convert the NULL-terminated array
of strings returned by the APIs of libtracefs into a Python list
of strings. Here we add an option the returned string to be sorted
in alphabetical order.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx>
---
 src/ftracepy-utils.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 53fc95f..0fcadd8 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -475,7 +475,7 @@ static bool write_to_file_and_check(struct tracefs_instance *instance,
 	return ret == 0 ? true : false;
 }
 
-static PyObject *tfs_list2py_list(char **list)
+static PyObject *tfs_list2py_list(char **list, bool sort)
 {
 	PyObject *py_list = PyList_New(0);
 	int i;
@@ -483,6 +483,9 @@ static PyObject *tfs_list2py_list(char **list)
 	for (i = 0; list && list[i]; i++)
 		PyList_Append(py_list, PyUnicode_FromString(list[i]));
 
+	if (sort)
+		PyList_Sort(py_list);
+
 	tracefs_list_free(list);
 
 	return py_list;
@@ -636,7 +639,7 @@ PyObject *PyFtrace_available_tracers(PyObject *self, PyObject *args,
 	if (!list)
 		return NULL;
 
-	return tfs_list2py_list(list);
+	return tfs_list2py_list(list, false);
 }
 
 PyObject *PyFtrace_set_current_tracer(PyObject *self, PyObject *args,
@@ -724,7 +727,7 @@ PyObject *PyFtrace_available_event_systems(PyObject *self, PyObject *args,
 	if (!list)
 		return NULL;
 
-	return tfs_list2py_list(list);
+	return tfs_list2py_list(list, false);
 }
 
 PyObject *PyFtrace_available_system_events(PyObject *self, PyObject *args,
@@ -750,10 +753,11 @@ PyObject *PyFtrace_available_system_events(PyObject *self, PyObject *args,
 
 	list = tracefs_system_events(tracefs_instance_get_dir(instance),
 				     system);
+
 	if (!list)
 		return NULL;
 
-	return tfs_list2py_list(list);
+	return tfs_list2py_list(list, false);
 }
 
 bool get_event_enable_file(struct tracefs_instance *instance,
-- 
2.30.2




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux