+ 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,
+ uint64_t cycles, int64_t *ns)
+{
+ int ret = 0;
+ struct bt_ctf_clock_value *clock_value;
+
+ assert(ns);
+ clock_value = bt_ctf_clock_value_create(clock_class, cycles);
+ if (!clock_value) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value, ns);
+ if (ret) {
+ goto end;
+ }
+end:
+ bt_put(clock_value);
+ return ret;
+}
+
+static
+struct ctf_fs_ds_index *build_index_from_idx_file(
+ struct ctf_fs_ds_file *ds_file)
+{
+ int ret;