ir: clock: use value in cycles instead of ns
[babeltrace.git] / formats / ctf / ir / clock.c
index bf2fbda5b2627b8cffb9584650ff1a81921b2afa..0bf7f3518cd5026450703001190699bd031be717 100644 (file)
@@ -327,7 +327,14 @@ int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time)
                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;
 }
@@ -337,12 +344,48 @@ int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time)
        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;
 }
This page took 0.024332 seconds and 4 git commands to generate.