src.ctf.fs: compute stream range using entire file info group
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 30 Apr 2019 23:01:17 +0000 (19:01 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:12:56 +0000 (00:12 -0400)
Given that index entries are sorted within their file info structure and
that file info structures are sorted by time within the file info group,
we can simply compute the range of the stream by using the absolute
first index entry and the absolute last index entry of the entire file
info group.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I5b13451d72a4b1aeb9f31140ebfb025e2d712d7e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1128
Tested-by: jenkins
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
plugins/ctf/fs-src/query.c

index c185307caa3f6b2ef8d1dcd90b0704ec81876117..b56997c655bfa558c066061f3f8626902b62ef10 100644 (file)
@@ -271,9 +271,8 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group,
        size_t file_idx;
        bt_value_status status;
        bt_value *file_paths;
-
-       stream_range->begin_ns = INT64_MAX;
-       stream_range->end_ns = 0;
+       struct ctf_fs_ds_file_info *first_file_info, *last_file_info;
+       struct ctf_fs_ds_index_entry *first_ds_index_entry, *last_ds_index_entry;
 
        file_paths = bt_value_array_create();
        if (!file_paths) {
@@ -282,7 +281,6 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group,
        }
 
        for (file_idx = 0; file_idx < group->ds_file_infos->len; file_idx++) {
-               int64_t file_begin_epoch, file_end_epoch;
                struct ctf_fs_ds_file_info *info =
                        g_ptr_array_index(group->ds_file_infos,
                                file_idx);
@@ -300,20 +298,36 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group,
                        ret = -1;
                        goto end;
                }
+       }
 
-               /*
-                * file range is from timestamp_begin of the first entry to the
-                * timestamp_end of the last entry.
-                */
-               file_begin_epoch = ((struct ctf_fs_ds_index_entry *) &g_array_index(info->index->entries,
-                               struct ctf_fs_ds_index_entry, 0))->timestamp_begin_ns;
-               file_end_epoch = ((struct ctf_fs_ds_index_entry *) &g_array_index(info->index->entries,
-                               struct ctf_fs_ds_index_entry, info->index->entries->len - 1))->timestamp_end_ns;
+       /*
+        * Since `struct ctf_fs_ds_file_info` elements are sorted by value of
+        * `begin_ns` within the `ds_file_groups` array and `struct
+        * ctf_fs_ds_index_entry` elements are sorted by time within their
+        * respective `struct ctf_fs_ds_file_info`, we can compute the stream
+        * range from timestamp_begin of the first index entry of the first
+        * file to the timestamp_end of the last index entry of the last file.
+        */
+       BT_ASSERT(group->ds_file_infos->len > 0);
 
-               stream_range->begin_ns = min(stream_range->begin_ns, file_begin_epoch);
-               stream_range->end_ns = max(stream_range->end_ns, file_end_epoch);
-               stream_range->set = true;
-       }
+       first_file_info = g_ptr_array_index(group->ds_file_infos, 0);
+       last_file_info = g_ptr_array_index(group->ds_file_infos,
+               group->ds_file_infos->len - 1);
+
+       BT_ASSERT(first_file_info->index->entries->len > 0);
+
+       first_ds_index_entry = (struct ctf_fs_ds_index_entry *) &g_array_index(
+               first_file_info->index->entries, struct ctf_fs_ds_index_entry, 0);
+
+       BT_ASSERT(last_file_info->index->entries->len > 0);
+
+       last_ds_index_entry = (struct ctf_fs_ds_index_entry *) &g_array_index(
+               last_file_info->index->entries, struct ctf_fs_ds_index_entry,
+               last_file_info->index->entries->len - 1);
+
+       stream_range->begin_ns = first_ds_index_entry->timestamp_begin_ns;
+       stream_range->end_ns = last_ds_index_entry->timestamp_end_ns;
+       stream_range->set = true;
 
        if (stream_range->set) {
                ret = add_range(group_info, stream_range, "range-ns");
This page took 0.02607 seconds and 5 git commands to generate.