Fix: offset_s and CTF clocks with frequency != 1GHz
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 2 Oct 2014 19:23:46 +0000 (15:23 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 2 Oct 2014 19:26:37 +0000 (15:26 -0400)
Take into account offset_s from the clock description when calculating
the tc_offset in ctf_get_real_timestamp().

Do not assume that the single_clock->offset field is at a frequency of
1GHz. Take into account the its clock frequency.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/events-private.h
include/babeltrace/clock-internal.h
lib/trace-collection.c

index 4906c02aa9171ec6674b11b679ef74886e045e8f..9bea75d4f6bad5a2895204bbb08c4fe17d3a9d9d 100644 (file)
@@ -46,7 +46,7 @@ uint64_t ctf_get_real_timestamp(struct ctf_stream_definition *stream,
        if (tc->clock_use_offset_avg)
                tc_offset = tc->single_clock_offset_avg;
        else
-               tc_offset = trace->parent.single_clock->offset;
+               tc_offset = clock_offset_ns(trace->parent.single_clock);
 
        ts_nsec = clock_cycles_to_ns(stream->current_clock, timestamp);
        ts_nsec += tc_offset;   /* Add offset */
index 002cc7fd848bd26c291c298ac22ce7ff33ee7b56..cd6bdbae03b9d2ecc8ad7f04142378cf280b0a95 100644 (file)
@@ -42,4 +42,17 @@ uint64_t clock_cycles_to_ns(struct ctf_clock *clock, uint64_t cycles)
        }
 }
 
+/*
+ * Note: if using a frequency different from 1GHz for clock->offset, it
+ * is recommended to express the seconds in offset_s, otherwise there
+ * will be a loss of precision caused by the limited size of the double
+ * mantissa.
+ */
+static inline
+uint64_t clock_offset_ns(struct ctf_clock *clock)
+{
+       return clock->offset_s * 1000000000ULL
+                       + clock_cycles_to_ns(clock, clock->offset);
+}
+
 #endif /* _BABELTRACE_CLOCK_INTERNAL_H */
index fa1497acbfc34897924b3e58fafda0a59c0cb6e9..035d2dc2d78a77a596e1b0fce2d6e8ccc86f6c3c 100644 (file)
@@ -72,19 +72,6 @@ static void check_clock_match(gpointer key, gpointer value, gpointer user_data)
        }
 }
 
-/*
- * Note: if using a frequency different from 1GHz for clock->offset, it
- * is recommended to express the seconds in offset_s, otherwise there
- * will be a loss of precision caused by the limited size of the double
- * mantissa.
- */
-static
-uint64_t clock_offset_ns(struct ctf_clock *clock)
-{
-       return clock->offset_s * 1000000000ULL
-                       + clock_cycles_to_ns(clock, clock->offset);
-}
-
 static void clock_add(gpointer key, gpointer value, gpointer user_data)
 {
        struct clock_match *clock_match = user_data;
This page took 0.035051 seconds and 4 git commands to generate.