linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 1/4] trace-cruncher: Add optional sort to tfs_list2py_list()
Date: Tue, 31 Aug 2021 15:53:54 +0300	[thread overview]
Message-ID: <20210831125357.56862-1-y.karadz@gmail.com> (raw)

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


             reply	other threads:[~2021-08-31 12:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 12:53 Yordan Karadzhov (VMware) [this message]
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)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210831125357.56862-1-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).