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 2/2] trace-cruncher: Make the tracing of a process stoppable
Date: Mon, 15 Nov 2021 10:55:18 +0200	[thread overview]
Message-ID: <20211115085518.204852-2-y.karadz@gmail.com> (raw)
In-Reply-To: <20211115085518.204852-1-y.karadz@gmail.com>

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


      reply	other threads:[~2021-11-15  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15  8:55 [PATCH 1/2] trace-cruncher: More options for stopping data iteration Yordan Karadzhov (VMware)
2021-11-15  8:55 ` Yordan Karadzhov (VMware) [this message]

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=20211115085518.204852-2-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).