From: Mathieu Desnoyers Date: Thu, 2 Oct 2014 19:23:46 +0000 (-0400) Subject: Fix: offset_s and CTF clocks with frequency != 1GHz X-Git-Tag: v1.2.4~3 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=b1b25c8336594451add511cd247cb73f23653333 Fix: offset_s and CTF clocks with frequency != 1GHz 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 --- diff --git a/formats/ctf/events-private.h b/formats/ctf/events-private.h index 4906c02a..9bea75d4 100644 --- a/formats/ctf/events-private.h +++ b/formats/ctf/events-private.h @@ -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 */ diff --git a/include/babeltrace/clock-internal.h b/include/babeltrace/clock-internal.h index 002cc7fd..cd6bdbae 100644 --- a/include/babeltrace/clock-internal.h +++ b/include/babeltrace/clock-internal.h @@ -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 */ diff --git a/lib/trace-collection.c b/lib/trace-collection.c index fa1497ac..035d2dc2 100644 --- a/lib/trace-collection.c +++ b/lib/trace-collection.c @@ -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;