trace-cmd: support -m parameter for virt instances
PATCH 1/1 trace-cmd: support -m parameter for virt instances
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.
lib/trace-cmd/include/private/trace-cmd-private.h +1 -1
@@ -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);
lib/trace-cmd/trace-recorder.c +34 -7
69 lines not on this page · raw message
tracecmd/trace-record.c +1 -1
@@ -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)
Test by: Junyao Zhao <[email protected]>
Successfully collected 12h test data from the guest.
Quoted 114 lines · Marcelo Tosatti
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 <[email protected]>Signed-off-by Marcelo Tosatti <[email protected]>lib/trace-cmd/include/private/trace-cmd-private.h +1
-1@@ -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);lib/trace-cmd/trace-recorder.c +34
-7@@ -175,19 +175,46 @@ tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, struct tracestatic 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)tracecmd/trace-record.c +1
-1@@ -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)
Ping?
Quoted 113 lines · Marcelo Tosatti
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 <[email protected]>Signed-off-by Marcelo Tosatti <[email protected]>lib/trace-cmd/include/private/trace-cmd-private.h +1
-1@@ -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);lib/trace-cmd/trace-recorder.c +34
-7@@ -175,19 +175,46 @@ tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, struct tracestatic 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)tracecmd/trace-record.c +1
-1@@ -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)
Quoted 1 line · On Mon, 13 May 2024 14:46:31 -0300 Marcelo Tosatti <[email protected]> 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