Implement bt_ctf_clock_value interface
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 17 Nov 2016 21:47:47 +0000 (16:47 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:06 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/clock.c
formats/ctf/ir/event.c
include/babeltrace/ctf-ir/clock-internal.h
include/babeltrace/ctf-ir/clock.h
include/babeltrace/ctf-writer/clock.h
tests/lib/test_ctf_ir_ref.c
tests/lib/test_ctf_writer.c

index 738f2d80977a6a0eb0ee5b7195594493354b08a4..dee93c7a54634676f204ec4a0867cb74fcbad0d7 100644 (file)
@@ -336,30 +336,6 @@ uint64_t ns_from_value(uint64_t frequency, uint64_t value)
        return ns;
 }
 
-int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time)
-{
-       int ret = 0;
-
-       if (!clock || !time) {
-               ret = -1;
-               goto end;
-       }
-
-
-       if (!clock->has_value) {
-               /*
-                * Clock belongs to a non-writer mode trace and thus
-                * this function is disabled.
-                */
-               goto end;
-       }
-
-       *time = (int64_t) ns_from_value(clock->frequency, clock->value);
-
-end:
-       return ret;
-}
-
 int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time)
 {
        int ret = 0;
@@ -389,52 +365,8 @@ int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, int64_t time)
                        (double) clock->frequency) / 1e9);
        }
 
