linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH 10/10] trace-cmd record: Keep stopping the recording when finished
Date: Fri,  6 Jan 2023 13:39:30 -0500	[thread overview]
Message-ID: <20230106183930.12565-11-rostedt@goodmis.org> (raw)
In-Reply-To: <20230106183930.12565-1-rostedt@goodmis.org>

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The tracecmd_stop_recording() is suppose to force the recorders to finish,
but because it is called from a signal handler, that may not necessarily be
the case (due to race conditions and such). Set an alarm to try again in a
second, then after two seconds, and then three, and so on.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-record.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index b3614b0706de..7f0cebe8cd7a 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3164,11 +3164,21 @@ static void expand_event_list(void)
 
 static void finish(void)
 {
+	static int secs = 1;
+
 	sleep_time = 0;
 
 	/* all done */
-	if (recorder)
+	if (recorder) {
 		tracecmd_stop_recording(recorder);
+		/*
+		 * We could just call the alarm if the above returned non zero,
+		 * as zero is suppose to guarantee that the reader woke up.
+		 * But as this is called from a signal handler, that may not
+		 * necessarily be the case.
+		 */
+		alarm(secs++);
+	}
 	finished = 1;
 }
 
@@ -3181,6 +3191,7 @@ static void flush(void)
 static void do_sig(int sig)
 {
 	switch (sig) {
+	case SIGALRM:
 	case SIGUSR1:
 	case SIGINT:
 		return finish();
@@ -3432,6 +3443,7 @@ static int create_recorder(struct buffer_instance *instance, int cpu,
 		signal(SIGINT, SIG_IGN);
 		signal(SIGUSR1, do_sig);
 		signal(SIGUSR2, do_sig);
+		signal(SIGALRM, do_sig);
 
 		if (rt_prio)
 			set_prio(rt_prio);
-- 
2.35.1


      parent reply	other threads:[~2023-01-06 18:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 18:39 [PATCH 00/10] trace-cmd: Fix trace-cmd stream Steven Rostedt
2023-01-06 18:39 ` [PATCH 01/10] trace-cmd library: Set recorder to nonblock when finished Steven Rostedt
2023-01-06 18:39 ` [PATCH 02/10] trace-cmd stream: Do not block when stopping threads Steven Rostedt
2023-01-06 18:39 ` [PATCH 03/10] trace-cmd stream: Add a flush signal to kick the output Steven Rostedt
2023-01-06 18:39 ` [PATCH 04/10] trace-cmd stream: Do one last flush when finished Steven Rostedt
2023-01-06 18:39 ` [PATCH 05/10] trace-cmd library: Fix read_data() with error from tracefs_cpu_read() Steven Rostedt
2023-01-06 18:39 ` [PATCH 06/10] trace-cmd: Have trace_stream_read() use poll() Steven Rostedt
2023-01-06 18:39 ` [PATCH 07/10] trace-cmd stream: Set default sleep time to half a second Steven Rostedt
2023-01-06 18:39 ` [PATCH 08/10] trace-cmd library: Return the result of tracefs_cpu_stop() Steven Rostedt
2023-01-06 18:39 ` [PATCH 09/10] trace-cmd record: Set sleep_time to zero at end of recording Steven Rostedt
2023-01-06 18:39 ` Steven Rostedt [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=20230106183930.12565-11-rostedt@goodmis.org \
    --to=rostedt@goodmis.org \
    --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).