Update timestamps by carrying the overflow
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 23 May 2011 15:13:54 +0000 (11:13 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 23 May 2011 15:13:54 +0000 (11:13 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
include/babeltrace/ctf/metadata.h
include/babeltrace/ctf/types.h

index 5e43d2fa867cce377f14cf9869929ef20afd79bd..29f95fec1bcae16ba7a8dcc53665c51d18d7729b 100644 (file)
@@ -87,6 +87,32 @@ struct format ctf_format = {
        .close_trace = ctf_close_trace,
 };
 
+static
+void ctf_update_timestamp(struct ctf_stream *stream,
+                         struct definition_integer *integer_definition)
+{
+       struct declaration_integer *integer_declaration =
+               integer_definition->declaration;
+       uint64_t oldval, newval, updateval;
+
+       if (integer_declaration->len == 64) {
+               stream->timestamp = integer_definition->value._unsigned;
+               return;
+       }
+       /* keep low bits */
+       oldval = stream->timestamp;
+       oldval &= (1ULL << integer_declaration->len) - 1;
+       newval = integer_definition->value._unsigned;
+       /* Test for overflow by comparing low bits */
+       if (newval < oldval)
+               newval += 1ULL << integer_declaration->len;
+       /* updateval contains old high bits, and new low bits (sum) */
+       updateval = stream->timestamp;
+       updateval &= ~((1ULL << integer_declaration->len) - 1);
+       updateval += newval;
+       stream->timestamp = updateval;
+}
+
 static
 int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
 {
@@ -132,12 +158,12 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
                /* lookup timestamp */
                integer_definition = lookup_integer(&stream_class->event_header->p, "timestamp", FALSE);
                if (integer_definition) {
-                       stream->timestamp = integer_definition->value._unsigned;
+                       ctf_update_timestamp(stream, integer_definition);
                } else {
                        if (variant) {
                                integer_definition = lookup_integer(variant, "timestamp", FALSE);
                                if (integer_definition) {
-                                       stream->timestamp = integer_definition->value._unsigned;
+                                       ctf_update_timestamp(stream, integer_definition);
                                }
                        }
                }
@@ -381,7 +407,12 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
                /* Lookup context/packet size in index */
                pos->content_size = index->content_size;
                pos->packet_size = index->packet_size;
-               pos->offset = index->data_offset;
+               if (index->data_offset < index->content_size)
+                       pos->offset = index->data_offset;
+               else {
+                       pos->offset = EOF;
+                       return;
+               }
        }
        /* map new base. Need mapping length from header. */
        pos->base = mmap(NULL, pos->packet_size / CHAR_BIT, pos->prot,
index e3cd325ae8aa6637b51c971541176b7f4f230a2a..25baa3a95395e43b5b3f1d9bd48baf4bc41ae59f 100644 (file)
@@ -194,5 +194,4 @@ struct metadata_packet_header {
        HEADER_END;
 };
 
-
 #endif /* _BABELTRACE_CTF_METADATA_H */
index 1ec2ad5a497ba07472667db066b478f8803fc8c6..14da1d91108e8a575336c8750462d9d39c2dd9e8 100644 (file)
@@ -33,7 +33,7 @@
 
 struct packet_index {
        off_t offset;           /* offset of the packet in the file, in bytes */
-       off_t data_offset;      /* offset of data within the packet */
+       off_t data_offset;      /* offset of data within the packet, in bits */
        size_t packet_size;     /* packet size, in bits */
        size_t content_size;    /* content size, in bits */
 };
This page took 0.026734 seconds and 4 git commands to generate.