tap-driver.sh: flush stdout after each test result
[babeltrace.git] / plugins / ctf / fs-src / query.c
index d666e1c4f6f9baab495027975ac29dacfc5a6a08..e2018b157a0aef746e6d1c7ea85781bd992dd8a0 100644 (file)
 
 #include "query.h"
 #include <stdbool.h>
-#include <babeltrace/assert-internal.h>
+#include <babeltrace2/assert-internal.h>
 #include "metadata.h"
 #include "../common/metadata/decoder.h"
-#include <babeltrace/common-internal.h>
-#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/babeltrace.h>
+#include <babeltrace2/common-internal.h>
+#include <babeltrace2/babeltrace-internal.h>
+#include <babeltrace2/babeltrace.h>
 #include "fs.h"
 
 #define BT_LOG_TAG "PLUGIN-CTF-FS-QUERY-SRC"
@@ -271,7 +271,6 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group,
        size_t file_idx;
        bt_value_status status;
        bt_value *file_paths;
-       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;
        gchar *port_name = NULL;
 
@@ -295,43 +294,37 @@ int populate_stream_info(struct ctf_fs_ds_file_group *group,
        }
 
        /*
-        * 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.
+        * Since each `struct ctf_fs_ds_file_group` has a sorted array of
+        * `struct ctf_fs_ds_index_entry`, we can compute the stream range from
+        * the timestamp_begin of the first index entry and the timestamp_end
+        * of the last index entry.
         */
-       BT_ASSERT(group->ds_file_infos->len > 0);
+       BT_ASSERT(group->index);
+       BT_ASSERT(group->index->entries);
+       BT_ASSERT(group->index->entries->len > 0);
 
-       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);
+       /* First entry. */
+       first_ds_index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index(
+               group->index->entries, 0);
 
-       BT_ASSERT(first_file_info->index);
-       BT_ASSERT(first_file_info->index->entries);
-       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);
-       BT_ASSERT(last_file_info->index->entries);
-       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);
+       /* Last entry. */
+       last_ds_index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index(
+               group->index->entries, group->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");
-               if (ret) {
-                       goto end;
-               }
+       /*
+        * If any of the begin and end timestamps is not set it means that
+        * packets don't include `timestamp_begin` _and_ `timestamp_end` fields
+        * in their packet context so we can't set the range.
+        */
+       stream_range->set = stream_range->begin_ns != UINT64_C(-1) &&
+               stream_range->end_ns != UINT64_C(-1);
+
+       ret = add_range(group_info, stream_range, "range-ns");
+       if (ret) {
+               goto end;
        }
 
        status = bt_value_map_insert_entry(group_info, "paths",
@@ -427,6 +420,12 @@ int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info)
                        goto end;
                }
 
+               status = bt_value_array_append_element(file_groups, group_info);
+               bt_value_put_ref(group_info);
+               if (status != BT_VALUE_STATUS_OK) {
+                       goto end;
+               }
+
                if (group_range.set) {
                        trace_range.begin_ns = min(trace_range.begin_ns,
                                        group_range.begin_ns);
@@ -439,13 +438,6 @@ int populate_trace_info(const struct ctf_fs_trace *trace, bt_value *trace_info)
                        trace_intersection.end_ns = min(trace_intersection.end_ns,
                                        group_range.end_ns);
                        trace_intersection.set = true;
-                       status = bt_value_array_append_element(
-                               file_groups,
-                               group_info);
-                       bt_value_put_ref(group_info);
-                       if (status != BT_VALUE_STATUS_OK) {
-                               goto end;
-                       }
                }
        }
 
This page took 0.025069 seconds and 4 git commands to generate.