From 87d76bb1f3202bcdd577df14bbbf2231a26c244c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 16 Apr 2014 18:02:28 -0400 Subject: [PATCH] Implement CTF-IR Clock getters MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/clock.c | 125 ++++++++++++++++++--- include/babeltrace/ctf-ir/clock-internal.h | 3 - include/babeltrace/ctf-ir/clock.h | 97 +++++++++++++++- 3 files changed, 203 insertions(+), 22 deletions(-) diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index d8df956d..2860e010 100644 --- a/formats/ctf/ir/clock.c +++ b/formats/ctf/ir/clock.c @@ -53,11 +53,6 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name) goto error_destroy; } - clock->description = g_string_new(NULL); - if (!clock->description) { - goto error_destroy; - } - clock->precision = 1; clock->frequency = 1000000000; uuid_generate(clock->uuid); @@ -66,8 +61,38 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name) error_destroy: bt_ctf_clock_destroy(&clock->ref_count); error: - clock = NULL; - return clock; + return NULL; +} + +const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock) +{ + const char *ret = NULL; + + if (!clock) { + goto end; + } + + if (clock->name) { + ret = clock->name->str; + } + +end: + return ret; +} + +const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock) +{ + const char *ret = NULL; + + if (!clock) { + goto end; + } + + if (clock->description) { + ret = clock->description->str; + } +end: + return ret; } int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc) @@ -79,12 +104,25 @@ int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc) goto end; } - clock->description = g_string_assign(clock->description, desc); + clock->description = g_string_new(desc); ret = clock->description ? 0 : -1; end: return ret; } +uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock) +{ + uint64_t ret = -1ULL; + + if (!clock) { + goto end; + } + + ret = clock->frequency; +end: + return ret; +} + int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq) { int ret = 0; @@ -99,6 +137,19 @@ end: return ret; } +uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock) +{ + uint64_t ret = -1ULL; + + if (!clock) { + goto end; + } + + ret = clock->precision; +end: + return ret; +} + int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision) { int ret = 0; @@ -113,6 +164,19 @@ end: return ret; } +uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock) +{ + uint64_t ret = -1ULL; + + if (!clock) { + goto end; + } + + ret = clock->offset_s; +end: + return ret; +} + int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s) { int ret = 0; @@ -127,6 +191,19 @@ end: return ret; } +uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock) +{ + uint64_t ret = -1ULL; + + if (!clock) { + goto end; + } + + ret = clock->offset; +end: + return ret; +} + int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset) { int ret = 0; @@ -141,6 +218,19 @@ end: return ret; } +int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock) +{ + int ret = -1; + + if (!clock) { + goto end; + } + + ret = clock->absolute; +end: + return ret; +} + int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute) { int ret = 0; @@ -155,6 +245,19 @@ end: return ret; } +uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock) +{ + uint64_t ret = -1ULL; + + if (!clock) { + goto end; + } + + ret = clock->time; +end: + return ret; +} + int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time) { int ret = 0; @@ -236,12 +339,6 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, g_string_append(context->string, "};\n\n"); } -BT_HIDDEN -uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock) -{ - return clock ? clock->time : 0; -} - static void bt_ctf_clock_destroy(struct bt_ctf_ref *ref) { diff --git a/include/babeltrace/ctf-ir/clock-internal.h b/include/babeltrace/ctf-ir/clock-internal.h index fe945010..501f6247 100644 --- a/include/babeltrace/ctf-ir/clock-internal.h +++ b/include/babeltrace/ctf-ir/clock-internal.h @@ -59,7 +59,4 @@ BT_HIDDEN void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, struct metadata_context *context); -BT_HIDDEN -uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock); - #endif /* BABELTRACE_CTF_IR_CLOCK_INTERNAL_H */ diff --git a/include/babeltrace/ctf-ir/clock.h b/include/babeltrace/ctf-ir/clock.h index 8558afd3..fe6e9537 100644 --- a/include/babeltrace/ctf-ir/clock.h +++ b/include/babeltrace/ctf-ir/clock.h @@ -49,6 +49,28 @@ struct bt_ctf_clock; */ extern struct bt_ctf_clock *bt_ctf_clock_create(const char *name); +/* + * bt_ctf_clock_get_name: get a clock's name. + * + * Get the clock's name. + * + * @param clock Clock instance. + * + * Returns the clock's name, NULL on error. + */ +extern const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock); + +/* + * bt_ctf_clock_get_description: get a clock's description. + * + * Get the clock's description. + * + * @param clock Clock instance. + * + * Returns the clock's description, NULL if unset. + */ +extern const char *bt_ctf_clock_get_description(struct bt_ctf_clock *clock); + /* * bt_ctf_clock_set_description: set a clock's description. * @@ -63,6 +85,17 @@ extern struct bt_ctf_clock *bt_ctf_clock_create(const char *name); extern int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, const char *desc); +/* + * bt_ctf_clock_get_frequency: get a clock's frequency. + * + * Get the clock's frequency (Hz). + * + * @param clock Clock instance. + * + * Returns the clock's frequency, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_frequency(struct bt_ctf_clock *clock); + /* * bt_ctf_clock_set_frequency: set a clock's frequency. * @@ -76,6 +109,17 @@ extern int bt_ctf_clock_set_description(struct bt_ctf_clock *clock, extern int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, uint64_t freq); +/* + * bt_ctf_clock_get_precision: get a clock's precision. + * + * Get the clock's precision (in clock ticks). + * + * @param clock Clock instance. + * + * Returns the clock's precision, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_precision(struct bt_ctf_clock *clock); + /* * bt_ctf_clock_set_precision: set a clock's precision. * @@ -89,6 +133,17 @@ extern int bt_ctf_clock_set_frequency(struct bt_ctf_clock *clock, extern int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, uint64_t precision); +/* + * bt_ctf_clock_get_offset_s: get a clock's offset in seconds. + * + * Get the clock's offset in seconds from POSIX.1 Epoch, 1970-01-01. + * + * @param clock Clock instance. + * + * Returns the clock's offset in seconds, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_offset_s(struct bt_ctf_clock *clock); + /* * bt_ctf_clock_set_offset_s: set a clock's offset in seconds. * @@ -103,6 +158,16 @@ extern int bt_ctf_clock_set_precision(struct bt_ctf_clock *clock, extern int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, uint64_t offset_s); +/* + * bt_ctf_clock_get_offset_s: get a clock's offset in ticks. + * + * Get the clock's offset in ticks from Epoch + offset_t. + * + * @param clock Clock instance. + * + * Returns the clock's offset in ticks from Epoch + offset_s, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_offset(struct bt_ctf_clock *clock); /* * bt_ctf_clock_set_offset: set a clock's offset in ticks. @@ -117,11 +182,23 @@ extern int bt_ctf_clock_set_offset_s(struct bt_ctf_clock *clock, extern int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, uint64_t offset); +/* + * bt_ctf_clock_get_is_absolute: get a clock's absolute attribute. + * + * Get the clock's absolute attribute. A clock is absolute if the clock is a + * global reference across the trace's other clocks. + * + * @param clock Clock instance. + * + * Returns the clock's absolute attribute, a negative value on error. + */ +extern int bt_ctf_clock_get_is_absolute(struct bt_ctf_clock *clock); + /* * bt_ctf_clock_set_is_absolute: set a clock's absolute attribute. * - * A clock is absolute if the clock is a global reference across the trace's - * other clocks. + * Set the clock's absolute attribute. A clock is absolute if the clock is a + * global reference across the trace's other clocks. * * @param clock Clock instance. * @param is_absolute Clock's absolute attribute, defaults to FALSE. @@ -131,16 +208,26 @@ extern int bt_ctf_clock_set_offset(struct bt_ctf_clock *clock, extern int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute); +/* + * bt_ctf_clock_get_time: get a clock's current time value. + * + * Get the current time in nanoseconds since the clock's origin (offset and + * offset_s attributes). + * + * Returns the clock's current time value, -1ULL on error. + */ +extern uint64_t bt_ctf_clock_get_time(struct bt_ctf_clock *clock); + /* * bt_ctf_clock_set_time: set a clock's current time value. * * Set the current time in nanoseconds since the clock's origin (offset and - * offset_s attributes). The clock's value will be sampled as events are - * appended to a stream. + * offset_s attributes). Defaults to 0. * * Returns 0 on success, a negative value on error. */ -extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, uint64_t time); +extern int bt_ctf_clock_set_time(struct bt_ctf_clock *clock, + uint64_t time); /* * bt_ctf_clock_get and bt_ctf_clock_put: increment and decrement the -- 2.34.1