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

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

 



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@xxxxxxxxx>
---
 src/ftracepy-utils.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

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);
 }
 
-- 
2.32.0




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

  Powered by Linux