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;
(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;
}
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;
}
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, ×tamp);
bt_put(mapped_clock);
if (ret) {
goto end;
}
+ */
ret = set_integer_field_value(timestamp_field,
timestamp);
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);
#endif
struct bt_ctf_clock;
+struct bt_ctf_clock_value;
/*
* bt_ctf_clock_create: create a 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
}
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.
*
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
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");
#define DEFAULT_CLOCK_TIME 0
#define DEFAULT_CLOCK_VALUE 0
-#define NR_TESTS 620
+#define NR_TESTS 604
static int64_t current_time = 42;
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.
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);
}
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;
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");
"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");