goto end;
}
- *time = clock->time;
+ /* Common case where cycles are actually nanoseconds */
+ if (clock->frequency == 1000000000) {
+ *time = (int64_t) clock->value;
+ } else {
+ *time = (int64_t) ((1e9 * (double) clock->value) /
+ (double) clock->frequency);
+ }
+
end:
return ret;
}
int ret = 0;
/* Timestamps are strictly monotonic */
- if (!clock || time < clock->time) {
+ if (!clock) {
+ ret = -1;
+ goto end;
+ }
+
+ /* Common case where cycles are actually nanoseconds */
+ if (clock->frequency == 1000000000) {
+ clock->value = time;
+ goto end;
+ }
+
+ ret = bt_ctf_clock_set_value(clock,
+ (uint64_t) (((double) time * (double) clock->frequency) / 1e9));
+
+end:
+ return ret;
+}
+
+uint64_t bt_ctf_clock_get_value(struct bt_ctf_clock *clock)
+{
+ uint64_t ret = -1ULL;
+
+ if (!clock) {
+ goto end;
+ }
+
+ ret = clock->value;
+end:
+ return ret;
+}
+
+int bt_ctf_clock_set_value(struct bt_ctf_clock *clock, uint64_t value)
+{
+ int ret = 0;
+
+ /* Timestamps are strictly monotonic */
+ if (!clock || value < clock->value) {
ret = -1;
goto end;
}
- clock->time = time;
+ clock->value = value;
end:
return ret;
}
extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock,
int64_t time);
+extern uint64_t bt_ctf_clock_get_value(struct bt_ctf_clock *clock);
+
+extern int bt_ctf_clock_set_value(struct bt_ctf_clock *clock,
+ uint64_t value);
+
/*
* bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the
* refcount of the clock
#define DEFAULT_CLOCK_OFFSET_S 0
#define DEFAULT_CLOCK_IS_ABSOLUTE 0
#define DEFAULT_CLOCK_TIME 0
+#define DEFAULT_CLOCK_VALUE 0
-#define NR_TESTS 594
+#define NR_TESTS 597
static int64_t current_time = 42;
"bt_ctf_clock_get_time succeeds");
ok(get_time == DEFAULT_CLOCK_TIME,
"bt_ctf_clock_get_time returns the correct default time");
+ ok(bt_ctf_clock_get_value(clock) == DEFAULT_CLOCK_VALUE,
+ "bt_ctf_clock_get_value returns the correct default value");
+ ok(bt_ctf_clock_set_value(clock, current_time) == 0,
+ "Set clock value");
+ ok(bt_ctf_clock_get_value(clock) == current_time,
+ "bt_ctf_clock_get_value returns the correct value once it is set");
ok(bt_ctf_clock_set_time(clock, current_time) == 0,
"Set clock time");
ok(bt_ctf_clock_get_time(clock, &get_time) == 0,
"bt_ctf_clock_get_time succeeds");
- ok(get_time == current_time,
+ ok(get_time >= current_time - 1 && get_time <= current_time + 1,
"bt_ctf_clock_get_time returns the correct time once it is set");
ok(bt_ctf_writer_add_clock(writer, clock) == 0,