trace-cmd: Do not depend on timestamp not being zero
trace-cmd will interleave events based on timestamp when reading
multiple buffers (for each CPU as well as between trace files).
Currently, it is assumed that no timestamp will be zero, as tracing
doesn't start until a bit of time has passed. This is an incorrect
assumption, as tracing can use a "counter" clock that is not based on
time, as well as new ftrace code can start really early in boot before
the timer is active and all events will have a zero timestamp.
This causes trace-cmd to print events out of order, or worse, not even
show events with timestamps of zero.
Use a 'first_record' flag instead of the shortcut to use a timestap of
zero to denote if a record has been compared or not.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/trace-input.c b/trace-input.c
index 73363ed..aa42755 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -1812,6 +1812,7 @@
{
unsigned long long ts;
struct pevent_record *record;
+ int first_record = 1;
int next;
int cpu;
@@ -1823,9 +1824,10 @@
for (cpu = 0; cpu < handle->cpus; cpu++) {
record = tracecmd_peek_data(handle, cpu);
- if (record && (!ts || record->ts < ts)) {
+ if (record && (first_record || record->ts < ts)) {
ts = record->ts;
next = cpu;
+ first_record = 0;
}
}
diff --git a/trace-read.c b/trace-read.c
index 67c2e97..bfa7461 100644
--- a/trace-read.c
+++ b/trace-read.c
@@ -599,20 +599,22 @@
next = -1;
ts = 0;
if (filter_cpus) {
- unsigned long long last_stamp = 0;
+ long long last_stamp = -1;
struct pevent_record *precord;
+ int first_record = 1;
int next_cpu = -1;
int i;
for (i = 0; (cpu = filter_cpus[i]) >= 0; i++) {
precord = tracecmd_peek_data(handles->handle, cpu);
if (precord &&
- (!last_stamp || precord->ts < last_stamp)) {
+ (first_record || precord->ts < last_stamp)) {
next_cpu = cpu;
last_stamp = precord->ts;
+ first_record = 0;
}
}
- if (last_stamp)
+ if (!first_record)
record = tracecmd_read_data(handles->handle, next_cpu);
else
record = NULL;