bt_clock_class_create(): accept mandatory trace class
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 10 Dec 2018 16:13:21 +0000 (11:13 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
This patch makes bt_clock_class_create() accept a mandatory trace class
parameter. This parameter is not used for the moment, but it could serve
in the future to control allocation (for example, object pooling),
bookkeeping, and validation.

I'm adding a public bt_util_clock_cycles_to_ns_from_origin() function to
get the nanoseconds from an origin using custom offsets and frequency.
This is the equivalent of bt_clock_class_cycles_to_ns_from_origin(), but
you don't need a clock class object, just its properties.

The `ctf` plugin is updated so that its CTF IR API has a
`struct ctf_clock_class`. `bt_clock_class` was the only remaining trace
IR object that was used as is, but it's not possible anymore because a
CTF IR metadata tree can exist without a trace IR trace class, and you
need a trace IR trace class to create a trace IR clock class. The
bt_clock_class_cycles_to_ns_from_origin() calls are replaced with
bt_util_clock_cycles_to_ns_from_origin() calls, passing the raw CTF IR
clock class properties.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
16 files changed:
include/Makefile.am
include/babeltrace/babeltrace.h
include/babeltrace/trace-ir/clock-class.h
include/babeltrace/trace-ir/clock-snapshot-internal.h
include/babeltrace/trace-ir/utils-internal.h
include/babeltrace/util.h [new file with mode: 0644]
lib/Makefile.am
lib/trace-ir/clock-class.c
lib/util.c [new file with mode: 0644]
plugins/ctf/common/metadata/ctf-meta-translate.c
plugins/ctf/common/metadata/ctf-meta-update-default-clock-classes.c
plugins/ctf/common/metadata/ctf-meta.h
plugins/ctf/common/metadata/visitor-generate-ir.c
plugins/ctf/fs-src/data-stream-file.c
plugins/ctf/fs-src/fs.c
plugins/text/dmesg/dmesg.c

index 96d41927aef9a5716f6bed4226a0ca0247fab4d1..4474d914ed966e0a2c255a125edbfa03e40cc736 100644 (file)
@@ -75,6 +75,7 @@ babeltraceinclude_HEADERS = \
        babeltrace/logging.h \
        babeltrace/property.h \
        babeltrace/types.h \
+       babeltrace/util.h \
        babeltrace/value-const.h \
        babeltrace/value.h \
        babeltrace/version.h
index 10595c2919f48e93f888fc0b96d85980d65dd290..2930140ac886df9961312b176f8de187d16aa196 100644 (file)
@@ -29,6 +29,7 @@
 #include <babeltrace/logging.h>
 #include <babeltrace/property.h>
 #include <babeltrace/types.h>
+#include <babeltrace/util.h>
 #include <babeltrace/value-const.h>
 #include <babeltrace/value.h>
 #include <babeltrace/version.h>
index c2bc7fde7299331a1ff0ad8f9184887cf9763890..d5c67742d7331debbe17738ab844b3852f9af515 100644 (file)
@@ -29,7 +29,7 @@
 
 #include <stdint.h>
 
-/* For bt_bool, bt_uuid, bt_clock_class */
+/* For bt_bool, bt_uuid, bt_clock_class, bt_trace_class */
 #include <babeltrace/types.h>
 
 /* For bt_clock_class_status */
@@ -39,7 +39,7 @@
 extern "C" {
 #endif
 
-extern bt_clock_class *bt_clock_class_create(void);
+extern bt_clock_class *bt_clock_class_create(bt_trace_class *trace_class);
 
 extern bt_clock_class_status bt_clock_class_set_name(
                bt_clock_class *clock_class, const char *name);
index 3ba604eee30ea58b04aa1b80b36832afe073b83b..8b7f75a601508ea19e21af861eb437106e0a724c 100644 (file)
@@ -58,11 +58,11 @@ void bt_clock_snapshot_reset(struct bt_clock_snapshot *clock_snapshot)
 static inline
 void set_ns_from_origin(struct bt_clock_snapshot *clock_snapshot)
 {
-       if (bt_util_ns_from_origin(clock_snapshot->clock_class, clock_snapshot->value_cycles,
+       if (bt_util_ns_from_origin_clock_class(clock_snapshot->clock_class,
+                       clock_snapshot->value_cycles,
                        &clock_snapshot->ns_from_origin)) {
                clock_snapshot->ns_from_origin_overflows = true;
        }
-
 }
 
 static inline
index 53de58fc85f9224bd90d4ac76d4b0174b9c954f0..2356d6ab6ba0db810ac9cb50537859277de4dbc8 100644 (file)
@@ -55,23 +55,56 @@ uint64_t bt_util_ns_from_value(uint64_t frequency, uint64_t value_cycles)
 }
 
 static inline
-int bt_util_ns_from_origin(const struct bt_clock_class *clock_class,
-               uint64_t value, int64_t *ns_from_origin)
+bool bt_util_get_base_offset_ns(int64_t offset_seconds, uint64_t offset_cycles,
+               uint64_t frequency, int64_t *base_offset_ns)
 {
-       int ret = 0;
-       uint64_t value_ns_unsigned;
-       int64_t value_ns_signed;
+       bool overflows = false;
+       uint64_t offset_cycles_ns;
 
-       if (clock_class->base_offset.overflows) {
-               ret = -1;
+       BT_ASSERT(base_offset_ns);
+
+       /* Initialize nanosecond timestamp to clock's offset in seconds */
+       if (offset_seconds <= (INT64_MIN / INT64_C(1000000000) - 1) ||
+                       offset_seconds >= (INT64_MAX / INT64_C(1000000000)) - 1) {
+               /*
+                * Overflow: offset in seconds converted to nanoseconds
+                * is outside the int64_t range. We also subtract 1 here
+                * to leave "space" for the offset in cycles converted
+                * to nanoseconds (which is always less than 1 second by
+                * contract).
+                */
+               overflows = true;
                goto end;
        }
 
+       /* Offset (seconds) to nanoseconds */
+       *base_offset_ns = offset_seconds * INT64_C(1000000000);
+
+       /* Add offset in cycles */
+       BT_ASSERT(offset_cycles < frequency);
+       offset_cycles_ns = bt_util_ns_from_value(frequency,
+               offset_cycles);
+       BT_ASSERT(offset_cycles_ns < 1000000000);
+       *base_offset_ns += (int64_t) offset_cycles_ns;
+
+end:
+       return overflows;
+}
+
+static inline
+int bt_util_ns_from_origin_inline(int64_t base_offset_ns,
+               int64_t offset_seconds, uint64_t offset_cycles,
+               uint64_t frequency, uint64_t value, int64_t *ns_from_origin)
+{
+       int ret = 0;
+       uint64_t value_ns_unsigned;
+       int64_t value_ns_signed;
+
        /* Initialize to clock class's base offset */
-       *ns_from_origin = clock_class->base_offset.value_ns;
+       *ns_from_origin = base_offset_ns;
 
        /* Add given value in cycles */
-       value_ns_unsigned = bt_util_ns_from_value(clock_class->frequency, value);
+       value_ns_unsigned = bt_util_ns_from_value(frequency, value);
        if (value_ns_unsigned >= (uint64_t) INT64_MAX) {
                /*
                 * FIXME: `value_ns_unsigned` could be greater than
@@ -104,6 +137,25 @@ end:
        return ret;
 }
 
+static inline
+int bt_util_ns_from_origin_clock_class(const struct bt_clock_class *clock_class,
+               uint64_t value, int64_t *ns_from_origin)
+{
+       int ret = 0;
+
+       if (clock_class->base_offset.overflows) {
+               ret = -1;
+               goto end;
+       }
+
+       ret = bt_util_ns_from_origin_inline(clock_class->base_offset.value_ns,
+               clock_class->offset_seconds, clock_class->offset_cycles,
+               clock_class->frequency, value, ns_from_origin);
+
+end:
+       return ret;
+}
+
 static inline
 bool bt_util_value_is_in_range_signed(uint64_t size, int64_t value)
 {
diff --git a/include/babeltrace/util.h b/include/babeltrace/util.h
new file mode 100644 (file)
index 0000000..2ac4684
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef BABELTRACE_UTIL_H
+#define BABELTRACE_UTIL_H
+
+/*
+ * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum bt_util_status {
+       BT_UTIL_STATUS_OK = 0,
+       BT_UTIL_STATUS_OVERFLOW = -75,
+} bt_util_status;
+
+bt_util_status bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles,
+               uint64_t frequency, int64_t offset_seconds,
+               uint64_t offset_cycles, int64_t *ns);
+
+#endif /* BABELTRACE_UTIL_H */
index 5665b0131095b8d238a41ab17abee8c9669e616d..6cafdebcdfa9520f984b26080b9c0289b97f18a5 100644 (file)
@@ -5,6 +5,7 @@ lib_LTLIBRARIES = libbabeltrace.la libbabeltrace-ctf.la
 libbabeltrace_la_SOURCES = \
        babeltrace.c \
        value.c \
+       util.c \
        lib-logging.c \
        logging.c \
        object-pool.c
index 273d8f58a544d39b788fb5f7e9750066091bc910..f21518e6c5061975516e2a27c8ab1ac50a067cd6 100644 (file)
@@ -74,43 +74,17 @@ void free_clock_snapshot(struct bt_clock_snapshot *clock_snapshot,
 static inline
 void set_base_offset(struct bt_clock_class *clock_class)
 {
-       uint64_t offset_cycles_ns;
-
-       /* Initialize nanosecond timestamp to clock's offset in seconds */
-       if (clock_class->offset_seconds <= (INT64_MIN / INT64_C(1000000000) - 1) ||
-                       clock_class->offset_seconds >= (INT64_MAX / INT64_C(1000000000)) - 1) {
-               /*
-                * Overflow: offset in seconds converted to nanoseconds
-                * is outside the int64_t range. We also subtract 1 here
-                * to leave "space" for the offset in cycles converted
-                * to nanoseconds (which is always less than 1 second by
-                * contract).
-                */
-               clock_class->base_offset.overflows = true;
-               goto end;
-       }
-
-       /* Offset (seconds) to nanoseconds */
-       clock_class->base_offset.value_ns = clock_class->offset_seconds *
-               INT64_C(1000000000);
-
-       /* Add offset in cycles */
-       BT_ASSERT(clock_class->offset_cycles < clock_class->frequency);
-       offset_cycles_ns = bt_util_ns_from_value(clock_class->frequency,
-               clock_class->offset_cycles);
-       BT_ASSERT(offset_cycles_ns < 1000000000);
-       clock_class->base_offset.value_ns += (int64_t) offset_cycles_ns;
-       clock_class->base_offset.overflows = false;
-
-end:
-       return;
+       clock_class->base_offset.overflows = bt_util_get_base_offset_ns(
+               clock_class->offset_seconds, clock_class->offset_cycles,
+               clock_class->frequency, &clock_class->base_offset.value_ns);
 }
 
-struct bt_clock_class *bt_clock_class_create(void)
+struct bt_clock_class *bt_clock_class_create(bt_trace_class *trace_class)
 {
        int ret;
        struct bt_clock_class *clock_class = NULL;
 
+       BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
        BT_LOGD_STR("Creating default clock class object");
 
        clock_class = g_new0(struct bt_clock_class, 1);
@@ -312,7 +286,7 @@ enum bt_clock_class_status bt_clock_class_cycles_to_ns_from_origin(
 
        BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
        BT_ASSERT_PRE_NON_NULL(ns, "Nanoseconds (output)");
-       ret = bt_util_ns_from_origin(clock_class, cycles, ns);
+       ret = bt_util_ns_from_origin_clock_class(clock_class, cycles, ns);
        if (ret) {
                ret = BT_CLOCK_CLASS_STATUS_OVERFLOW;
                BT_LIB_LOGW("Cannot convert cycles to nanoseconds "
diff --git a/lib/util.c b/lib/util.c
new file mode 100644 (file)
index 0000000..c8e9f30
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define BT_LOG_TAG "UTIL"
+#include <babeltrace/lib-logging-internal.h>
+
+#include <babeltrace/assert-pre-internal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string.h>
+#include <inttypes.h>
+#include <babeltrace/util.h>
+#include <babeltrace/trace-ir/utils-internal.h>
+
+bt_util_status bt_util_clock_cycles_to_ns_from_origin(uint64_t cycles,
+               uint64_t frequency, int64_t offset_seconds,
+               uint64_t offset_cycles, int64_t *ns)
+{
+       bool overflows;
+       int64_t base_offset_ns;
+       bt_util_status status = BT_UTIL_STATUS_OK;
+       int ret;
+
+       BT_ASSERT_PRE_NON_NULL(ns, "Nanoseconds (output)");
+       BT_ASSERT_PRE(frequency != UINT64_C(-1) && frequency != 0,
+               "Invalid frequency: freq=%" PRIu64, frequency);
+       BT_ASSERT_PRE(offset_cycles < frequency,
+               "Offset (cycles) is greater than frequency: "
+               "offset-cycles=%" PRIu64 ", freq=%" PRIu64,
+               offset_cycles, frequency);
+
+       overflows = bt_util_get_base_offset_ns(offset_seconds, offset_cycles,
+               frequency, &base_offset_ns);
+       if (overflows) {
+               status = BT_UTIL_STATUS_OVERFLOW;
+               goto end;
+       }
+
+       ret = bt_util_ns_from_origin_inline(base_offset_ns,
+               offset_seconds, offset_cycles,
+               frequency, cycles, ns);
+       if (ret) {
+               status = BT_UTIL_STATUS_OVERFLOW;
+       }
+
+end:
+       return status;
+}
index 516b499fa5c4ee3f886245363101ba62c84d8c52..e16f5be253843b8d6035dc76807f299f080f21d9 100644 (file)
@@ -514,8 +514,9 @@ bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
        bt_stream_class_set_assigns_automatic_stream_id(ir_sc, BT_FALSE);
 
        if (sc->default_clock_class) {
+               BT_ASSERT(sc->default_clock_class->ir_cc);
                ret = bt_stream_class_set_default_clock_class(ir_sc,
-                       sc->default_clock_class);
+                       sc->default_clock_class->ir_cc);
                BT_ASSERT(ret == 0);
        }
 
@@ -563,8 +564,33 @@ end:
 }
 
 static inline
-int ctf_trace_class_to_ir(bt_trace_class *ir_tc,
-               struct ctf_trace_class *tc)
+void ctf_clock_class_to_ir(bt_clock_class *ir_cc, struct ctf_clock_class *cc)
+{
+       int ret;
+
+       if (strlen(cc->name->str) > 0) {
+               ret = bt_clock_class_set_name(ir_cc, cc->name->str);
+               BT_ASSERT(ret == 0);
+       }
+
+       if (strlen(cc->description->str) > 0) {
+               ret = bt_clock_class_set_description(ir_cc, cc->description->str);
+               BT_ASSERT(ret == 0);
+       }
+
+       bt_clock_class_set_frequency(ir_cc, cc->frequency);
+       bt_clock_class_set_precision(ir_cc, cc->precision);
+       bt_clock_class_set_offset(ir_cc, cc->offset_seconds, cc->offset_cycles);
+
+       if (cc->has_uuid) {
+               bt_clock_class_set_uuid(ir_cc, cc->uuid);
+       }
+
+       bt_clock_class_set_is_absolute(ir_cc, cc->is_absolute);
+}
+
+static inline
+int ctf_trace_class_to_ir(bt_trace_class *ir_tc, struct ctf_trace_class *tc)
 {
        int ret = 0;
        uint64_t i;
@@ -613,6 +639,13 @@ int ctf_trace_class_to_ir(bt_trace_class *ir_tc,
                }
        }
 
+       for (i = 0; i < tc->clock_classes->len; i++) {
+               struct ctf_clock_class *cc = tc->clock_classes->pdata[i];
+
+               cc->ir_cc = bt_clock_class_create(ir_tc);
+               ctf_clock_class_to_ir(cc->ir_cc, cc);
+       }
+
        bt_trace_class_set_assigns_automatic_stream_class_id(ir_tc,
                BT_FALSE);
        tc->is_translated = true;
index 335f608accb8d72939d2ad3f9799b05e56ddecdb..398d977bda38300cd65821bfc45ef21453b0a86a 100644 (file)
@@ -27,7 +27,7 @@
 
 static inline
 int find_mapped_clock_class(struct ctf_field_class *fc,
-               bt_clock_class **clock_class)
+               struct ctf_clock_class **clock_class)
 {
        int ret = 0;
        uint64_t i;
@@ -48,8 +48,8 @@ int find_mapped_clock_class(struct ctf_field_class *fc,
                                BT_LOGE("Stream class contains more than one "
                                        "clock class: expected-cc-name=\"%s\", "
                                        "other-cc-name=\"%s\"",
-                                       bt_clock_class_get_name(*clock_class),
-                                       bt_clock_class_get_name(int_fc->mapped_clock_class));
+                                       (*clock_class)->name->str,
+                                       int_fc->mapped_clock_class->name->str);
                                ret = -1;
                                goto end;
                        }
@@ -120,7 +120,7 @@ int update_stream_class_default_clock_class(
                struct ctf_stream_class *stream_class)
 {
        int ret = 0;
-       bt_clock_class *clock_class =
+       struct ctf_clock_class *clock_class =
                stream_class->default_clock_class;
        uint64_t i;
 
@@ -161,7 +161,6 @@ int update_stream_class_default_clock_class(
 
        if (!stream_class->default_clock_class) {
                stream_class->default_clock_class = clock_class;
-               bt_clock_class_get_ref(stream_class->default_clock_class);
        }
 
 end:
@@ -173,10 +172,9 @@ int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class *ctf_tc)
 {
        uint64_t i;
        int ret = 0;
-       bt_clock_class *clock_class = NULL;
+       struct ctf_clock_class *clock_class = NULL;
 
-       ret = find_mapped_clock_class(ctf_tc->packet_header_fc,
-               &clock_class);
+       ret = find_mapped_clock_class(ctf_tc->packet_header_fc, &clock_class);
        if (ret) {
                goto end;
        }
index bca30c7aa7c47f64c6c6ec66d1643f3cbaf769de..0982cc404953bd3970c863490379c925069606a0 100644 (file)
@@ -59,6 +59,21 @@ enum ctf_encoding {
        CTF_ENCODING_UTF8,
 };
 
+struct ctf_clock_class {
+       GString *name;
+       GString *description;
+       uint64_t frequency;
+       uint64_t precision;
+       int64_t offset_seconds;
+       uint64_t offset_cycles;
+       uint8_t uuid[16];
+       bool has_uuid;
+       bool is_absolute;
+
+       /* Weak, set during translation */
+       bt_clock_class *ir_cc;
+};
+
 struct ctf_field_class {
        enum ctf_field_class_type type;
        unsigned int alignment;
@@ -83,8 +98,8 @@ struct ctf_field_class_int {
        enum ctf_encoding encoding;
        int64_t storing_index;
 
-       /* Owned by this */
-       bt_clock_class *mapped_clock_class;
+       /* Weak */
+       struct ctf_clock_class *mapped_clock_class;
 };
 
 struct ctf_range {
@@ -223,8 +238,8 @@ struct ctf_stream_class {
         */
        GHashTable *event_classes_by_id;
 
-       /* Owned by this */
-       bt_clock_class *default_clock_class;
+       /* Weak */
+       struct ctf_clock_class *default_clock_class;
 
        /* Weak, set during translation */
        bt_stream_class *ir_sc;
@@ -257,7 +272,7 @@ struct ctf_trace_class {
 
        uint64_t stored_value_count;
 
-       /* Array of `bt_clock_class *` (owned by this) */
+       /* Array of `struct ctf_clock_class *` (owned by this) */
        GPtrArray *clock_classes;
 
        /* Array of `struct ctf_stream_class *` */
@@ -471,7 +486,6 @@ static inline
 void _ctf_field_class_int_destroy(struct ctf_field_class_int *fc)
 {
        BT_ASSERT(fc);
-       bt_clock_class_put_ref(fc->mapped_clock_class);
        g_free(fc);
 }
 
@@ -479,7 +493,6 @@ static inline
 void _ctf_field_class_enum_destroy(struct ctf_field_class_enum *fc)
 {
        BT_ASSERT(fc);
-       bt_clock_class_put_ref(fc->base.mapped_clock_class);
 
        if (fc->mappings) {
                uint64_t i;
@@ -1108,7 +1121,6 @@ void ctf_field_class_int_copy_content(
        dst_fc->disp_base = src_fc->disp_base;
        dst_fc->encoding = src_fc->encoding;
        dst_fc->mapped_clock_class = src_fc->mapped_clock_class;
-       bt_clock_class_get_ref(dst_fc->mapped_clock_class);
        dst_fc->storing_index = src_fc->storing_index;
 }
 
@@ -1397,7 +1409,6 @@ void ctf_stream_class_destroy(struct ctf_stream_class *sc)
        ctf_field_class_destroy(sc->packet_context_fc);
        ctf_field_class_destroy(sc->event_header_fc);
        ctf_field_class_destroy(sc->event_common_context_fc);
-       bt_clock_class_put_ref(sc->default_clock_class);
        g_free(sc);
 }
 
@@ -1443,6 +1454,38 @@ void _ctf_trace_class_env_entry_fini(struct ctf_trace_class_env_entry *entry)
        }
 }
 
+static inline
+struct ctf_clock_class *ctf_clock_class_create(void)
+{
+       struct ctf_clock_class *cc = g_new0(struct ctf_clock_class, 1);
+
+       BT_ASSERT(cc);
+       cc->name = g_string_new(NULL);
+       BT_ASSERT(cc->name);
+       cc->description = g_string_new(NULL);
+       BT_ASSERT(cc->description);
+       return cc;
+}
+
+static inline
+void ctf_clock_class_destroy(struct ctf_clock_class *cc)
+{
+       if (!cc) {
+               return;
+       }
+
+       if (cc->name) {
+               g_string_free(cc->name, TRUE);
+       }
+
+       if (cc->description) {
+               g_string_free(cc->description, TRUE);
+       }
+
+       bt_clock_class_put_ref(cc->ir_cc);
+       g_free(cc);
+}
+
 static inline
 struct ctf_trace_class *ctf_trace_class_create(void)
 {
@@ -1451,7 +1494,7 @@ struct ctf_trace_class *ctf_trace_class_create(void)
        BT_ASSERT(tc);
        tc->default_byte_order = -1;
        tc->clock_classes = g_ptr_array_new_with_free_func(
-               (GDestroyNotify) bt_clock_class_put_ref);
+               (GDestroyNotify) ctf_clock_class_destroy);
        BT_ASSERT(tc->clock_classes);
        tc->stream_classes = g_ptr_array_new_with_free_func(
                (GDestroyNotify) ctf_stream_class_destroy);
@@ -1542,21 +1585,20 @@ end:
 }
 
 static inline
-bt_clock_class *ctf_trace_class_borrow_clock_class_by_name(
+struct ctf_clock_class *ctf_trace_class_borrow_clock_class_by_name(
                struct ctf_trace_class *tc, const char *name)
 {
        uint64_t i;
-       bt_clock_class *ret_cc = NULL;
+       struct ctf_clock_class *ret_cc = NULL;
 
        BT_ASSERT(tc);
        BT_ASSERT(name);
 
        for (i = 0; i < tc->clock_classes->len; i++) {
-               bt_clock_class *cc = tc->clock_classes->pdata[i];
-               const char *cc_name = bt_clock_class_get_name(cc);
+               struct ctf_clock_class *cc = tc->clock_classes->pdata[i];
 
-               BT_ASSERT(cc_name);
-               if (strcmp(cc_name, name) == 0) {
+               BT_ASSERT(cc->name);
+               if (strcmp(cc->name->str, name) == 0) {
                        ret_cc = cc;
                        goto end;
                }
index e009b4437aa0a40ec170e514e3b98f0a9e8540f0..27345fd287a63ff33d85987d0531f4d96ab7e656 100644 (file)
@@ -2353,7 +2353,7 @@ int visit_integer_decl(struct ctx *ctx,
        int signedness = 0;
        struct ctf_node *expression;
        uint64_t alignment = 0, size = 0;
-       bt_clock_class *mapped_clock_class = NULL;
+       struct ctf_clock_class *mapped_clock_class = NULL;
        enum ctf_encoding encoding = CTF_ENCODING_NONE;
        bt_field_class_integer_preferred_display_base base =
                BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
@@ -2708,7 +2708,6 @@ int visit_integer_decl(struct ctx *ctx,
        (*integer_decl)->disp_base = base;
        (*integer_decl)->encoding = encoding;
        (*integer_decl)->mapped_clock_class = mapped_clock_class;
-       bt_clock_class_get_ref((*integer_decl)->mapped_clock_class);
        return 0;
 
 error:
@@ -3565,7 +3564,7 @@ static
 int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                struct ctf_field_class *fc)
 {
-       bt_clock_class *clock_class_to_map_to = NULL;
+       struct ctf_clock_class *clock_class_to_map_to = NULL;
        struct ctf_field_class_int *int_fc = (void *) fc;
        int ret = 0;
        uint64_t clock_class_count;
@@ -3593,16 +3592,13 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                 * implicit one at 1 GHz, named `default`, and use this clock
                 * class.
                 */
-               clock_class_to_map_to = bt_clock_class_create();
+               clock_class_to_map_to = ctf_clock_class_create();
                BT_ASSERT(clock_class_to_map_to);
-               bt_clock_class_set_frequency(clock_class_to_map_to,
-                       UINT64_C(1000000000));
-               ret = bt_clock_class_set_name(clock_class_to_map_to,
-                       "default");
+               clock_class_to_map_to->frequency = UINT64_C(1000000000);
+               g_string_assign(clock_class_to_map_to->name, "default");
                BT_ASSERT(ret == 0);
                g_ptr_array_add(ctx->ctf_tc->clock_classes,
                        clock_class_to_map_to);
-               bt_clock_class_get_ref(clock_class_to_map_to);
                break;
        case 1:
                /*
@@ -3610,7 +3606,6 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                 * this one.
                 */
                clock_class_to_map_to = ctx->ctf_tc->clock_classes->pdata[0];
-               bt_clock_class_get_ref(clock_class_to_map_to);
                break;
        default:
                /*
@@ -3625,10 +3620,8 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
 
        BT_ASSERT(clock_class_to_map_to);
        int_fc->mapped_clock_class = clock_class_to_map_to;
-       bt_clock_class_get_ref(int_fc->mapped_clock_class);
 
 end:
-       bt_clock_class_put_ref(clock_class_to_map_to);
        return ret;
 }
 
@@ -4358,7 +4351,7 @@ error:
 
 static
 int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
-       bt_clock_class *clock, int *set, int64_t *offset_seconds,
+       struct ctf_clock_class *clock, int *set, int64_t *offset_seconds,
        uint64_t *offset_cycles)
 {
        int ret = 0;
@@ -4397,14 +4390,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               ret = bt_clock_class_set_name(clock, right);
-               if (ret) {
-                       _BT_LOGE_NODE(entry_node,
-                               "cannot set clock class's name");
-                       g_free(right);
-                       goto error;
-               }
-
+               g_string_assign(clock->name, right);
                g_free(right);
                _SET(set, _CLOCK_NAME_SET);
        } else if (!strcmp(left, "uuid")) {
@@ -4423,7 +4409,8 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               bt_clock_class_set_uuid(clock, uuid);
+               clock->has_uuid = true;
+               memcpy(&clock->uuid[0], uuid, 16);
                _SET(set, _CLOCK_UUID_SET);
        } else if (!strcmp(left, "description")) {
                char *right;
@@ -4444,14 +4431,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               ret = bt_clock_class_set_description(clock, right);
-               if (ret) {
-                       _BT_LOGE_NODE(entry_node,
-                               "Cannot set clock class's description.");
-                       g_free(right);
-                       goto error;
-               }
-
+               g_string_assign(clock->description, right);
                g_free(right);
                _SET(set, _CLOCK_DESCRIPTION_SET);
        } else if (!strcmp(left, "freq")) {
@@ -4480,7 +4460,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               bt_clock_class_set_frequency(clock, freq);
+               clock->frequency = freq;
                _SET(set, _CLOCK_FREQ_SET);
        } else if (!strcmp(left, "precision")) {
                uint64_t precision;
@@ -4501,7 +4481,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               bt_clock_class_set_precision(clock, precision);
+               clock->precision = precision;
                _SET(set, _CLOCK_PRECISION_SET);
        } else if (!strcmp(left, "offset_s")) {
                if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) {
@@ -4559,7 +4539,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               bt_clock_class_set_is_absolute(clock, ret);
+               clock->is_absolute = ret;
                _SET(set, _CLOCK_ABSOLUTE_SET);
        } else {
                _BT_LOGW_NODE(entry_node,
@@ -4605,7 +4585,7 @@ void calibrate_clock_class_offsets(int64_t *offset_seconds,
 
 static
 void apply_clock_class_offset(struct ctx *ctx,
-               bt_clock_class *clock)
+               struct ctf_clock_class *clock)
 {
        uint64_t freq;
        int64_t offset_s_to_apply = ctx->decoder_config.clock_class_offset_s;
@@ -4640,9 +4620,9 @@ void apply_clock_class_offset(struct ctx *ctx,
                offset_s_to_apply += extra_s;
        }
 
-       freq = bt_clock_class_get_frequency(clock);
-       bt_clock_class_get_offset(clock,
-                                 &cur_offset_s, &cur_offset_cycles);
+       freq = clock->frequency;
+       cur_offset_s = clock->offset_seconds;
+       cur_offset_cycles = clock->offset_cycles;
 
        /* Apply offsets */
        cur_offset_s += offset_s_to_apply;
@@ -4655,7 +4635,8 @@ void apply_clock_class_offset(struct ctx *ctx,
        calibrate_clock_class_offsets(&cur_offset_s, &cur_offset_cycles, freq);
 
        /* Set final offsets */
-       bt_clock_class_set_offset(clock, cur_offset_s, cur_offset_cycles);
+       clock->offset_seconds = cur_offset_s;
+       clock->offset_cycles = cur_offset_cycles;
 
 end:
        return;
@@ -4666,7 +4647,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
 {
        int ret = 0;
        int set = 0;
-       bt_clock_class *clock;
+       struct ctf_clock_class *clock;
        struct ctf_node *entry_node;
        struct bt_list_head *decl_list = &clock_node->u.clock.declaration_list;
        const char *clock_class_name;
@@ -4681,7 +4662,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
        clock_node->visited = TRUE;
 
        /* CTF 1.8's default frequency for a clock class is 1 GHz */
-       clock = bt_clock_class_create();
+       clock = ctf_clock_class_create();
        if (!clock) {
                _BT_LOGE_NODE(clock_node,
                        "Cannot create default clock class.");
@@ -4689,9 +4670,6 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                goto end;
        }
 
-       /* CTF: not absolute by default */
-       bt_clock_class_set_is_absolute(clock, BT_FALSE);
-
        bt_list_for_each_entry(entry_node, decl_list, siblings) {
                ret = visit_clock_decl_entry(ctx, entry_node, clock, &set,
                        &offset_seconds, &offset_cycles);
@@ -4710,7 +4688,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                goto end;
        }
 
-       clock_class_name = bt_clock_class_get_name(clock);
+       clock_class_name = clock->name->str;
        BT_ASSERT(clock_class_name);
        if (ctx->is_lttng && strcmp(clock_class_name, "monotonic") == 0) {
                /*
@@ -4719,23 +4697,27 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                 * it's a condition to be able to sort messages
                 * from different sources.
                 */
-               bt_clock_class_set_is_absolute(clock, BT_TRUE);
+               clock->is_absolute = true;
        }
 
        /*
         * Adjust offsets so that the part in cycles is less than the
         * frequency (move to the part in seconds).
         */
-       freq = bt_clock_class_get_frequency(clock);
+       freq = clock->frequency;
        calibrate_clock_class_offsets(&offset_seconds, &offset_cycles, freq);
-       BT_ASSERT(offset_cycles < bt_clock_class_get_frequency(clock));
-       bt_clock_class_set_offset(clock, offset_seconds, offset_cycles);
+       BT_ASSERT(offset_cycles < clock->frequency);
+       clock->offset_seconds = offset_seconds;
+       clock->offset_cycles = offset_cycles;
        apply_clock_class_offset(ctx, clock);
        g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);
-       bt_clock_class_get_ref(clock);
+       clock = NULL;
 
 end:
-       BT_CLOCK_CLASS_PUT_REF_AND_RESET(clock);
+       if (clock) {
+               ctf_clock_class_destroy(clock);
+       }
+
        return ret;
 }
 
index 517bfec6ade205f1bc1b8f8dcf3ffa9f28ebdfa1..2865f6020d9b2828a1a320f73ebd54bed164dc6b 100644 (file)
@@ -293,11 +293,12 @@ struct ctf_fs_ds_index_entry *ctf_fs_ds_index_add_new_entry(
 }
 
 static
-int convert_cycles_to_ns(bt_clock_class *clock_class,
+int convert_cycles_to_ns(struct ctf_clock_class *clock_class,
                uint64_t cycles, int64_t *ns)
 {
-       return bt_clock_class_cycles_to_ns_from_origin(clock_class, cycles,
-                                                      ns);
+       return bt_util_clock_cycles_to_ns_from_origin(cycles,
+                       clock_class->frequency, clock_class->offset_seconds,
+                       clock_class->offset_cycles, ns);
 }
 
 static
index daaae12e5a3a4ce1de501db31c5ce78362f15855..da242fd06a9631314b5adab3c35ed68ca63b7c40 100644 (file)
@@ -656,9 +656,11 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace,
 
        if (props.snapshots.beginning_clock != UINT64_C(-1)) {
                BT_ASSERT(sc->default_clock_class);
-               ret = bt_clock_class_cycles_to_ns_from_origin(
-                       sc->default_clock_class,
-                       props.snapshots.beginning_clock, &begin_ns);
+               ret = bt_util_clock_cycles_to_ns_from_origin(
+                       props.snapshots.beginning_clock,
+                       sc->default_clock_class->frequency,
+                       sc->default_clock_class->offset_seconds,
+                       sc->default_clock_class->offset_cycles, &begin_ns);
                if (ret) {
                        BT_LOGE("Cannot convert clock cycles to nanoseconds from origin (`%s`).",
                                path);
index 4a7876d7053fc3680001b0ef66fdaecbb591516f..332322b83e4f410be598444456e114d916bc914b 100644 (file)
@@ -137,7 +137,8 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts)
        }
 
        if (has_ts) {
-               dmesg_comp->clock_class = bt_clock_class_create();
+               dmesg_comp->clock_class = bt_clock_class_create(
+                       dmesg_comp->trace_class);
                if (!dmesg_comp->clock_class) {
                        BT_LOGE_STR("Cannot create clock class.");
                        goto error;
This page took 0.040065 seconds and 4 git commands to generate.