trace-cmd: Stop recording when processes traced with -P exit
PATCH RESEND 1/1 trace-cmd: Stop recording when processes traced with -P exit
From: Bijan Tabatabai <[email protected]>
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 <[email protected]>
---
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(-)
tracecmd/trace-record.c +17 -4
@@ -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 ();
Signature · 1 line
2.17.1