* [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 related [flat|nested] only message in thread
only message in thread, other threads:[~2020-04-18 23:31 UTC | newest]
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
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).