Re: [PATCH] trace-cmd: support -m parameter for virt instances

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

 



Ping?

On Thu, Mar 07, 2024 at 09:15:28AM -0300, Marcelo Tosatti wrote:
> 
> Take into consideration the value passed in with "-m",
> the max size in kilobytes that a per cpu buffer should be,
> when reading trace data from guests.
> 
> This allows one to prevent running out of diskspace on long runs.
> 
> Reported-by: Junyao Zhao <junzhao@xxxxxxxxxx>
> Signed-off-by: Marcelo Tosatti <mtosatti@xxxxxxxxxx>
> 
> diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
> index f2cf8dc8..2d14ed7a 100644
> --- a/lib/trace-cmd/include/private/trace-cmd-private.h
> +++ b/lib/trace-cmd/include/private/trace-cmd-private.h
> @@ -370,7 +370,7 @@ enum {
>  void tracecmd_free_recorder(struct tracecmd_recorder *recorder);
>  struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu, unsigned flags);
>  struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu, unsigned flags);
> -struct tracecmd_recorder *tracecmd_create_recorder_virt(const char *file, int cpu, unsigned flags, int trace_fd);
> +struct tracecmd_recorder *tracecmd_create_recorder_virt(const char *file, int cpu, unsigned flags, int trace_fd, int maxkb);
>  struct tracecmd_recorder *tracecmd_create_recorder_maxkb(const char *file, int cpu, unsigned flags, int maxkb);
>  struct tracecmd_recorder *tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, struct tracefs_instance *instance);
>  struct tracecmd_recorder *tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, struct tracefs_instance *instance);
> diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c
> index 0633edf5..44f245d5 100644
> --- a/lib/trace-cmd/trace-recorder.c
> +++ b/lib/trace-cmd/trace-recorder.c
> @@ -175,19 +175,46 @@ tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, struct trace
>  
>  static struct tracecmd_recorder *
>  __tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags,
> -				  struct tracefs_instance *instance, int tfd)
> +				  struct tracefs_instance *instance, int tfd, int maxkb)
>  {
>  	struct tracecmd_recorder *recorder;
> -	int fd;
> +	int fd, fd2 = -1;
> +	char *file2;
>  
> -	fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
> +	fd = open(file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
>  	if (fd < 0)
>  		return NULL;
>  
> -	recorder = create_buffer_recorder_fd2(fd, -1, cpu, flags, instance, 0, tfd);
> +	if (maxkb) {
> +		int len = strlen(file);
> +
> +		file2 = malloc(len + 3);
> +		if (!file2)
> +			return NULL;
> +
> +		sprintf(file2, "%s.1", file);
> +
> +		fd2 = open(file2, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
> +		if (fd2 < 0) {
> +			close(fd);
> +			unlink(file);
> +			free(file2);
> +			return NULL;
> +		}
> +	}
> +
> +	recorder = create_buffer_recorder_fd2(fd, fd2, cpu, flags, instance, maxkb, tfd);
>  	if (!recorder) {
>  		close(fd);
>  		unlink(file);
> +		if (fd2 != -1)
> +			close(fd2);
> +	}
> +
> +	if (fd2 != -1) {
> +		/* Unlink file2, we need to add everything to file at the end */
> +		unlink(file2);
> +		free(file2);
>  	}
>  
>  	return recorder;
> @@ -242,7 +269,7 @@ struct tracecmd_recorder *
>  tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags,
>  				struct tracefs_instance *instance)
>  {
> -	return __tracecmd_create_buffer_recorder(file, cpu, flags, instance, -1);
> +	return __tracecmd_create_buffer_recorder(file, cpu, flags, instance, -1, 0);
>  }
>  
>  /**
> @@ -255,9 +282,9 @@ tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags,
>   */
>  struct tracecmd_recorder *
>  tracecmd_create_recorder_virt(const char *file, int cpu, unsigned flags,
> -			      int trace_fd)
> +			      int trace_fd, int maxkb)
>  {
> -	return __tracecmd_create_buffer_recorder(file, cpu, flags, NULL, trace_fd);
> +	return __tracecmd_create_buffer_recorder(file, cpu, flags, NULL, trace_fd, maxkb);
>  }
>  
>  struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu, unsigned flags)
> diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
> index 91cc90d4..69ea0cbd 100644
> --- a/tracecmd/trace-record.c
> +++ b/tracecmd/trace-record.c
> @@ -3584,7 +3584,7 @@ create_recorder_instance(struct buffer_instance *instance, const char *file, int
>  			flags |= TRACECMD_RECORD_NOBRASS;
>  		else if (!trace_vsock_can_splice_read())
>  			flags |= TRACECMD_RECORD_NOSPLICE;
> -		return tracecmd_create_recorder_virt(file, cpu, flags, fd);
> +		return tracecmd_create_recorder_virt(file, cpu, flags, fd, max_kb);
>  	}
>  
>  	if (brass)
> 





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

  Powered by Linux