Skip to contentSkip to conversation

trace-cruncher: Optimize get_arg_list()

PATCH New Yordan Karadzhov (VMware) 1 participant 2 messages Oct 13, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 trace-cruncher: Optimize get_arg_list()

The extraction of a 'C' string from a Python list of strings gets defined as a static method instead of being coded in the body of 'get_arg_list()'. The new static method will be used in following patches. The error message emitted in the case of an error is remover since it will never get printed (it is overwritten by the error messages of the functions calling 'get_arg_list()').

---
 src/ftracepy-utils.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
src/ftracepy-utils.c +12 -7
index d8115f6..5c8bcca 100644
@@ -274,10 +274,19 @@ PyObject *PyTepEvent_get_pid(PyTepEvent* self, PyObject *args,
 	return PyLong_FromLong(pid);
 }
 
+static const char *str_from_list(PyObject *py_list, int i)
+{
+	PyObject *item = PyList_GetItem(py_list, i);
+
+	if (!PyUnicode_Check(item))
+		return NULL;
+
+	return PyUnicode_DATA(item);
+}
+
 static const char **get_arg_list(PyObject *py_list)
 {
 	const char **argv = NULL;
-	PyObject *arg_py;
 	int i, n;
 
 	if (!PyList_CheckExact(py_list))
@@ -286,18 +295,14 @@ static const char **get_arg_list(PyObject *py_list)
 	n = PyList_Size(py_list);
 	argv = calloc(n + 1, sizeof(*argv));
 	for (i = 0; i < n; ++i) {
-		arg_py = PyList_GetItem(py_list, i);
-		if (!PyUnicode_Check(arg_py))
+		argv[i] = str_from_list(py_list, i);
+		if (!argv[i])
 			goto fail;
-
-		argv[i] = PyUnicode_DATA(arg_py);
 	}
 
 	return argv;
 
  fail:
-	PyErr_SetString(TRACECRUNCHER_ERROR,
-			"Failed to parse argument list.");
 	free(argv);
 	return NULL;
 }
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 trace-cruncher: Modify the APIs for enable/disable multiple events

The current version of these APIs takes the list of systems and the 'list of list' of events to enable/disable in two independent arguments. This can potentially create confusion since the user is expected to provide two correlated lists via disjoined arguments. Here we switch to using a single 'events' argument for these APIs that takes a dictionary where the 'systems' are 'keys' and the lists of events from each system are the 'value'.

---
 examples/start_tracing.py                     |  4 +-
 src/ftracepy-utils.c                          | 87 ++++++-------------
 .../tests/1_unit/test_01_ftracepy_unit.py     | 41 +++------
 3 files changed, 40 insertions(+), 92 deletions(-)
examples/start_tracing.py +2 -2
index c9960e3..aaeb0cf 100755
@@ -13,8 +13,8 @@ inst = ft.create_instance()
 
 # Enable all static events from systems "sched" and "irq".
 ft.enable_events(instance=inst,
-                 systems=['sched', 'irq'],
-                 events=[['sched_switch'],['all']])
+                 events={'sched': ['sched_switch', 'sched_waking'],
+                         'irq':   ['all']})
 
 # Print the stream of trace events. "Ctrl+c" to stop tracing.
 ft.read_trace(instance=inst)
src/ftracepy-utils.c +28 -59

118 lines not on this page · raw message

tracecruncher/tests/1_unit/test_01_ftracepy_unit.py +10 -31

76 lines not on this page · raw message

Signature · 1 line
2.30.2