linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trace-cmd: Fix last_timestamp logic to handle multiple files
@ 2021-02-10 21:45 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2021-02-10 21:45 UTC (permalink / raw)
  To: Linux Trace Devel

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The last_timestamp logic to check the integrity of the timestamps in the
ring buffer was done globally, but would break if multiple files were being
included where the data files had different number of CPUs. That's because
the last_timestamp array was recreated for each passed in data file and the
size of the number of CPUs for each file.

Not only was the last_timestamp broken if there were different number of
CPUs, but it was also leaking memory.

Fixes: 8cf601567 ("trace-cmd: Add --ts-check option to report")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-read.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index 9270fa2e..ce07b6bd 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -52,6 +52,7 @@ struct handle_list {
 	struct tep_record	*record;
 	struct filter		*event_filters;
 	struct filter		*event_filter_out;
+	unsigned long long	*last_timestamp;
 };
 static struct list_head handle_list;
 
@@ -1193,17 +1194,16 @@ enum output_type {
 static void read_data_info(struct list_head *handle_list, enum output_type otype,
 			   int global)
 {
-	unsigned long long *last_timestamp;
 	struct handle_list *handles;
 	struct handle_list *last_handle;
 	struct tep_record *record;
 	struct tep_record *last_record;
 	struct tep_handle *pevent;
 	struct tep_event *event;
-	int cpus;
 	int ret;
 
 	list_for_each_entry(handles, handle_list, list) {
+		int cpus;
 
 		/* Don't process instances that we added here */
 		if (tracecmd_is_buffer_instance(handles->handle))
@@ -1218,8 +1218,8 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 		print_handle_file(handles);
 		printf("cpus=%d\n", cpus);
 
-		last_timestamp = calloc(cpus, sizeof(*last_timestamp));
-		if (!last_timestamp)
+		handles->last_timestamp = calloc(cpus, sizeof(*handles->last_timestamp));
+		if (!handles->last_timestamp)
 			die("allocating timestamps");
 
 		/* Latency trace is just all ASCII */
@@ -1302,31 +1302,30 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype
 		}
 		if (last_record) {
 			int cpu = last_record->cpu;
-			if (cpu >= cpus)
-				die("cpu %d creater than %d\n", cpu, cpus);
+			if (cpu >= last_handle->cpus)
+				die("cpu %d creater than %d\n", cpu, last_handle->cpus);
 			if (tscheck &&
-			    last_timestamp[cpu] > last_record->ts) {
+			    last_handle->last_timestamp[cpu] > last_record->ts) {
 				errno = 0;
 				warning("WARNING: Record on cpu %d went backwards: %lld to %lld delta: -%lld\n",
-					cpu, last_timestamp[cpu],
+					cpu, last_handle->last_timestamp[cpu],
 					last_record->ts,
-					last_timestamp[cpu] - last_record->ts);
+					last_handle->last_timestamp[cpu] - last_record->ts);
 			}
-			last_timestamp[cpu] = last_record->ts;
+			last_handle->last_timestamp[cpu] = last_record->ts;
 			print_handle_file(last_handle);
 			trace_show_data(last_handle->handle, last_record);
 			free_handle_record(last_handle);
 		}
 	} while (last_record);
 
-	free(last_timestamp);
-
 	if (profile)
 		do_trace_profile();
 
 	list_for_each_entry(handles, handle_list, list) {
 		free_filters(handles->event_filters);
 		free_filters(handles->event_filter_out);
+		free(handles->last_timestamp);
 
 		show_test(handles->handle);
 	}
-- 
2.25.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-10 21:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 21:45 [PATCH] trace-cmd: Fix last_timestamp logic to handle multiple files Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).