Linux-Trace-Devel Archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Junyao Zhao <junzhao@redhat.com>, Nini Gu <ngu@redhat.com>,
	linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH] trace-cmd: support -m parameter for virt instances
Date: Mon, 13 May 2024 14:46:31 -0300	[thread overview]
Message-ID: <ZkJR9wJLAuEDpmR7@tpad> (raw)
In-Reply-To: <Zemv4OUx1WexdrlB@tpad>


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@redhat.com>
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> 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)
> 


  parent reply	other threads:[~2024-05-13 17:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 12:15 [PATCH] trace-cmd: support -m parameter for virt instances Marcelo Tosatti
2024-03-12  4:12 ` Junyao Zhao
2024-05-13 17:46 ` Marcelo Tosatti [this message]
2024-05-13 17:50   ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZkJR9wJLAuEDpmR7@tpad \
    --to=mtosatti@redhat.com \
    --cc=junzhao@redhat.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=ngu@redhat.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).