Skip to contentSkip to conversation

trace-cmd: Fixes for instance recording and reporting

PATCH New Steven Rostedt 1 participant 3 messages Mar 5, 2021

lore
Share & tools
lore
#0 lore raw

cover trace-cmd: Fixes for instance recording and reporting

It appears that the valification code broke instances.

Steven Rostedt (VMware) (2):
trace-cmd record: Allow tracecmd_write_cpu_data() be called multiple times trace-cmd report: Add last_timestamp array for instances

----

 lib/trace-cmd/trace-output.c |  4 +++-
 tracecmd/trace-read.c        | 12 ++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)
#1 lore raw

PATCH 1/2 trace-cmd record: Allow tracecmd_write_cpu_data() be called multiple times

From: "Steven Rostedt (VMware)" <[email protected]>

When trace-cmd record -B foo is executed, buffers for instances are recorded in the trace.dat file by calling tracecmd_write_cpu_data() multiple times (for toplevel and once for each instance). But currently the verification code fails on the second call as it expects the state to be the previous state. Allow this call to happen when the state is already set to TRACECMD_FILE_CPU_FLYRECORD.

Fixes 3717bb92a ("trace-cmd: Add validation for reading and writing trace.dat files")
---
 lib/trace-cmd/trace-output.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/trace-cmd/trace-output.c +3 -1
index c8f8a106c295..a2d4a16e3c3d 100644
@@ -1339,7 +1339,9 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle,
 	int ret;
 	int i;
 
-	ret = check_out_state(handle, TRACECMD_FILE_CPU_FLYRECORD);
+	/* This can be called multiple times (when recording instances) */
+	ret = handle->file_state == TRACECMD_FILE_CPU_FLYRECORD ? 0 :
+		check_out_state(handle, TRACECMD_FILE_CPU_FLYRECORD);
 	if (ret < 0) {
 		warning("Cannot write trace data into the file, unexpected state 0x%X",
 			handle->file_state);
Signature · 1 line
2.30.0
#2 lore raw

PATCH 2/2 trace-cmd report: Add last_timestamp array for instances

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

The logic to add a last_timestamp array to the reading of trace data for multiple files failed to include the array for instances within a given file. This caused the instance handles not to have a way to save the last timestamp, and caused the output to quit due to reading a record on a CPU past the last CPU in the last_timestamp array.

Fixes db36a61d2 ("trace-cmd: Fix last_timestamp logic to handle multiple files")
---
 tracecmd/trace-read.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tracecmd/trace-read.c +6 -6
index ce07b6bdb143..56fc0626d486 100644
@@ -1205,6 +1205,12 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 	list_for_each_entry(handles, handle_list, list) {
 		int cpus;
 
+		cpus = tracecmd_cpus(handles->handle);
+		handles->cpus = cpus;
+		handles->last_timestamp = calloc(cpus, sizeof(*handles->last_timestamp));
+		if (!handles->last_timestamp)
+			die("allocating timestamps");
+
 		/* Don't process instances that we added here */
 		if (tracecmd_is_buffer_instance(handles->handle))
 			continue;
@@ -1213,15 +1219,9 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 		if (ret < 0)
 			die("failed to init data");
 
-		cpus = tracecmd_cpus(handles->handle);
-		handles->cpus = cpus;
 		print_handle_file(handles);
 		printf("cpus=%d\n", cpus);
 
-		handles->last_timestamp = calloc(cpus, sizeof(*handles->last_timestamp));
-		if (!handles->last_timestamp)
-			die("allocating timestamps");
-
 		/* Latency trace is just all ASCII */
 		if (ret > 0) {
 			if (multi_inputs)
Signature · 1 line
2.30.0