diff mbox series

[v2,31/87] trace-cmd library: Fit CPU latency trace data in the new trace file version 7 format

Message ID 20210729050959.12263-32-tz.stoyanov@gmail.com (mailing list archive)
State Superseded
Headers show
Series Trace file version 7 | expand

Commit Message

Tzvetomir Stoyanov (VMware) July 29, 2021, 5:09 a.m. UTC
Trace file version 7 format is based on sections. To fit the latency
trace data in this structure, a new section and option for it is
defined:
  BUFFER_LAT
It is similar to the BUFFER section which holds the flyrecord data, but
has a latency specific design. The BUFFER_LAT section has:
 - section header, as all other sections
 - compression of the trace data, optional
 - corresponding trace option, pointing to the section

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 .../include/private/trace-cmd-private.h       |  3 +-
 lib/trace-cmd/trace-output.c                  | 36 ++++++++++++++++---
 tracecmd/trace-record.c                       |  2 +-
 3 files changed, 35 insertions(+), 6 deletions(-)

Comments

Steven Rostedt Aug. 17, 2021, 3:44 p.m. UTC | #1
On Thu, 29 Jul 2021 08:09:03 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> Trace file version 7 format is based on sections. To fit the latency
> trace data in this structure, a new section and option for it is
> defined:
>   BUFFER_LAT
> It is similar to the BUFFER section which holds the flyrecord data, but
> has a latency specific design. The BUFFER_LAT section has:

Actually, let's call it BUFFER_TEXT.

Although we do it for "latency" format, which I'm thinking we should
call it something different for v7, the real difference is that it's
text and not binary. Perhaps we can save other formats as "text".

In fact, I think v7 should allow for a mixture of TEXT and BINARY
buffers.

-- Steve

>  - section header, as all other sections
>  - compression of the trace data, optional
>  - corresponding trace option, pointing to the section
> 
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Steven Rostedt Aug. 19, 2021, 7:10 p.m. UTC | #2
On Thu, 29 Jul 2021 08:09:03 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> +++ b/lib/trace-cmd/include/private/trace-cmd-private.h
> @@ -135,6 +135,7 @@ enum {
>  	TRACECMD_OPTION_TIME_SHIFT,
>  	TRACECMD_OPTION_GUEST,
>  	TRACECMD_OPTION_TSC2NSEC,
> +	TRACECMD_OPTION_BUFFER_LAT,

I just realized that this will break the parsing.

You can't add an enum in the middle. That will cause all the other
enums to shift in value,  and these are already a file API.

>  	TRACECMD_OPTION_HEADER_INFO,

For example, if you saved a file before this patch, the
TRACECMD_OPTION_HEADER_INFO will be one number, and stored in the
trace.dat file.

Then if you try to read that same trace.dat file after this patch, it
will interpret the TRACECMD_OPTION_HEADER_INFO as
TRACECMD_OPTION_BUFFER_LAT, which will obviously be incorrect.

-- Steve



>  	TRACECMD_OPTION_FTRACE_EVENTS,
>  	TRACECMD_OPTION_EVENT_FORMATS,
Tzvetomir Stoyanov (VMware) Sept. 2, 2021, 12:48 p.m. UTC | #3
On Tue, Aug 17, 2021 at 6:44 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Thu, 29 Jul 2021 08:09:03 +0300
> "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:
>
> > Trace file version 7 format is based on sections. To fit the latency
> > trace data in this structure, a new section and option for it is
> > defined:
> >   BUFFER_LAT
> > It is similar to the BUFFER section which holds the flyrecord data, but
> > has a latency specific design. The BUFFER_LAT section has:
>
> Actually, let's call it BUFFER_TEXT.
>
> Although we do it for "latency" format, which I'm thinking we should
> call it something different for v7, the real difference is that it's
> text and not binary. Perhaps we can save other formats as "text".
>
> In fact, I think v7 should allow for a mixture of TEXT and BINARY
> buffers.

It does, there is no limitation to do a flyrecord in one buffer and
latency tracing in another. Although I cannot imagine a use case for
that.

>
> -- Steve
>
> >  - section header, as all other sections
> >  - compression of the trace data, optional
> >  - corresponding trace option, pointing to the section
> >
> > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
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 4e718c40..f2868576 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -135,6 +135,7 @@  enum {
 	TRACECMD_OPTION_TIME_SHIFT,
 	TRACECMD_OPTION_GUEST,
 	TRACECMD_OPTION_TSC2NSEC,
+	TRACECMD_OPTION_BUFFER_LAT,
 	TRACECMD_OPTION_HEADER_INFO,
 	TRACECMD_OPTION_FTRACE_EVENTS,
 	TRACECMD_OPTION_EVENT_FORMATS,
@@ -294,7 +295,7 @@  int tracecmd_output_write_headers(struct tracecmd_output *handler,
 				  struct tracecmd_event_list *list);
 
 struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus,
-						     int file_version);
+						     int file_version, const char *compression);
 struct tracecmd_output *tracecmd_create_init_fd(int fd);
 
 struct tracecmd_output *tracecmd_create_init_file(const char *output_file);
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 30a6acf4..83c3b9e7 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -2034,9 +2034,11 @@  out_add_buffer_option_v7(struct tracecmd_output *handle, const char *name,
 }
 
 struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus,
