Time offset: use trace offset average
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Jan 2012 23:33:12 +0000 (18:33 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 Jan 2012 23:33:12 +0000 (18:33 -0500)
Use the average offset for a given clock across all trace descriptions
as offset for the trace collection. This ensures that the time-stamps
stay invariant for a given trace collection: it won't change if the
traversal order of the trace directories change.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
converter/babeltrace.c
formats/ctf/ctf.c
include/babeltrace/babeltrace-internal.h
include/babeltrace/ctf-ir/metadata.h

index 22ec92446c5c32ea337706e1355496a5b1be93c7..f872e6dc30ccea4ca06b9f84cae475f4e0a2bb5b 100644 (file)
@@ -301,6 +301,10 @@ static void init_trace_collection(struct trace_collection *tc)
 {
        tc->array = g_ptr_array_sized_new(DEFAULT_FILE_ARRAY_SIZE);
        tc->clocks = g_hash_table_new(g_direct_hash, g_direct_equal);
+       tc->single_clock_offset_avg = 0;
+       tc->offset_first = 0;
+       tc->delta_offset_first_sum = 0;
+       tc->offset_nr = 0;
 }
 
 /*
@@ -375,13 +379,18 @@ static void clock_add(gpointer key, gpointer value, gpointer user_data)
                if (!tc_clock) {
                        /*
                         * For now, we only support CTF that has one
-                        * single clock.
+                        * single clock uuid or name (absolute ref).
                         */
                        if (g_hash_table_size(tc_clocks) > 0) {
                                fprintf(stderr, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
                        }
-                       if (!clock_match->tc->single_clock) {
-                               clock_match->tc->single_clock = value;
+                       if (!clock_match->tc->offset_nr) {
+                               clock_match->tc->offset_first =
+                                       (t_clock->offset_s * 1000000000ULL) + t_clock->offset;
+                               clock_match->tc->delta_offset_first_sum = 0;
+                               clock_match->tc->offset_nr++;
+                               clock_match->tc->single_clock_offset_avg =
+                                       clock_match->tc->offset_first;
                        }
                        g_hash_table_insert(tc_clocks,
                                (gpointer) (unsigned long) v,
@@ -402,10 +411,18 @@ static void clock_add(gpointer key, gpointer value, gpointer user_data)
                                g_quark_to_string(tc_clock->name),
                                diff_ns < 0 ? -diff_ns : diff_ns);
                        if (diff_ns > 10000) {
-                               fprintf(stderr, "[warning] Clock \"%s\" offset differs between traces (delta %" PRIu64 " ns). Choosing one arbitrarily.\n",
+                               fprintf(stderr, "[warning] Clock \"%s\" offset differs between traces (delta %" PRIu64 " ns). Using average.\n",
                                        g_quark_to_string(tc_clock->name),
                                        diff_ns < 0 ? -diff_ns : diff_ns);
                        }
+                       /* Compute average */
+                       clock_match->tc->delta_offset_first_sum +=
+                               (t_clock->offset_s * 1000000000ULL) + t_clock->offset
+                               - clock_match->tc->offset_first;
+                       clock_match->tc->offset_nr++;
+                       clock_match->tc->single_clock_offset_avg =
+                               clock_match->tc->offset_first
+                               + (clock_match->tc->delta_offset_first_sum / clock_match->tc->offset_nr);
                }
        }
 }
index 62cc2e3939e2f8506d779aada3c02b215a6623d0..ab4945dddcff18b8c41c6df91798096b4940695b 100644 (file)
@@ -141,14 +141,13 @@ void ctf_print_timestamp(FILE *fp,
        uint64_t ts_sec = 0, ts_nsec;
        struct ctf_trace *trace = stream->stream_class->trace;
        struct trace_collection *tc = trace->collection;
-       struct ctf_clock *clock = tc->single_clock;
+       uint64_t tc_offset = tc->single_clock_offset_avg;
 
        ts_nsec = timestamp;
 
        /* Add offsets */
-       if (!opt_clock_raw && clock) {
-               ts_sec += clock->offset_s;
-               ts_nsec += clock->offset;
+       if (!opt_clock_raw) {
+               ts_nsec += tc_offset;
        }
        ts_sec += opt_clock_offset;
 
index 913b043cf9d0b46b345015b9619c7c7755fac0be..8996afcddab8c67cc4d632227abbb42730215dd4 100644 (file)
@@ -26,7 +26,11 @@ struct trace_descriptor;
 struct trace_collection {
        GPtrArray *array;       /* struct trace_descriptor */
        GHashTable *clocks;     /* struct ctf_clock */
-       struct ctf_clock *single_clock;
+
+       uint64_t single_clock_offset_avg;
+       uint64_t offset_first;
+       int64_t delta_offset_first_sum;
+       int offset_nr;
 };
 
 extern int opt_all_field_names,
index 94de920cc060a4aef9ddd65ea1d08909d867df0b..ad40e03e75b3daa947f1b691d50f03cfb0be1964 100644 (file)
@@ -52,7 +52,6 @@ struct ctf_stream {
        uint32_t events_discarded;
        uint64_t prev_timestamp;        /* Last event */
        uint64_t prev_timestamp_end;    /* End-of-packet timestamp */
-       
 };
 
 struct ctf_stream_event {
This page took 0.037194 seconds and 4 git commands to generate.