diff mbox series

[2/2] trace-cruncher: Make the tracing of a process stoppable

Message ID 20211115085518.204852-2-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series [1/2] trace-cruncher: More options for stopping data iteration | expand

Commit Message

Yordan Karadzhov Nov. 15, 2021, 8:55 a.m. UTC
Both 'trace_process()' and 'trace_shell_process()' can be stopped
from the callback function by calling 'sys.exit()' or by returning
non zero integer value.

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

Patch

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 8e803ee..b5cdcee 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -2097,10 +2097,17 @@  static void iterate_raw_events_waitpid(struct tracefs_instance *instance,
 				       PyObject *py_func,
 				       pid_t pid)
 {
+	bool *callback_status = &callback_ctx.status;
+	int ret;
+
 	callback_ctx.py_callback = py_func;
+	(*(volatile bool *)callback_status) = true;
 	do {
-		tracefs_iterate_raw_events(tep, instance, NULL, 0,
-					   callback, &callback_ctx);
+		ret = tracefs_iterate_raw_events(tep, instance, NULL, 0,
+						 callback, &callback_ctx);
+
+		if (*(volatile bool *)callback_status == false || ret < 0)
+			break;
 	} while (waitpid(pid, NULL, WNOHANG) != pid);
 }