Compare traces by stream path as secondary key
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Jun 2013 20:17:17 +0000 (16:17 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Jun 2013 20:17:17 +0000 (16:17 -0400)
Ensure runs of babeltrace in different environments give the same output
for the same trace collection. There are usually few events with the
same timestamp in a trace, so this secondary key comparison should not
be often required.

Fixes #540

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lib/iterator.c

index 4190e65286d914021133ea110e936a27ce51c208..009fcd3fecf0b502e19a4719225d470fd4719c7d 100644 (file)
@@ -73,16 +73,24 @@ static int stream_read_event(struct ctf_file_stream *sin)
 }
 
 /*
- * returns true if a < b, false otherwise.
+ * Return true if a < b, false otherwise.
+ * If time stamps are exactly the same, compare by stream path. This
+ * ensures we get the same result between runs on the same trace
+ * collection on different environments.
+ * The result will be random for memory-mapped traces since there is no
+ * fixed path leading to those (they have empty path string).
  */
 static int stream_compare(void *a, void *b)
 {
        struct ctf_file_stream *s_a = a, *s_b = b;
 
-       if (s_a->parent.real_timestamp < s_b->parent.real_timestamp)
+       if (s_a->parent.real_timestamp < s_b->parent.real_timestamp) {
                return 1;
-       else
+       } else if (likely(s_a->parent.real_timestamp > s_b->parent.real_timestamp)) {
                return 0;
+       } else {
+               return strcmp(s_a->parent.path, s_b->parent.path);
+       }
 }
 
 void bt_iter_free_pos(struct bt_iter_pos *iter_pos)
This page took 0.025784 seconds and 4 git commands to generate.