Export the list header with a new namespace
[babeltrace.git] / formats / ctf / ctf.c
index f1c0de478ba7f5cc60a1c9e0ffa99555136eab49..fd9f49603a2a2834514538979bbfa0df917b9d51 100644 (file)
@@ -107,6 +107,9 @@ struct format ctf_format = {
        .close_trace = ctf_close_trace,
 };
 
+/*
+ * Update stream current timestamp, keep at clock frequency.
+ */
 static
 void ctf_update_timestamp(struct ctf_stream *stream,
                          struct definition_integer *integer_definition)
@@ -134,6 +137,10 @@ void ctf_update_timestamp(struct ctf_stream *stream,
        stream->timestamp = updateval;
 }
 
+/*
+ * Print timestamp, rescaling clock frequency to nanoseconds and
+ * applying offsets as needed (unix time).
+ */
 void ctf_print_timestamp(FILE *fp,
                        struct ctf_stream *stream,
                        uint64_t timestamp)
@@ -143,7 +150,12 @@ void ctf_print_timestamp(FILE *fp,
        struct trace_collection *tc = trace->collection;
        uint64_t tc_offset = tc->single_clock_offset_avg;
 
-       ts_nsec = timestamp;
+       if (stream->current_clock->freq == 1000000000ULL) {
+               ts_nsec = timestamp;
+       } else {
+               ts_nsec = (uint64_t) ((double) timestamp * 1000000000.0
+                               / (double) stream->current_clock->freq);
+       }
 
        /* Add offsets */
        if (!opt_clock_raw) {
@@ -217,6 +229,11 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
 
        ctf_pos_get_event(pos);
 
+       /* save the current position as a restore point */
+       pos->last_offset = pos->offset;
+       /* we just read the event, it is consumed when used by the caller */
+       stream->consumed = 0;
+
        /*
         * This is the EOF check after we've advanced the position in
         * ctf_pos_get_event.
@@ -495,8 +512,8 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence)
                        break;
                }
                case SEEK_SET:
-                       assert(offset == 0);    /* only seek supported for now */
-                       pos->cur_index = 0;
+                       if (offset == 0)
+                               pos->cur_index = 0;
                        file_stream->parent.prev_timestamp = 0;
                        file_stream->parent.prev_timestamp_end = 0;
                        break;
@@ -1168,14 +1185,14 @@ int create_stream_packet_index(struct ctf_trace *td,
 
                /* Validate content size and packet size values */
                if (packet_index.content_size > packet_index.packet_size) {
-                       fprintf(stderr, "[error] Content size (%zu bits) is larger than packet size (%zu bits).\n",
+                       fprintf(stderr, "[error] Content size (%" PRIu64 " bits) is larger than packet size (%" PRIu64 " bits).\n",
                                packet_index.content_size, packet_index.packet_size);
                        return -EINVAL;
                }
 
-               if (packet_index.packet_size > (filestats.st_size - packet_index.offset) * CHAR_BIT) {
-                       fprintf(stderr, "[error] Packet size (%zu bits) is larger than remaining file size (%zu bits).\n",
-                               packet_index.content_size, (size_t) (filestats.st_size - packet_index.offset) * CHAR_BIT);
+               if (packet_index.packet_size > ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT) {
+                       fprintf(stderr, "[error] Packet size (%" PRIu64 " bits) is larger than remaining file size (%" PRIu64 " bits).\n",
+                               packet_index.content_size, ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT);
                        return -EINVAL;
                }
 
@@ -1249,6 +1266,10 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
        ret = create_trace_definitions(td, &file_stream->parent);
        if (ret)
                goto error_def;
+       /*
+        * For now, only a single slock is supported.
+        */
+       file_stream->parent.current_clock = td->single_clock;
        ret = create_stream_packet_index(td, file_stream);
        if (ret)
                goto error_index;
@@ -1488,7 +1509,7 @@ int ctf_open_mmap_trace_read(struct ctf_trace *td,
         * for each stream, try to open, check magic number, and get the
         * stream ID to add to the right location in the stream array.
         */
-       cds_list_for_each_entry(mmap_info, &mmap_list->head, list) {
+       bt_list_for_each_entry(mmap_info, &mmap_list->head, list) {
                ret = ctf_open_mmap_stream_read(td, mmap_info, move_pos_slow);
                if (ret) {
                        fprintf(stderr, "[error] Open file mmap stream error.\n");
This page took 0.023808 seconds and 4 git commands to generate.