trace-cmd: Use record->cpu instead of tracking cpu
tracecmd_read_data(), tracecmd_read_next_data() and tracecmd_peek_data()
all set the record->cpu to the cpu that the record is on. Do not track
the cpu if we can use record->cpu instead. This prevents the bug (that this
patch fixes) where the cpu gets out of sync with the record be processed.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/trace-read.c b/trace-read.c
index ce04756..db322e5 100644
--- a/trace-read.c
+++ b/trace-read.c
@@ -755,11 +755,11 @@
}
}
-static void show_data(struct tracecmd_input *handle,
- struct pevent_record *record, int cpu)
+static void show_data(struct tracecmd_input *handle, struct pevent_record *record)
{
struct pevent *pevent;
struct trace_seq s;
+ int cpu = record->cpu;
bool use_trace_clock;
if (filter_record(handle, record))
@@ -772,13 +772,11 @@
trace_seq_init(&s);
if (record->missed_events > 0)
trace_seq_printf(&s, "CPU:%d [%lld EVENTS DROPPED]\n",
- record->cpu, record->missed_events);
+ cpu, record->missed_events);
else if (record->missed_events < 0)
- trace_seq_printf(&s, "CPU:%d [EVENTS DROPPED]\n",
- record->cpu);
+ trace_seq_printf(&s, "CPU:%d [EVENTS DROPPED]\n", cpu);
if (buffer_breaks && tracecmd_record_at_buffer_start(handle, record))
- trace_seq_printf(&s, "CPU:%d [SUBBUFFER START]\n",
- record->cpu);
+ trace_seq_printf(&s, "CPU:%d [SUBBUFFER START]\n", cpu);
use_trace_clock = tracecmd_get_use_trace_clock(handle);
pevent_print_event(pevent, &s, record, use_trace_clock);
@@ -828,12 +826,10 @@
return ret;
}
-static struct pevent_record *
-get_next_record(struct handle_list *handles, int *next_cpu)
+static struct pevent_record *get_next_record(struct handle_list *handles)
{
struct pevent_record *record;
int found = 0;
- int next;
int cpu;
int ret;
@@ -844,7 +840,6 @@
return NULL;
do {
- next = -1;
if (filter_cpus) {
long long last_stamp = -1;
struct pevent_record *precord;
@@ -888,7 +883,6 @@
handles->record = record;
if (!record)
handles->done = 1;
- *next_cpu = next;
return record;
}
@@ -932,9 +926,7 @@
struct handle_list *last_handle;
struct pevent_record *record;
struct pevent_record *last_record;
- int last_cpu;
int cpus;
- int next;
int ret;
list_for_each_entry(handles, handle_list, list) {
@@ -1000,17 +992,16 @@
last_record = NULL;
list_for_each_entry(handles, handle_list, list) {
- record = get_next_record(handles, &next);
+ record = get_next_record(handles);
if (!last_record ||
(record && record->ts < last_record->ts)) {
last_record = record;
last_handle = handles;
- last_cpu = next;
}
}
if (last_record) {
print_handle_file(last_handle);
- show_data(last_handle->handle, last_record, last_cpu);
+ show_data(last_handle->handle, last_record);
free_handle_record(last_handle);
}
} while (last_record);