All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] trace-cruncher: Add optional sort to tfs_list2py_list()
@ 2021-08-31 12:53 Yordan Karadzhov (VMware)
  2021-08-31 12:53 ` [PATCH 2/4] trace-cruncher: Add optional sort to available_system_events() Yordan Karadzhov (VMware)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-08-31 12:53 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] trace-cruncher: Add optional sort to available_system_events()
  2021-08-31 12:53 [PATCH 1/4] trace-cruncher: Add optional sort to tfs_list2py_list() Yordan Karadzhov (VMware)
@ 2021-08-31 12:53 ` Yordan Karadzhov (VMware)
  2021-08-31 12:53 ` [PATCH 3/4] trace-cruncher: Add optional sort to available_event_systems() Yordan Karadzhov (VMware)
  2021-08-31 12:53 ` [PATCH 4/4] trace-cruncher: Add tests for sorted events/systems Yordan Karadzhov (VMware)
  2 siblings, 0 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-08-31 12:53 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

An optional parameter 'sort' is added. If set to True, the returned
list of event 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 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 0fcadd8..f884106 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -733,18 +733,20 @@ PyObject *PyFtrace_available_event_systems(PyObject *self, PyObject *args,
 PyObject *PyFtrace_available_system_events(PyObject *self, PyObject *args,
 							   PyObject *kwargs)
 {
-	static char *kwlist[] = {"system", "instance", NULL};
+	static char *kwlist[] = {"system", "instance", "sort", NULL};
 	struct tracefs_instance *instance;
 	PyObject *py_inst = NULL;
 	const char *system;
+	int sort = false;
 	char **list;
 
 	if (!PyArg_ParseTupleAndKeywords(args,
 					 kwargs,
-					 "s|O",
+					 "s|Op",
 					 kwlist,
 					 &system,
-					 &py_inst)) {
+					 &py_inst,
+					 &sort)) {
 		return NULL;
 	}
 
@@ -757,7 +759,7 @@ PyObject *PyFtrace_available_system_events(PyObject *self, PyObject *args,
 	if (!list)
 		return NULL;
 
-	return tfs_list2py_list(list, false);
+	return tfs_list2py_list(list, sort);
 }
 
 bool get_event_enable_file(struct tracefs_instance *instance,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] trace-cruncher: Add optional sort to available_event_systems()
  2021-08-31 12:53 [PATCH 1/4] trace-cruncher: Add optional sort to tfs_list2py_list() Yordan Karadzhov (VMware)
  2021-08-31 12:53 ` [PATCH 2/4] trace-cruncher: Add optional sort to available_system_events() Yordan Karadzhov (VMware)
@ 2021-08-31 12:53 ` Yordan Karadzhov (VMware)
  2021-08-31 12:53 ` [PATCH 4/4] trace-cruncher: Add tests for sorted events/systems Yordan Karadzhov (VMware)
  2 siblings, 0 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-08-31 12:53 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

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 --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,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] trace-cruncher: Add tests for sorted events/systems
  2021-08-31 12:53 [PATCH 1/4] trace-cruncher: Add optional sort to tfs_list2py_list() Yordan Karadzhov (VMware)
  2021-08-31 12:53 ` [PATCH 2/4] trace-cruncher: Add optional sort to available_system_events() Yordan Karadzhov (VMware)
  2021-08-31 12:53 ` [PATCH 3/4] trace-cruncher: Add optional sort to available_event_systems() Yordan Karadzhov (VMware)
@ 2021-08-31 12:53 ` Yordan Karadzhov (VMware)
  2 siblings, 0 replies; 4+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-08-31 12:53 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

An optional parameter 'sort' was added to available_event_systems()
and available_system_events(). Here we add the corresponding test
cases.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 .../tests/1_unit/test_01_ftracepy_unit.py          | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
index 971fd5f..710d3e1 100644
--- a/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
+++ b/tracecruncher/tests/1_unit/test_01_ftracepy_unit.py
@@ -111,19 +111,23 @@ class TracersTestCase(unittest.TestCase):
 
 class EventsTestCase(unittest.TestCase):
     def test_available_systems(self):
-        systems = ft.available_event_systems()
-        self.assertTrue(len(systems) > 1)
+        systems = ft.available_event_systems(sort=True)
+        self.assertTrue(len(systems) > 2)
         self.assertTrue('sched' in systems)
+        for i in range(len(systems) - 2):
+            self.assertTrue(systems[i] < systems[i + 1])
 
         inst = ft.create_instance(instance_name)
         systems = ft.available_event_systems(inst)
-        self.assertTrue(len(systems) > 1)
+        self.assertTrue(len(systems) > 2)
         self.assertTrue('sched' in systems)
 
     def test_available_system_events(self):
-        events = ft.available_system_events(system='sched')
-        self.assertTrue(len(events) > 1)
+        events = ft.available_system_events(system='sched', sort=True)
+        self.assertTrue(len(events) > 2)
         self.assertTrue('sched_switch' in events)
+        for i in range(len(events) - 2):
+            self.assertTrue(events[i] < events[i + 1])
 
         inst = ft.create_instance(instance_name)
         events = ft.available_system_events(instance=inst,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-31 12:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-31 12:53 [PATCH 1/4] trace-cruncher: Add optional sort to tfs_list2py_list() Yordan Karadzhov (VMware)
2021-08-31 12:53 ` [PATCH 2/4] trace-cruncher: Add optional sort to available_system_events() Yordan Karadzhov (VMware)
2021-08-31 12:53 ` [PATCH 3/4] trace-cruncher: Add optional sort to available_event_systems() Yordan Karadzhov (VMware)
2021-08-31 12:53 ` [PATCH 4/4] trace-cruncher: Add tests for sorted events/systems Yordan Karadzhov (VMware)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.