Skip to contentSkip to conversation

trace-cmd record: Append trace options after the trace data are written

PATCH Superseded Tzvetomir Stoyanov (VMware) 2 participants 2 messages Nov 11, 2021 – Nov 24, 2021

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 9/25 trace-cmd record: Append trace options after the trace data are written

In trace file version 7, the CPU trace metadata is saved in a trace option. As this metadata has file offsets, which depend on the CPU trace data, the option must be written in the file after the CPU trace data.

---
 tracecmd/trace-record.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tracecmd/trace-record.c +5 -1
index 757dab0f..32270e20 100644
@@ -4449,6 +4449,9 @@ static void write_guest_file(struct buffer_instance *instance)
 
 	if (tracecmd_write_cpu_data(handle, cpu_count, temp_files, NULL) < 0)
 		die("failed to write CPU data");
+	if (tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS)
+		tracecmd_write_options(handle);
+
 	tracecmd_output_close(handle);
 
 	for (i = 0; i < cpu_count; i++)
@@ -4597,7 +4600,8 @@ static void record_data(struct common_record_context *ctx)
 				append_buffer(handle, instance, temp_files);
 			}
 		}
-
+		if (tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS)
+			tracecmd_write_options(handle);
 		free(temp_files);
 	}
 	if (!handle)
Signature · 1 line
2.33.1
#1 lore raw
Quoted 14 lines · On Thu, 11 Nov 2021 17:09:33 +0200 "Tzvetomir Stoyanov (VMware)"…

In trace file version 7, the CPU trace metadata is saved in a trace option. As this metadata has file offsets, which depend on the CPU trace data, the option must be written in the file after the CPU trace data.

---
 tracecmd/trace-record.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tracecmd/trace-record.c +0 -0
index 757dab0f..32270e20 100644

tracecmd/trace-record.c static void write_guest_file(struct buffer_instance *instance) · line 4452

Quoted 4 lines
tracecmd/trace-record.c +1 -0
@@ -4449,6 +4449,9 @@ static void write_guest_file(struct buffer_instance *instance)
 
 	if (tracecmd_write_cpu_data(handle, cpu_count, temp_files, NULL) < 0)
 		die("failed to write CPU data");
+	if (tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS)

Can't this be detected on close?

That is, if the handle has pending options to write out, and the handle has sections, can't the tracecmd_output_close() write it out then?

Why make this something the user must worry about?

-- Steve

Quoted 15 lines
tracecmd/trace-record.c +4 -1
+		tracecmd_write_options(handle);
+
 	tracecmd_output_close(handle);
 
 	for (i = 0; i < cpu_count; i++)
@@ -4597,7 +4600,8 @@ static void record_data(struct common_record_context *ctx)
 				append_buffer(handle, instance, temp_files);
 			}
 		}
-
+		if (tracecmd_get_out_file_version(handle) >= FILE_VERSION_SECTIONS)
+			tracecmd_write_options(handle);
 		free(temp_files);
 	}
 	if (!handle)