diff mbox series

trace-cmd: support -m parameter for virt instances

Message ID Zemv4OUx1WexdrlB@tpad (mailing list archive)
State Accepted
Commit 41f90a280c2992d82f9062d1f2dc98c9c74f7313
Headers show
Series trace-cmd: support -m parameter for virt instances | expand

Commit Message

Marcelo Tosatti March 7, 2024, 12:15 p.m. UTC
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>

Comments

Junyao Zhao March 12, 2024, 4:12 a.m. UTC | #1
Test by: Junyao Zhao <junzhao@redhat.com>

Successfully collected 12h test data from the guest.




On Thu, Mar 7, 2024 at 8:19 PM Marcelo Tosatti <mtosatti@redhat.com> 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)
>
Marcelo Tosatti May 13, 2024, 5:46 p.m. UTC | #2
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)
>
Steven Rostedt May 13, 2024, 5:50 p.m. UTC | #3
On Mon, 13 May 2024 14:46:31 -0300
Marcelo Tosatti <mtosatti@redhat.com> wrote:

> Ping?

Apologies, I got totally swamped. But the priority of updating user
space tooling is getting higher, so hopefully not too long.

Thanks for you patience.

-- Steve
diff mbox series

Patch

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)