Re: [PATCH] trace-cmd: Stop recording when processes traced with -P exit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 18 Apr 2020 11:36:05 -0500
Bijan Tabatabai <bijan311@xxxxxxxxx> wrote:

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

I don't mind the idea, but I'm worried about this approach.

> 
> Signed-off-by: Bijan Tabatabai <bijan311@xxxxxxxxx>
> ---
>  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));

Won't that while loop just go into a spin?

What about something like a fsnotify on a /proc/<pid>/ file?

I rather have trace-cmd sleep and wake up when a task exits, than to do a
spin. Like it does for the -F option.

Thanks!

-- Steve


> +				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();




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux