API fix: packet_seek should take an index rather than offset
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 17 Feb 2012 18:01:29 +0000 (13:01 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 17 Feb 2012 18:01:29 +0000 (13:01 -0500)
Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/bt-dummy/bt-dummy.c
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
include/babeltrace/context.h
include/babeltrace/ctf/types.h
include/babeltrace/format.h
lib/context.c
lib/iterator.c

index 3249317ae347fb0ab6a75ba9086e8859faea9d3d..e251ee7b80c22df13d9f89f6b8e6cc423997aa4d 100644 (file)
@@ -40,7 +40,7 @@ int bt_dummy_write_event(struct stream_pos *ppos,
 
 static
 struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_text_stream_pos *pos;
index 62cb5310092dce9dcdbbc1f28673a11bd7259bbe..20e18e86fcf1e952c8f090db3dff58eb430a3e76 100644 (file)
@@ -76,7 +76,7 @@ enum bt_loglevel {
 
 
 struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp);
 void ctf_text_close_trace(struct trace_descriptor *descriptor);
 
@@ -459,7 +459,7 @@ error:
 
 
 struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_text_stream_pos *pos;
index 5911b19d25cdaa5f45735893a0771af1fbf42b6a..17f299c3dece67bb334c769a1516fa9898ba0c60 100644 (file)
@@ -65,12 +65,14 @@ extern int yydebug;
 
 static
 struct trace_descriptor *ctf_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
-                       int whence), FILE *metadata_fp);
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
+                       int whence),
+               FILE *metadata_fp);
 static
 struct trace_descriptor *ctf_open_mmap_trace(
                struct mmap_stream_list *mmap_list,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset, int whence),
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
+                       int whence),
                FILE *metadata_fp);
 
 static
@@ -436,7 +438,11 @@ void ctf_fini_pos(struct ctf_stream_pos *pos)
        (void) g_array_free(pos->packet_index, TRUE);
 }
 
-void ctf_packet_seek(struct stream_pos *stream_pos, size_t offset, int whence)
+/*
+ * for SEEK_CUR: go to next packet.
+ * for SEEK_POS: go to packet numer (index).
+ */
+void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
 {
        struct ctf_stream_pos *pos =
                container_of(stream_pos, struct ctf_stream_pos, parent);
@@ -444,7 +450,7 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t offset, int whence)
                container_of(pos, struct ctf_file_stream, pos);
        int ret;
        off_t off;
-       struct packet_index *index;
+       struct packet_index *packet_index;
 
        if (pos->prot == PROT_WRITE && pos->content_size_loc)
                *pos->content_size_loc = pos->offset;
@@ -468,11 +474,10 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t offset, int whence)
                switch (whence) {
                case SEEK_CUR:
                        /* The writer will add padding */
-                       assert(pos->offset + offset == pos->packet_size);
                        pos->mmap_offset += WRITE_PACKET_LEN / CHAR_BIT;
                        break;
                case SEEK_SET:
-                       assert(offset == 0);    /* only seek supported for now */
+                       assert(index == 0);     /* only seek supported for now */
                        pos->cur_index = 0;
                        break;
                default:
@@ -495,27 +500,25 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t offset, int whence)
                                return;
                        }
                        /* For printing discarded event count */
-                       index = &g_array_index(pos->packet_index,
+                       packet_index = &g_array_index(pos->packet_index,
                                        struct packet_index, pos->cur_index);
-                       events_discarded_diff = index->events_discarded;
+                       events_discarded_diff = packet_index->events_discarded;
                        file_stream->parent.prev_timestamp_end =
-                                               index->timestamp_end;
+                                               packet_index->timestamp_end;
                        if (pos->cur_index > 0) {
-                               index = &g_array_index(pos->packet_index,
+                               packet_index = &g_array_index(pos->packet_index,
                                                struct packet_index,
                                                pos->cur_index - 1);
-                               events_discarded_diff -= index->events_discarded;
+                               events_discarded_diff -= packet_index->events_discarded;
                        }
                        file_stream->parent.events_discarded = events_discarded_diff;
                        file_stream->parent.prev_timestamp = file_stream->parent.timestamp;
                        /* The reader will expect us to skip padding */
-                       assert(pos->offset + offset == pos->content_size);
                        ++pos->cur_index;
                        break;
                }
                case SEEK_SET:
-                       if (offset == 0)
-                               pos->cur_index = 0;
+                       pos->cur_index = index;
                        file_stream->parent.prev_timestamp = 0;
                        file_stream->parent.prev_timestamp_end = 0;
                        break;
@@ -546,20 +549,19 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t offset, int whence)
                        pos->offset = EOF;
                        return;
                }
-               index = &g_array_index(pos->packet_index, struct packet_index,
+               packet_index = &g_array_index(pos->packet_index, struct packet_index,
                                       pos->cur_index);
-               pos->mmap_offset = index->offset;
+               pos->mmap_offset = packet_index->offset;
 
                /* Lookup context/packet size in index */
-               file_stream->parent.timestamp = index->timestamp_begin;
-               pos->content_size = index->content_size;
-               pos->packet_size = index->packet_size;
-               if (index->data_offset < index->content_size) {
+               file_stream->parent.timestamp = packet_index->timestamp_begin;
+               pos->content_size = packet_index->content_size;
+               pos->packet_size = packet_index->packet_size;
+               if (packet_index->data_offset < packet_index->content_size) {
                        pos->offset = 0;        /* will read headers */
-               } else if (index->data_offset == index->content_size) {
+               } else if (packet_index->data_offset == packet_index->content_size) {
                        /* empty packet */
-                       pos->offset = index->data_offset;
-                       offset = 0;
+                       pos->offset = packet_index->data_offset;
                        whence = SEEK_CUR;
                        goto read_next_packet;
                } else {
@@ -770,7 +772,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
 
 static
 int ctf_open_trace_metadata_read(struct ctf_trace *td,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_scanner *scanner;
@@ -1243,7 +1245,7 @@ error:
  */
 static
 int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence))
 {
        int ret;
@@ -1294,7 +1296,7 @@ error:
 static
 int ctf_open_trace_read(struct ctf_trace *td,
                const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        int ret;
@@ -1378,7 +1380,7 @@ error:
 
 static
 struct trace_descriptor *ctf_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_trace *td;
@@ -1467,7 +1469,7 @@ end:
 static
 int ctf_open_mmap_stream_read(struct ctf_trace *td,
                struct mmap_stream *mmap_info,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence))
 {
        int ret;
@@ -1502,7 +1504,7 @@ error_def:
 
 int ctf_open_mmap_trace_read(struct ctf_trace *td,
                struct mmap_stream_list *mmap_list,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset,
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence),
                FILE *metadata_fp)
 {
@@ -1535,7 +1537,8 @@ error:
 static
 struct trace_descriptor *ctf_open_mmap_trace(
                struct mmap_stream_list *mmap_list,
-               void (*packet_seek)(struct stream_pos *pos, size_t offset, int whence),
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
+                       int whence),
                FILE *metadata_fp)
 {
        struct ctf_trace *td;
index 6190d37bdbf643518a6c2bba432e643ae560023d..f9da534e66fd428572b1caba78b954e92c5a09a8 100644 (file)
@@ -51,7 +51,7 @@ struct bt_context *bt_context_create(void);
 int bt_context_add_trace(struct bt_context *ctx, const char *path,
                const char *format,
                void (*packet_seek)(struct stream_pos *pos,
-                       size_t offset, int whence));
+                       size_t index, int whence));
 
 /*
  * bt_context_remove_trace: Remove a trace from the context.
index 24e1aa5b4783166ff222e8571083040a44c3b373..faa653ea475056597da9c2c7af4f69079a09028f 100644 (file)
@@ -62,7 +62,7 @@ struct ctf_stream_pos {
        ssize_t offset;         /* offset from base, in bits. EOF for end of file. */
        ssize_t last_offset;    /* offset before the last read_event */
        size_t cur_index;       /* current index in packet index */
-       void (*packet_seek)(struct stream_pos *pos, size_t offset,
+       void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence); /* function called to switch packet */
 
        int dummy;              /* dummy position, for length calculation */
@@ -90,7 +90,7 @@ int ctf_array_write(struct stream_pos *pos, struct definition *definition);
 int ctf_sequence_read(struct stream_pos *pos, struct definition *definition);
 int ctf_sequence_write(struct stream_pos *pos, struct definition *definition);
 
-void ctf_packet_seek(struct stream_pos *pos, size_t offset, int whence);
+void ctf_packet_seek(struct stream_pos *pos, size_t index, int whence);
 
 void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags);
 void ctf_fini_pos(struct ctf_stream_pos *pos);
@@ -118,7 +118,7 @@ void ctf_move_pos(struct ctf_stream_pos *pos, size_t bit_offset)
                        && (unlikely(pos->offset + bit_offset >= pos->packet_size))) {
                        printf_debug("ctf_packet_seek (before call): %zd\n",
                                     pos->offset);
-                       ctf_packet_seek(&pos->parent, bit_offset, SEEK_CUR);
+                       ctf_packet_seek(&pos->parent, 0, SEEK_CUR);
                        printf_debug("ctf_packet_seek (after call): %zd\n",
                                     pos->offset);
                        return;
index bba056cc5a7c799a99451f265ae15248645e1c9b..8eae42c0e2aa7f3405969f785987216986d485d5 100644 (file)
@@ -48,12 +48,12 @@ struct format {
 
        struct trace_descriptor *(*open_trace)(const char *path, int flags,
                        void (*packet_seek)(struct stream_pos *pos,
-                               size_t offset, int whence),
+                               size_t index, int whence),
                        FILE *metadata_fp);
        struct trace_descriptor *(*open_mmap_trace)(
                        struct mmap_stream_list *mmap_list,
                        void (*packet_seek)(struct stream_pos *pos,
-                               size_t offset, int whence),
+                               size_t index, int whence),
                        FILE *metadata_fp);
        void (*close_trace)(struct trace_descriptor *descriptor);
 };
