+ clock_class_count = bt_ctf_trace_get_clock_class_count(ctx->trace);
+ assert(clock_class_count >= 0);
+
+ switch (clock_class_count) {
+ case 0:
+ /*
+ * No clock class exists in the trace at this
+ * point. Create an implicit one at 1 GHz,
+ * named `default`, and use this clock class.
+ */
+ clock_class_to_map_to = bt_ctf_clock_class_create("default",
+ 1000000000);
+ if (!clock_class_to_map_to) {
+ BT_LOGE_STR("Cannot create a clock class.");
+ ret = -1;
+ goto end;
+ }
+
+ ret = bt_ctf_trace_add_clock_class(ctx->trace,
+ clock_class_to_map_to);
+ if (ret) {
+ BT_LOGE_STR("Cannot add clock class to trace.");
+ goto end;
+ }
+ break;
+ case 1:
+ /*
+ * Only one clock class exists in the trace at
+ * this point: use this one.
+ */
+ clock_class_to_map_to =
+ bt_ctf_trace_get_clock_class_by_index(ctx->trace, 0);
+ assert(clock_class_to_map_to);
+ break;
+ default:
+ /*
+ * Timestamp field not mapped to a clock class
+ * and there's more than one clock class in the
+ * trace: this is an error.
+ */
+ BT_LOGE_STR("Timestamp field found with no mapped clock class, "
+ "but there's more than one clock class in the trace at this point.");
+ ret = -1;