From 1924bed7bc5faaae152e27448dd9a0d97596a296 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Tue, 30 Apr 2019 19:01:17 -0400 Subject: [PATCH] src.ctf.fs: compute stream range using entire file info group 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 Change-Id: I5b13451d72a4b1aeb9f31140ebfb025e2d712d7e Reviewed-on: https://review.lttng.org/c/babeltrace/+/1128 Tested-by: jenkins Reviewed-by: Philippe Proulx --- plugins/ctf/fs-src/query.c | 46 +++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index c185307c..b56997c6 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -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"); -- 2.34.1