index 5021d7add1c56ab92386e4f93cdd43c520509086..1311b5c2a0e684e81d51fb2adf688e3db66bf5d4 100644 (file)
@@ -58,8 +58,8 @@ struct bt_context *bt_context_create(void)
 
 int bt_context_add_trace(struct bt_context *ctx, const char *path,
                const char *format_name,
-               void (*packet_seek)(struct stream_pos *pos,
-                       size_t offset, int whence))
+               void (*packet_seek)(struct stream_pos *pos, size_t index,
+                       int whence))
 {
        struct trace_descriptor *td;
        struct format *fmt;
index 2cb40cbc5b166a4e4884c58f4d52e817a7a7e8a0..398b097bce00bdb7723bcb2ea75c22d399888620 100644 (file)
@@ -115,9 +115,7 @@ static int seek_file_stream_by_timestamp(struct ctf_file_stream *cfs,
                                index->timestamp_end <= timestamp)
                        continue;
 
-               stream_pos->cur_index = i;
-               stream_pos->packet_seek(&stream_pos->parent,
-                       index->offset, SEEK_SET);
+               stream_pos->packet_seek(&stream_pos->parent, i, SEEK_SET);
                while (cfs->parent.timestamp < timestamp) {
                        ret = stream_read_event(cfs);
                        if (ret < 0)
@@ -191,7 +189,6 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
                                i++) {
                        struct stream_saved_pos *saved_pos;
                        struct ctf_stream_pos *stream_pos;
-                       struct packet_index *index;
                        struct ctf_stream *stream;
 
                        saved_pos = &g_array_index(
@@ -199,13 +196,9 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
                                        struct stream_saved_pos, i);
                        stream = &saved_pos->file_stream->parent;
                        stream_pos = &saved_pos->file_stream->pos;
-                       index = &g_array_index(stream_pos->packet_index,
-                                       struct packet_index,
-                                       saved_pos->cur_index);
 
-                       stream_pos->cur_index = saved_pos->cur_index;
                        stream_pos->packet_seek(&stream_pos->parent,
-                                       index->offset, SEEK_SET);
+                                       saved_pos->cur_index, SEEK_SET);
 
                        /*
                         * the timestamp needs to be restored after
This page took 0.0318 seconds and 4 git commands to generate.