Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH RESEND] trace-cmd: Stop recording when processes traced with -P exit
@ 2020-04-18 23:30 Bijan Tabatabai
  0 siblings, 0 replies; only message in thread
From: Bijan Tabatabai @ 2020-04-18 23:30 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Bijan Tabatabai

From: Bijan Tabatabai <bijan311@yahoo.com>

When the -F flag is used in trace-cmd record, trace-cmd stops recording
when the executable it is tracing terminates.
This patch makes the -P flag act similarly.

Signed-off-by: Bijan Tabatabai <bijan311@yahoo.com>
---
 Resending this because the mailing server did not like my original
 email address.

 tracecmd/trace-record.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index d89b32d..b5cd4c4 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -121,8 +121,10 @@ struct filter_pids {
 };
 
 static struct filter_pids *filter_pids;
+static struct filter_pids *process_pids;
 static int nr_filter_pids;
 static int len_filter_pids;
+static int nr_process_pids = 0;
 
 static int have_set_event_pid;
 static int have_event_fork;
@@ -5799,7 +5801,9 @@ static void parse_record_options(int argc,
 			while (pid) {
 				add_filter_pid(atoi(pid), 0);
 				pid = strtok_r(NULL, ",", &sav);
+				nr_process_pids++;
 			}
+			process_pids = filter_pids;
 			free(pids);
 			break;
 		case 'c':
@@ -6273,10 +6277,19 @@ static void record_trace(int argc, char **argv,
 					ptrace_attach(pid->pid);
 			}
 		}
-		/* sleep till we are woken with Ctrl^C */
-		printf("Hit Ctrl^C to stop recording\n");
-		while (!finished)
-			trace_or_sleep(type);
+		if (nr_process_pids) {
+			for (pid = process_pids; pid && nr_process_pids; pid = pid->next) {
+				if (!pid->exclude)
+					/* Wait for the process to end */
+					while(!kill(pid->pid, 0));
+				nr_process_pids--;
+			}
+		} else {
+			/* sleep till we are woken with Ctrl^C */
+			printf("Hit Ctrl^C to stop recording\n");
+			while (!finished)
+				trace_or_sleep(type);
+		}
 	}
 
 	tell_guests_to_stop();
-- 
2.17.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18 23:30 [PATCH RESEND] trace-cmd: Stop recording when processes traced with -P exit Bijan Tabatabai

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git