-struct ctf_fs_ds_index *ctf_fs_ds_index_create(size_t length)
-{
- struct ctf_fs_ds_index *index = g_new0(struct ctf_fs_ds_index, 1);
-
- if (!index) {
- BT_LOGE_STR("Failed to allocate index");
- goto error;
- }
-
- index->entries = g_array_sized_new(FALSE, TRUE,
- sizeof(struct ctf_fs_ds_index_entry), length);
- if (!index->entries) {
- BT_LOGE("Failed to allocate %zu index entries.", length);
- goto error;
- }
- g_array_set_size(index->entries, length);
-end:
- return index;
-error:
- ctf_fs_ds_index_destroy(index);
- goto end;
-}
-
-/* Returns a new, zeroed, index entry. */
-static
-struct ctf_fs_ds_index_entry *ctf_fs_ds_index_add_new_entry(
- struct ctf_fs_ds_index *index)
-{
- g_array_set_size(index->entries, index->entries->len + 1);
- return &g_array_index(index->entries, struct ctf_fs_ds_index_entry,
- index->entries->len - 1);
-}
-
-static
-struct bt_ctf_clock_class *get_field_mapped_clock_class(
- struct bt_ctf_field *field)
-{
- struct bt_ctf_field_type *field_type;
- struct bt_ctf_clock_class *clock_class = NULL;
-
- field_type = bt_ctf_field_get_type(field);
- if (!field_type) {
- goto end;
- }
-
- clock_class = bt_ctf_field_type_integer_get_mapped_clock_class(
- field_type);
- if (!clock_class) {
- goto end;
- }
-end:
- bt_put(field_type);
- return clock_class;
-}
-
-static
-int get_packet_bounds_from_packet_context(
- struct bt_ctf_field *packet_context,
- struct bt_ctf_clock_class **_timestamp_begin_cc,
- struct bt_ctf_field **_timestamp_begin,
- struct bt_ctf_clock_class **_timestamp_end_cc,
- struct bt_ctf_field **_timestamp_end)
-{
- int ret = 0;
- struct bt_ctf_clock_class *timestamp_begin_cc = NULL;
- struct bt_ctf_clock_class *timestamp_end_cc = NULL;
- struct bt_ctf_field *timestamp_begin = NULL;
- struct bt_ctf_field *timestamp_end = NULL;
-
- timestamp_begin = bt_ctf_field_structure_get_field_by_name(
- packet_context, "timestamp_begin");
- if (!timestamp_begin) {
- BT_LOGD_STR("Cannot retrieve timestamp_begin field in packet context.");
- ret = -1;
- goto end;
- }
-
- timestamp_begin_cc = get_field_mapped_clock_class(timestamp_begin);
- if (!timestamp_begin_cc) {
- BT_LOGD_STR("Cannot retrieve the clock mapped to timestamp_begin.");
- }
-
- timestamp_end = bt_ctf_field_structure_get_field_by_name(
- packet_context, "timestamp_end");
- if (!timestamp_end) {
- BT_LOGD_STR("Cannot retrieve timestamp_end field in packet context.");
- ret = -1;
- goto end;
- }
-
- timestamp_end_cc = get_field_mapped_clock_class(timestamp_end);
- if (!timestamp_end_cc) {
- BT_LOGD_STR("Cannot retrieve the clock mapped to timestamp_end.");
- }
-
- if (_timestamp_begin_cc) {
- *_timestamp_begin_cc = bt_get(timestamp_begin_cc);
- }
- if (_timestamp_begin) {
- *_timestamp_begin = bt_get(timestamp_begin);
- }
- if (_timestamp_end_cc) {
- *_timestamp_end_cc = bt_get(timestamp_end_cc);
- }
- if (_timestamp_end) {
- *_timestamp_end = bt_get(timestamp_end);
- }
-end:
- bt_put(timestamp_begin_cc);
- bt_put(timestamp_end_cc);
- bt_put(timestamp_begin);
- bt_put(timestamp_end);
- return ret;
-}
-
-static
-int get_ds_file_packet_bounds_clock_classes(struct ctf_fs_ds_file *ds_file,
- struct bt_ctf_clock_class **timestamp_begin_cc,
- struct bt_ctf_clock_class **timestamp_end_cc)
-{
- struct bt_ctf_field *packet_context = NULL;
- int ret = ctf_fs_ds_file_get_packet_header_context_fields(ds_file,
- NULL, &packet_context);
-
- if (ret || !packet_context) {
- BT_LOGD("Cannot retrieve packet context field of stream \'%s\'",
- ds_file->file->path->str);
- ret = -1;
- goto end;
- }
-
- ret = get_packet_bounds_from_packet_context(packet_context,
- timestamp_begin_cc, NULL,
- timestamp_end_cc, NULL);
-end:
- bt_put(packet_context);
- return ret;
-}
-
-static
-int convert_cycles_to_ns(struct bt_ctf_clock_class *clock_class,