-						     int file_version)
+						     int file_version, const char *compression)
 {
+	enum tracecmd_section_flags flags = 0;
 	struct tracecmd_output *handle;
+	tsize_t offset;
 	char *path;
 	int fd;
 
@@ -2049,6 +2051,12 @@  struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in
 		goto out_free;
 	if (file_version && tracecmd_output_set_version(handle, file_version))
 		goto out_free;
+	if (compression) {
+		if (tracecmd_output_set_compression(handle, compression))
+			goto out_free;
+	} else if (file_version >= 7) {
+		tracecmd_output_set_compression(handle, "any");
+	}
 	if (tracecmd_output_write_init(handle))
 		goto out_free;
 	if (tracecmd_output_write_headers(handle, NULL))
@@ -2061,7 +2069,8 @@  struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in
 
 	if (tracecmd_write_cpus(handle, cpus) < 0)
 		goto out_free;
-
+	if (tracecmd_write_buffer_info(handle) < 0)
+		goto out_free;
 	if (tracecmd_write_options(handle) < 0)
 		goto out_free;
 
@@ -2071,23 +2080,42 @@  struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in
 		goto out_free;
 	}
 
-	if (do_write_check(handle, "latency  ", 10))
+	if (handle->file_version < 7 && do_write_check(handle, "latency  ", 10))
 		goto out_free;
 
 	path = get_tracing_file(handle, "trace");
 	if (!path)
 		goto out_free;
 
+	offset = do_lseek(handle, 0, SEEK_CUR);
+	if (handle->file_version >= 7 &&
+	    !out_add_buffer_option_v7(handle, "", TRACECMD_OPTION_BUFFER_LAT, offset, 0, NULL))
+		goto out_free;
+	if (handle->compress)
+		flags |= TRACECMD_SEC_FL_COMPRESS;
+
+	offset = out_write_section_header(handle, TRACECMD_OPTION_BUFFER_LAT,
+					  "buffer latency", flags, false);
+
 	copy_file_compress(handle, path, NULL);
+	if (out_update_section_header(handle, offset))
+		goto out_free;
 
 	put_tracing_file(path);
 
 	handle->file_state = TRACECMD_FILE_CPU_LATENCY;
 
+	if (tracecmd_get_out_file_version(handle) >= 7)
+		tracecmd_write_options(handle);
+
 	return handle;
 
 out_free:
-	tracecmd_output_close(handle);
+	if (handle)
+		tracecmd_output_close(handle);
+	else
+		close(fd);
+	unlink(output_file);
 	return NULL;
 }
 
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index f8c1c090..2e8db8a4 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4531,7 +4531,7 @@  static void record_data(struct common_record_context *ctx)
 
 	if (latency) {
 		handle = tracecmd_create_file_latency(ctx->output, local_cpu_count,
-						      ctx->file_version);
+						      ctx->file_version, ctx->compression);
 		tracecmd_set_quiet(handle, quiet);
 	} else {
 		if (!local_cpu_count)