-       ret = bt_ctf_clock_set_value(clock, value);
-end:
-       return ret;
-}
-
-uint64_t bt_ctf_clock_get_value(struct bt_ctf_clock *clock)
-{
-       uint64_t ret = -1ULL;
-
-       if (!clock) {
-               goto end;
-       }
-
-       if (!clock->has_value) {
-               /*
-                * Clock belongs to a non-writer mode trace and thus
-                * this function is disabled.
-                */
-               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;
-
-       if (!clock) {
-               ret = -1;
-               goto end;
-       }
-
-       if (!clock->has_value) {
-               /*
-                * Clock belongs to a non-writer mode trace and thus
-                * this function is disabled.
-                */
-               ret = -1;
-               goto end;
-       }
-
-       /* Timestamps are strictly monotonic */
-       if (value < clock->value) {
+       if (clock->value > value) {
+               /* Timestamps must be strictly monotonic. */
                ret = -1;
                goto end;
        }
@@ -519,23 +451,78 @@ void bt_ctf_clock_destroy(struct bt_object *obj)
        g_free(clock);
 }
 
-int64_t bt_ctf_clock_ns_from_value(struct bt_ctf_clock *clock, uint64_t value)
+static
+void bt_ctf_clock_value_destroy(struct bt_object *obj)
+{
+       struct bt_ctf_clock_value *value;
+
+       if (!obj) {
+               return;
+       }
+
+       value = container_of(obj, struct bt_ctf_clock_value, base);
+       bt_put(value->clock_class);
+       g_free(value);
+}
+
+struct bt_ctf_clock_value *bt_ctf_clock_value_create(
+               struct bt_ctf_clock *clock, uint64_t value)
 {
-       int64_t ns = -1ULL;
+       struct bt_ctf_clock_value *ret = NULL;
 
        if (!clock) {
                goto end;
        }
 
-       /* Initialize nanosecond timestamp to clock's offset in seconds */
-       ns = clock->offset_s * 1000000000;
+       ret = g_new0(struct bt_ctf_clock_value, 1);
+       if (!ret) {
+               goto end;
+       }
+
+       bt_object_init(ret, bt_ctf_clock_value_destroy);
+       ret->clock_class = bt_get(clock);
+       ret->value = value;
+end:
+       return ret;
+}
 
-       /* Add offset in cycles, converted to nanoseconds */
-       ns += ns_from_value(clock->frequency, clock->offset);
+int bt_ctf_clock_value_get_value(
+               struct bt_ctf_clock_value *clock_value, uint64_t *raw_value)
+{
+       int ret = 0;
 
-       /* Add given value, converter to nanoseconds */
-       ns += ns_from_value(clock->frequency, value);
+       if (!clock_value || !raw_value) {
+               ret = -1;
+               goto end;
+       }
 
+       *raw_value = clock_value->value;
 end:
-       return ns;
+       return ret;
+}
+
+int bt_ctf_clock_value_ns_from_epoch(struct bt_ctf_clock_value *value,
+               int64_t *ret_value_ns)
+{
+       int ret = 0;
+       int64_t ns;
+
+       if (!value || !ret_value_ns) {
+               ret = -1;
+               goto end;
+       }
+
+       /* Initialize nanosecond timestamp to clock's offset in seconds. */
+       ns = value->clock_class->offset_s * 1000000000;
+
+       /* Add offset in cycles, converted to nanoseconds. */
+       ns += ns_from_value(value->clock_class->frequency,
+                       value->clock_class->offset);
+
+       /* Add given value, converter to nanoseconds. */
+       ns += ns_from_value(value->clock_class->frequency, value->value);
+
+       *ret_value_ns = ns;
+end:
+       return ret;
 }
index 505aa1049e24a473bf19c98ed70702f69aacfe51..beac9d489ca3f895938c977c730018471c81d3b8 100644 (file)
@@ -762,13 +762,16 @@ int bt_ctf_event_populate_event_header(struct bt_ctf_event *event)
                        timestamp_field_type);
                bt_put(timestamp_field_type);
                if (mapped_clock) {
-                       int64_t timestamp;
+                       int64_t timestamp = 0;
 
+                       // FIXME - Clock refactoring
+                       /*
                        ret = bt_ctf_clock_get_time(mapped_clock, &timestamp);
                        bt_put(mapped_clock);
                        if (ret) {
                                goto end;
                        }
+                       */
 
                        ret = set_integer_field_value(timestamp_field,
                                timestamp);
index ac13a8e3fc42713053218041d6bb56689ddd3454..0ed43ae991e9e85abdf4a4a5b434bbf4862e0ecb 100644 (file)
@@ -63,6 +63,12 @@ struct bt_ctf_clock {
        int frozen;
 };
 
+struct bt_ctf_clock_value {
+       struct bt_object base;
+       struct bt_ctf_clock *clock_class;
+       uint64_t value;
+};
+
 BT_HIDDEN
 void bt_ctf_clock_freeze(struct bt_ctf_clock *clock);
 
index 03f335fb836719a015b02ae04bbd9a49f91570f1..2bd1924bfe771408d2002ab077cb7e2c842e9878 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
 #endif
 
 struct bt_ctf_clock;
+struct bt_ctf_clock_value;
 
 /*
  * bt_ctf_clock_create: create a clock.
@@ -249,8 +250,14 @@ extern const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock);
 extern int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock,
                const unsigned char *uuid);
 
-extern int64_t bt_ctf_clock_ns_from_value(struct bt_ctf_clock *clock,
-               uint64_t value);
+extern struct bt_ctf_clock_value *bt_ctf_clock_value_create(
+               struct bt_ctf_clock *clock, uint64_t value);
+
+extern int bt_ctf_clock_value_get_value(
+               struct bt_ctf_clock_value *clock_value, uint64_t *raw_value);
+
+extern int bt_ctf_clock_value_get_value_ns_from_epoch(
+               struct bt_ctf_clock_value, int64_t *value_ns);
 
 #ifdef __cplusplus
 }
index 1bacc34e2aa14a57894b5a49f2fd3e9c566cda54..7ee14c652fe589101018fa1e6a34507a218ebfa8 100644 (file)
@@ -36,8 +36,6 @@
 extern "C" {
 #endif
 
-extern int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time);
-
 /*
  * bt_ctf_clock_set_time: set a clock's current time value.
  *
@@ -49,11 +47,6 @@ extern int bt_ctf_clock_get_time(struct bt_ctf_clock *clock, int64_t *time);
 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
index 5d0816b136675592efb6888a7cdd45d5e9123258..809af51c4dc20de9bef28f71e025d3cafb0f3f6d 100644 (file)
@@ -519,9 +519,6 @@ static void create_user_full(struct user *user)
        assert(clock);
        ret = bt_ctf_stream_class_set_clock(user->sc, clock);
        assert(!ret);
-       ret = bt_ctf_clock_set_value(clock, 23);
-       assert(!ret);
-       BT_PUT(clock);
        user->stream = bt_ctf_writer_create_stream(user->writer, user->sc);
        assert(user->stream);
        user->ec = bt_ctf_event_class_create("ec");
index 38bd3b714fecb8f6cd198df3dbf93f8cdc6a3e49..c72e1d3aea720cae44f3448f5f69ed7b017ff182 100644 (file)
@@ -59,7 +59,7 @@
 #define DEFAULT_CLOCK_TIME 0
 #define DEFAULT_CLOCK_VALUE 0
 
-#define NR_TESTS 620
+#define NR_TESTS 604
 
 static int64_t current_time = 42;
 
@@ -2789,24 +2789,6 @@ void test_create_writer_vs_non_writer_mode(void)
        ok(!bt_ctf_stream_append_event(writer_stream, event),
                "bt_ctf_stream_append_event() succeeds with a writer stream");
 
-       /*
-        * Verify that it's possible to get and set the value of a
-        * writer mode clock.
-        */
-       ok (!bt_ctf_clock_set_value(writer_clock, 1000),
-               "bt_ctf_clock_set_value() succeeds with a writer mode clock");
-       ok (bt_ctf_clock_get_value(writer_clock) == 1000,
-               "bt_ctf_clock_get_value() succeeds with a writer mode clock");
-
-       /*
-        * Verify that it's impossible to get and set the value of a
-        * non-writer mode clock.
-        */
-       ok (bt_ctf_clock_set_value(non_writer_clock, 1000),
-               "bt_ctf_clock_set_value() fails with a non-writer mode clock");
-       ok (bt_ctf_clock_get_value(non_writer_clock) == -1ULL,
-               "bt_ctf_clock_get_value() fails with a non-writer mode clock");
-
        /*
         * It should be possible to create a packet from a non-writer
         * stream, but not from a writer stream.
@@ -2912,13 +2894,8 @@ void test_clock_utils(void)
        assert(!ret);
        ret = bt_ctf_clock_set_frequency(clock, 1000000000);
        assert(!ret);
-       ok(bt_ctf_clock_ns_from_value(clock, 4321) == 1234000005321ULL,
-               "bt_ctf_clock_ns_from_value() returns the correct value with a 1 GHz frequency");
        ret = bt_ctf_clock_set_frequency(clock, 1534);
        assert(!ret);
-       ok(bt_ctf_clock_ns_from_value(clock, 4321) ==
-               (uint64_t) 1237468709256.845,
-               "bt_ctf_clock_ns_from_value() returns the correct value with a non-1 GHz frequency");
 
        BT_PUT(clock);
 }
@@ -2935,8 +2912,7 @@ int main(int argc, char **argv)
        const int64_t offset_s = 1351530929945824323;
        const int64_t offset = 1234567;
        int64_t get_offset_s,
-               get_offset,
-               get_time;
+               get_offset;
        const uint64_t precision = 10;
        const int is_absolute = 0xFF;
        char *metadata_string;
@@ -3212,22 +3188,8 @@ int main(int argc, char **argv)
        ok(bt_ctf_clock_get_is_absolute(clock) == !!is_absolute,
                "bt_ctf_clock_get_precision returns the correct is_absolute attribute once it is set");
 
-       ok(bt_ctf_clock_get_time(clock, &get_time) == 0,
-               "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 - 1 && get_time <= current_time + 1,
-               "bt_ctf_clock_get_time returns the correct time once it is set");
 
        ok(!bt_ctf_clock_get_name(NULL),
                "bt_ctf_clock_get_name correctly handles NULL");
@@ -3247,10 +3209,6 @@ int main(int argc, char **argv)
                "bt_ctf_clock_get_offset correctly handles NULL output");
        ok(bt_ctf_clock_get_is_absolute(NULL) < 0,
                "bt_ctf_clock_get_is_absolute correctly handles NULL");
-       ok(bt_ctf_clock_get_time(NULL, &get_time) < 0,
-               "bt_ctf_clock_get_time correctly handles NULL clock");
-       ok(bt_ctf_clock_get_time(clock, NULL) < 0,
-               "bt_ctf_clock_get_time correctly handles NULL output");
 
        ok(bt_ctf_clock_set_description(NULL, NULL) < 0,
                "bt_ctf_clock_set_description correctly handles NULL clock");
This page took 0.03016 seconds and 4 git commands to generate.