Fix: support 64-bit events discarded counter types
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 2 May 2012 15:48:52 +0000 (11:48 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 2 May 2012 15:48:52 +0000 (11:48 -0400)
Previously, counters coming for 64-bit architectures would be treated in
the same way as 32-bit counters, and would therefore miss 32-bit
overflows (only happens if 2^32 events or more are lost within in a
packet).

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

index 1d29390c7a1c5a5ed034c31cd0965b728704ca4d..4f5ba73e97b22cf045bbba3294ca43a5ce953bce 100644 (file)
@@ -244,7 +244,7 @@ int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream_definition *
        /* Print events discarded */
        if (stream->events_discarded) {
                fflush(pos->fp);
-               fprintf(stderr, "[warning] Tracer discarded %d events between [",
+               fprintf(stderr, "[warning] Tracer discarded %" PRIu64 " events between [",
                        stream->events_discarded);
                ctf_print_timestamp(stderr, stream, stream->prev_timestamp);
                fprintf(stderr, "] and [");
index bff84fe1df631fe836a7c5379ce3b3098782f8bc..07966632e82caa99139f20458faf7f3d99f87449 100644 (file)
@@ -594,7 +594,7 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
                switch (whence) {
                case SEEK_CUR:
                {
-                       uint32_t events_discarded_diff;
+                       uint64_t events_discarded_diff;
 
                        if (pos->offset == EOF) {
                                return;
@@ -610,6 +610,13 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
                                                struct packet_index,
                                                pos->cur_index - 1);
                                events_discarded_diff -= packet_index->events_discarded;
+                               /*
+                                * Deal with 32-bit wrap-around if the
+                                * tracer provided a 32-bit field.
+                                */
+                               if (packet_index->events_discarded_len == 32) {
+                                       events_discarded_diff = (uint32_t) events_discarded_diff;
+                               }
                        }
                        file_stream->parent.events_discarded = events_discarded_diff;
                        file_stream->parent.prev_timestamp = file_stream->parent.timestamp;
@@ -643,7 +650,7 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
                                 */
                                if ((&file_stream->parent)->stream_class->trace->collection) {
                                        fflush(stdout);
-                                       fprintf(stderr, "[warning] Tracer discarded %d events at end of stream between [",
+                                       fprintf(stderr, "[warning] Tracer discarded %" PRIu64 " events at end of stream between [",
                                                        file_stream->parent.events_discarded);
                                        ctf_print_timestamp(stderr, &file_stream->parent,
                                                        file_stream->parent.prev_timestamp);
@@ -1296,6 +1303,7 @@ int create_stream_packet_index(struct ctf_trace *td,
 
                                field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
                                packet_index.events_discarded = get_unsigned_int(field);
+                               packet_index.events_discarded_len = get_int_len(field);
                        }
                } else {
                        /* Use file size for packet size */
index c18749f708906b84f6b01dde9f193d38322edec5..a24dafabd41dbbcc497b43e84080c9df9b9e8b4d 100644 (file)
@@ -52,9 +52,9 @@ struct ctf_stream_definition {
        struct ctf_clock *current_clock;
 
        /* Event discarded information */
-       uint32_t events_discarded;
-       uint64_t prev_timestamp;        /* Last event */
-       uint64_t prev_timestamp_end;    /* End-of-packet timestamp */
+       uint64_t events_discarded;
+       uint64_t prev_timestamp;        /* Start-of-last-packet timestamp */
+       uint64_t prev_timestamp_end;    /* End-of-last-packet timestamp */
 };
 
 struct ctf_event_definition {
index 9e429bd34763f1791de7c4e5392b8bd6e08b369c..14a7e3d4b0fedc51408e7f3a5141506f8952cfdb 100644 (file)
@@ -40,7 +40,8 @@ struct packet_index {
        uint64_t content_size;  /* content size, in bits */
        uint64_t timestamp_begin;
        uint64_t timestamp_end;
-       uint32_t events_discarded;
+       uint64_t events_discarded;
+       size_t events_discarded_len;    /* length of the field, in bits */
 };
 
 /*
This page took 0.04282 seconds and 4 git commands to generate.