+ * Babeltrace 2.0 introduced a notion of per-event clock
+ * values which can be queried using a "clock" instance.
+ *
+ * However, the original CTF-Writer (BT 1.x) had a
+ * notion of per-stream clock which is sampled on
+ * a call to append an event to a stream.
+ *
+ * If the event has a clock value associated with the
+ * mapped clock, we ignore the pre-2.0 behaviour and
+ * populate the timestamp field using the clock value.
+ */
+ uint64_t timestamp = 0;
+ struct bt_ctf_clock_value *clock_value;
+
+ clock_value = bt_ctf_event_get_clock_value(event,
+ mapped_clock);
+ if (clock_value) {
+ ret = bt_ctf_clock_value_get_value(clock_value,
+ ×tamp);
+ bt_put(clock_value);
+ if (ret) {
+ goto end;
+ }
+ } else {
+ ret = bt_ctf_clock_get_value(mapped_clock,
+ ×tamp);
+ if (ret) {
+ goto end;
+ }