linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 4/4] libtracefs: Propagate the return value of the callback function
Date: Tue,  8 Jun 2021 16:55:03 +0300	[thread overview]
Message-ID: <20210608135503.12135-4-y.karadz@gmail.com> (raw)
In-Reply-To: <20210608135503.12135-1-y.karadz@gmail.com>

Currently the return value of the callback function can be used to
stop pulling data from the trace buffer, however this return value
is lost and the user has no idea if tracefs_iterate_raw_events()
terminated because there was no more data or because this was
requested from the callback function. If we propagate the return
value of the callback, this can be used in cases like the one below:

int callback(struct tep_event *event, struct tep_record *record,
	     int cpu, void *py_func)
{
	....

	return (something) ? 0 : 1
}

int main()
{
	int ret;

	....

	while(ret == 0)
		ret = tracefs_iterate_raw_events(tep, instance,
		                                 NULL, 0,
		                                 callback, NULL);

	....

Here the user can effectively terminate the pulling the data
from inside the callback.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/tracefs-events.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 0fef64f..0a87d28 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -131,7 +131,8 @@ static int read_cpu_pages(struct tep_handle *tep, struct cpu_iterate *cpus, int
 		}
 		if (j < count) {
 			if (callback(cpus[j].event, &cpus[j].record, cpus[j].cpu, callback_context))
-				break;
+				return -1;
+
 			cpus[j].event = NULL;
 			read_next_record(tep, cpus + j);
 		} else {
-- 
2.27.0


  parent reply	other threads:[~2021-06-08 13:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 13:55 [PATCH 1/4] libtracefs: Fix enable_disable_all() return value Yordan Karadzhov (VMware)
2021-06-08 13:55 ` [PATCH 2/4] libtracefs: Fix event_enable_disable() " Yordan Karadzhov (VMware)
2021-06-08 13:55 ` [PATCH 3/4] libtracefs: Fix typo in function name Yordan Karadzhov (VMware)
2021-06-08 13:55 ` Yordan Karadzhov (VMware) [this message]
2021-06-09 17:00   ` [PATCH 4/4] libtracefs: Propagate the return value of the callback function Steven Rostedt
2021-06-11 11:03     ` 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=20210608135503.12135-4-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --subject='Re: [PATCH 4/4] libtracefs: Propagate the return value of the callback function' \
    /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

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