lib: move trace class's name, UUID, and environment props to trace API
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 5 Jul 2019 19:11:11 +0000 (15:11 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 6 Jul 2019 10:13:20 +0000 (06:13 -0400)
This patch moves the name, UUID, and environment properties of the trace
class API to the trace API. The rationale behind this is that those
properties fundamentally belong to the instance of a trace class, not to
the class itself, as many traces with different names, UUIDs, and
environments can be created from a single trace class.

With this patch, a trace class becomes a simple container of stream
classes. Its name property is removed because it's not needed currently.

Specific, non-trivial changes:

`ctf` plugin:
    ctf_trace_class_translate() does not translate the UUID and
    environment anymore. Those properties are still part of a CTF IR
    trace class however. Instead, the new
    ctf_trace_class_configure_ir_trace() function can configure a trace
    IR trace object from the properties of a CTF IR trace class object.

    Both `src.ctf.fs` and `src.ctf.lttng-live` use
    ctf_trace_class_configure_ir_trace().

`sink.ctf.fs`:
    The private CTF IR trace class object is renamed to
    `fs_sink_ctf_trace` as it represents a single trace anyway.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Idaffd34c3ce28682b2c490588fccc963fcb1f3fa
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1640
Tested-by: jenkins <jenkins@lttng.org>
36 files changed:
include/babeltrace2/trace-ir/trace-class-const.h
include/babeltrace2/trace-ir/trace-class.h
include/babeltrace2/trace-ir/trace-const.h
include/babeltrace2/trace-ir/trace.h
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/trace.py
src/bindings/python/bt2/bt2/trace_class.py
src/lib/lib-logging.c
src/lib/trace-ir/trace-class.c
src/lib/trace-ir/trace-class.h
src/lib/trace-ir/trace.c
src/lib/trace-ir/trace.h
src/plugins/ctf/common/metadata/Makefile.am
src/plugins/ctf/common/metadata/ctf-meta-configure-ir-trace.c [new file with mode: 0644]
src/plugins/ctf/common/metadata/ctf-meta-configure-ir-trace.h [new file with mode: 0644]
src/plugins/ctf/common/metadata/ctf-meta-translate.c
src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-sink/fs-sink-trace.c
src/plugins/ctf/fs-sink/fs-sink-trace.h
src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c
src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.h
src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c
src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.h
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/fs-src/fs.h
src/plugins/ctf/lttng-live/metadata.c
src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c
src/plugins/text/details/details.c
src/plugins/text/details/details.h
src/plugins/text/details/write.c
src/plugins/text/pretty/print.c
tests/bindings/python/bt2/test_trace.py
tests/bindings/python/bt2/test_trace_class.py
tests/data/plugins/src.ctf.fs/succeed/trace-smalltrace.expect

index 1ceb6deb6330fa9be0ee5f09fdb3ecf7a192460d..6c6a9f4ac1371e53cfa8544fcf6b41e97fdd2460 100644 (file)
@@ -50,23 +50,6 @@ typedef void (* bt_trace_class_destruction_listener_func)(
 extern bt_bool bt_trace_class_assigns_automatic_stream_class_id(
                const bt_trace_class *trace_class);
 
-extern const char *bt_trace_class_get_name(
-               const bt_trace_class *trace_class);
-
-extern bt_uuid bt_trace_class_get_uuid(
-               const bt_trace_class *trace_class);
-
-extern uint64_t bt_trace_class_get_environment_entry_count(
-               const bt_trace_class *trace_class);
-
-extern void bt_trace_class_borrow_environment_entry_by_index_const(
-               const bt_trace_class *trace_class, uint64_t index,
-               const char **name, const bt_value **value);
-
-extern const bt_value *
-bt_trace_class_borrow_environment_entry_value_by_name_const(
-               const bt_trace_class *trace_class, const char *name);
-
 extern uint64_t bt_trace_class_get_stream_class_count(
                const bt_trace_class *trace_class);
 
index 1a32127ecbe290e610b815045b6f83a66d06224b..c4892130c15916a0d54853d63d6b63ad55ab3988 100644 (file)
 
 #include <stdint.h>
 
-/*
- * For bt_bool, bt_uuid, bt_trace_class, bt_stream_class,
- * bt_field_class, bt_self_component
- */
+/* For bt_bool, bt_trace_class, bt_stream_class, bt_self_component */
 #include <babeltrace2/types.h>
 
 /* For __BT_FUNC_STATUS_* */
@@ -49,32 +46,6 @@ extern bt_trace_class *bt_trace_class_create(bt_self_component *self_comp);
 extern void bt_trace_class_set_assigns_automatic_stream_class_id(
                bt_trace_class *trace_class, bt_bool value);
 
-typedef enum bt_trace_class_set_name_status {
-       BT_TRACE_CLASS_SET_NAME_STATUS_MEMORY_ERROR     = __BT_FUNC_STATUS_MEMORY_ERROR,
-       BT_TRACE_CLASS_SET_NAME_STATUS_OK               = __BT_FUNC_STATUS_OK,
-} bt_trace_class_set_name_status;
-
-extern bt_trace_class_set_name_status bt_trace_class_set_name(
-               bt_trace_class *trace_class, const char *name);
-
-extern void bt_trace_class_set_uuid(bt_trace_class *trace_class,
-               bt_uuid uuid);
-
-typedef enum bt_trace_class_set_environment_entry_status {
-       BT_TRACE_CLASS_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR        = __BT_FUNC_STATUS_MEMORY_ERROR,
-       BT_TRACE_CLASS_SET_ENVIRONMENT_ENTRY_STATUS_OK          = __BT_FUNC_STATUS_OK,
-} bt_trace_class_set_environment_entry_status;
-
-extern bt_trace_class_set_environment_entry_status
-bt_trace_class_set_environment_entry_integer(
-               bt_trace_class *trace_class,
-               const char *name, int64_t value);
-
-extern bt_trace_class_set_environment_entry_status
-bt_trace_class_set_environment_entry_string(
-               bt_trace_class *trace_class,
-               const char *name, const char *value);
-
 extern bt_stream_class *bt_trace_class_borrow_stream_class_by_index(
                bt_trace_class *trace_class, uint64_t index);
 
index a0ee825d6b791eee5254a69f1efa166169edf282..88ae1ecd7c82147190d4133b23d3e6bbb94a392e 100644 (file)
@@ -52,6 +52,17 @@ extern const bt_trace_class *bt_trace_borrow_class_const(
 
 extern const char *bt_trace_get_name(const bt_trace *trace);
 
+extern bt_uuid bt_trace_get_uuid(const bt_trace *trace);
+
+extern uint64_t bt_trace_get_environment_entry_count(const bt_trace *trace);
+
+extern void bt_trace_borrow_environment_entry_by_index_const(
+               const bt_trace *trace, uint64_t index,
+               const char **name, const bt_value **value);
+
+extern const bt_value *bt_trace_borrow_environment_entry_value_by_name_const(
+               const bt_trace *trace, const char *name);
+
 extern uint64_t bt_trace_get_stream_count(const bt_trace *trace);
 
 extern const bt_stream *bt_trace_borrow_stream_by_index_const(
index c759ca63f545b343cbe7a1552768471ffda21054..8335939f4dff85981f9df78339921a9a71569bcb 100644 (file)
@@ -29,7 +29,7 @@
 
 #include <stdint.h>
 
-/* For bt_bool, bt_trace, bt_trace_class, bt_stream */
+/* For bt_bool, bt_uuid, bt_trace, bt_trace_class, bt_stream */
 #include <babeltrace2/types.h>
 
 /* For __BT_FUNC_STATUS_* */
@@ -53,6 +53,21 @@ typedef enum bt_trace_set_name_status {
 extern bt_trace_set_name_status bt_trace_set_name(bt_trace *trace,
                const char *name);
 
+extern void bt_trace_set_uuid(bt_trace *trace, bt_uuid uuid);
+
+typedef enum bt_trace_set_environment_entry_status {
+       BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_MEMORY_ERROR      = __BT_FUNC_STATUS_MEMORY_ERROR,
+       BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK                = __BT_FUNC_STATUS_OK,
+} bt_trace_set_environment_entry_status;
+
+extern bt_trace_set_environment_entry_status
+bt_trace_set_environment_entry_integer(bt_trace *trace, const char *name,
+               int64_t value);
+
+extern bt_trace_set_environment_entry_status
+bt_trace_set_environment_entry_string(bt_trace *trace, const char *name,
+               const char *value);
+
 extern bt_stream *bt_trace_borrow_stream_by_index(bt_trace *trace,
                uint64_t index);
 
index 6d7fa3104dafa7d3da15295931374a693186ca0a..afd7514a7b856101f7361c05a3c42f12eeb58ffa 100644 (file)
@@ -606,8 +606,7 @@ class _UserComponent(metaclass=_UserComponentType):
     def _bt_graph_is_configured_from_native(self):
         self._graph_is_configured()
 
-    def _create_trace_class(self, env=None, uuid=None,
-                            assigns_automatic_stream_class_id=True):
+    def _create_trace_class(self, assigns_automatic_stream_class_id=True):
         ptr = self._bt_as_self_component_ptr(self._bt_ptr)
         tc_ptr = native_bt.trace_class_create(ptr)
 
@@ -615,14 +614,6 @@ class _UserComponent(metaclass=_UserComponentType):
             raise bt2.CreationError('could not create trace class')
 
         tc = bt2._TraceClass._create_from_ptr(tc_ptr)
-
-        if env is not None:
-            for key, value in env.items():
-                tc.env[key] = value
-
-        if uuid is not None:
-            tc._uuid = uuid
-
         tc._assigns_automatic_stream_class_id = assigns_automatic_stream_class_id
 
         return tc
index 9ab1a08021b3358e269e73af22ded62649703f8a..d7f03cb5d11e4f698d9c2bbe485ebd76c56ffaee 100644 (file)
@@ -28,6 +28,52 @@ import bt2.stream
 import bt2.trace_class
 import bt2
 import functools
+import uuid as uuidp
+
+
+class _TraceEnv(collections.abc.MutableMapping):
+    def __init__(self, trace):
+        self._trace = trace
+
+    def __getitem__(self, key):
+        utils._check_str(key)
+
+        borrow_entry_fn = native_bt.trace_borrow_environment_entry_value_by_name_const
+        value_ptr = borrow_entry_fn(self._trace._ptr, key)
+
+        if value_ptr is None:
+            raise KeyError(key)
+
+        return bt2.value._create_from_ptr_and_get_ref(value_ptr)
+
+    def __setitem__(self, key, value):
+        if isinstance(value, str):
+            set_env_entry_fn = native_bt.trace_set_environment_entry_string
+        elif isinstance(value, int):
+            set_env_entry_fn = native_bt.trace_set_environment_entry_integer
+        else:
+            raise TypeError('expected str or int, got {}'.format(type(value)))
+
+        status = set_env_entry_fn(self._trace._ptr, key, value)
+        utils._handle_func_status(status,
+                                  "cannot set trace object's environment entry")
+
+    def __delitem__(self, key):
+        raise NotImplementedError
+
+    def __len__(self):
+        count = native_bt.trace_get_environment_entry_count(self._trace._ptr)
+        assert count >= 0
+        return count
+
+    def __iter__(self):
+        trace_ptr = self._trace_env._trace._ptr
+
+        for idx in range(len(self)):
+            borrow_entry_fn = native_bt.trace_borrow_environment_entry_by_index_const
+            entry_name, _ = borrow_entry_fn(trace_ptr, idx)
+            assert entry_name is not None
+            yield entry_name
 
 
 def _trace_destruction_listener_from_native(user_listener, trace_ptr):
@@ -82,6 +128,24 @@ class _Trace(object._SharedObject, collections.abc.Mapping):
 
     _name = property(fset=_name)
 
+    @property
+    def uuid(self):
+        uuid_bytes = native_bt.trace_get_uuid(self._ptr)
+        if uuid_bytes is None:
+            return
+
+        return uuidp.UUID(bytes=uuid_bytes)
+
+    def _uuid(self, uuid):
+        utils._check_type(uuid, uuidp.UUID)
+        native_bt.trace_set_uuid(self._ptr, uuid.bytes)
+
+    _uuid = property(fset=_uuid)
+
+    @property
+    def env(self):
+        return _TraceEnv(self)
+
     def create_stream(self, stream_class, id=None, name=None):
         utils._check_type(stream_class, bt2.stream_class._StreamClass)
 
index 08d6cedc7d9758796f68105a7b8b57e0a410d935..76becf56c7effffefee7c08a49c359b4889a3977 100644 (file)
@@ -27,56 +27,10 @@ __all__ = ['_TraceClass']
 import bt2
 from bt2 import native_bt, utils, object
 import bt2.stream_class
-import uuid as uuidp
 import collections.abc
 import functools
 
 
-class _TraceClassEnv(collections.abc.MutableMapping):
-    def __init__(self, trace_class):
-        self._trace_class = trace_class
-
-    def __getitem__(self, key):
-        utils._check_str(key)
-
-        borrow_entry_fn = native_bt.trace_class_borrow_environment_entry_value_by_name_const
-        value_ptr = borrow_entry_fn(self._trace_class._ptr, key)
-
-        if value_ptr is None:
-            raise KeyError(key)
-
-        return bt2.value._create_from_ptr_and_get_ref(value_ptr)
-
-    def __setitem__(self, key, value):
-        if isinstance(value, str):
-            set_env_entry_fn = native_bt.trace_class_set_environment_entry_string
-        elif isinstance(value, int):
-            set_env_entry_fn = native_bt.trace_class_set_environment_entry_integer
-        else:
-            raise TypeError('expected str or int, got {}'.format(type(value)))
-
-        status = set_env_entry_fn(self._trace_class._ptr, key, value)
-        utils._handle_func_status(status,
-                                  "cannot set trace class object's environment entry")
-
-    def __delitem__(self, key):
-        raise NotImplementedError
-
-    def __len__(self):
-        count = native_bt.trace_class_get_environment_entry_count(self._trace_class._ptr)
-        assert count >= 0
-        return count
-
-    def __iter__(self):
-        trace_class_ptr = self._trace_class_env._trace_class._ptr
-
-        for idx in range(len(self)):
-            borrow_entry_fn = native_bt.trace_class_borrow_environment_entry_by_index_const
-            entry_name, _ = borrow_entry_fn(trace_class_ptr, idx)
-            assert entry_name is not None
-            yield entry_name
-
-
 class _StreamClassIterator(collections.abc.Iterator):
     def __init__(self, trace_class):
         self._trace_class = trace_class
@@ -104,23 +58,9 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping):
     _get_ref = staticmethod(native_bt.trace_class_get_ref)
     _put_ref = staticmethod(native_bt.trace_class_put_ref)
 
-    @property
-    def uuid(self):
-        uuid_bytes = native_bt.trace_class_get_uuid(self._ptr)
-        if uuid_bytes is None:
-            return
-
-        return uuidp.UUID(bytes=uuid_bytes)
-
-    def _uuid(self, uuid):
-        utils._check_type(uuid, uuidp.UUID)
-        native_bt.trace_class_set_uuid(self._ptr, uuid.bytes)
-
-    _uuid = property(fset=_uuid)
-
     # Instantiate a trace of this class.
 
-    def __call__(self, name=None):
+    def __call__(self, name=None, uuid=None, env=None):
         trace_ptr = native_bt.trace_create(self._ptr)
 
         if trace_ptr is None:
@@ -131,6 +71,13 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping):
         if name is not None:
             trace._name = name
 
+        if uuid is not None:
+            trace._uuid = uuid
+
+        if env is not None:
+            for key, value in env.items():
+                trace.env[key] = value
+
         return trace
 
     # Number of stream classes in this trace class.
@@ -161,10 +108,6 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping):
 
             yield id
 
-    @property
-    def env(self):
-        return _TraceClassEnv(self)
-
     def create_stream_class(self, id=None,
                             name=None,
                             packet_context_field_class=None,
index 66bfe9d31a91f229c48de2a047e7013ddaf45ddf..4c69d62f5b034cf778f0c0fb9bb91a6c6bb51310 100644 (file)
@@ -451,21 +451,12 @@ static inline void format_field_path(char **buf_ch, bool extended,
 static inline void format_trace_class(char **buf_ch, bool extended,
                const char *prefix, const struct bt_trace_class *trace_class)
 {
-       if (trace_class->name.value) {
-               BUF_APPEND(", %sname=\"%s\"",
-                       PRFIELD(trace_class->name.value));
-       }
-
        if (!extended) {
                return;
        }
 
        BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace_class->frozen));
 
-       if (trace_class->uuid.value) {
-               BUF_APPEND_UUID(trace_class->uuid.value);
-       }
-
        if (trace_class->stream_classes) {
                BUF_APPEND(", %sstream-class-count=%u",
                        PRFIELD(trace_class->stream_classes->len));
@@ -488,6 +479,10 @@ static inline void format_trace(char **buf_ch, bool extended,
                return;
        }
 
+       if (trace->uuid.value) {
+               BUF_APPEND_UUID(trace->uuid.value);
+       }
+
        BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen));
 
        if (trace->streams) {
index 1201534c919d4fd0cb74291879a140519c1c8435..9ad5849f78c5a0f7e93d89107eec8de5ab3e45c4 100644 (file)
@@ -43,7 +43,6 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include "attributes.h"
 #include "clock-class.h"
 #include "event-class.h"
 #include "event.h"
@@ -110,18 +109,6 @@ void destroy_trace_class(struct bt_object *obj)
                tc->destruction_listeners = NULL;
        }
 
-       if (tc->environment) {
-               BT_LOGD_STR("Destroying environment attributes.");
-               bt_attributes_destroy(tc->environment);
-               tc->environment = NULL;
-       }
-
-       if (tc->name.str) {
-               g_string_free(tc->name.str, TRUE);
-               tc->name.str = NULL;
-               tc->name.value = NULL;
-       }
-
        if (tc->stream_classes) {
                BT_LOGD_STR("Destroying stream classes.");
                g_ptr_array_free(tc->stream_classes, TRUE);
@@ -152,18 +139,6 @@ struct bt_trace_class *bt_trace_class_create(bt_self_component *self_comp)
                goto error;
        }
 
-       tc->name.str = g_string_new(NULL);
-       if (!tc->name.str) {
-               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
-               goto error;
-       }
-
-       tc->environment = bt_attributes_create();
-       if (!tc->environment) {
-               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty attributes object.");
-               goto error;
-       }
-
        tc->destruction_listeners = g_array_new(FALSE, TRUE,
                sizeof(struct bt_trace_class_destruction_listener_elem));
        if (!tc->destruction_listeners) {
@@ -182,40 +157,6 @@ end:
        return tc;
 }
 
-const char *bt_trace_class_get_name(const struct bt_trace_class *tc)
-{
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       return tc->name.value;
-}
-
-enum bt_trace_class_set_name_status bt_trace_class_set_name(
-               struct bt_trace_class *tc, const char *name)
-{
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       BT_ASSERT_PRE_NON_NULL(name, "Name");
-       BT_ASSERT_PRE_TRACE_CLASS_HOT(tc);
-       g_string_assign(tc->name.str, name);
-       tc->name.value = tc->name.str->str;
-       BT_LIB_LOGD("Set trace class's name: %!+T", tc);
-       return BT_FUNC_STATUS_OK;
-}
-
-bt_uuid bt_trace_class_get_uuid(const struct bt_trace_class *tc)
-{
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       return tc->uuid.value;
-}
-
-void bt_trace_class_set_uuid(struct bt_trace_class *tc, bt_uuid uuid)
-{
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       BT_ASSERT_PRE_NON_NULL(uuid, "UUID");
-       BT_ASSERT_PRE_TRACE_CLASS_HOT(tc);
-       memcpy(tc->uuid.uuid, uuid, BABELTRACE_UUID_LEN);
-       tc->uuid.value = tc->uuid.uuid;
-       BT_LIB_LOGD("Set trace class's UUID: %!+T", tc);
-}
-
 enum bt_trace_class_add_listener_status bt_trace_class_add_destruction_listener(
                const struct bt_trace_class *_tc,
                bt_trace_class_destruction_listener_func listener,
@@ -290,129 +231,6 @@ enum bt_trace_class_remove_listener_status bt_trace_class_remove_destruction_lis
        return BT_FUNC_STATUS_OK;
 }
 
-BT_ASSERT_FUNC
-static
-bool trace_has_environment_entry(const struct bt_trace_class *tc, const char *name)
-{
-       BT_ASSERT(tc);
-
-       return bt_attributes_borrow_field_value_by_name(
-               tc->environment, name) != NULL;
-}
-
-static
-enum bt_trace_class_set_environment_entry_status set_environment_entry(
-               struct bt_trace_class *tc,
-               const char *name, struct bt_value *value)
-{
-       int ret;
-
-       BT_ASSERT(tc);
-       BT_ASSERT(name);
-       BT_ASSERT(value);
-       BT_ASSERT_PRE(!tc->frozen ||
-               !trace_has_environment_entry(tc, name),
-               "Trace class is frozen: cannot replace environment entry: "
-               "%![tc-]+T, entry-name=\"%s\"", tc, name);
-       ret = bt_attributes_set_field_value(tc->environment, name,
-               value);
-       if (ret) {
-               ret = BT_FUNC_STATUS_MEMORY_ERROR;
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot set trace class's environment entry: "
-                       "%![tc-]+T, entry-name=\"%s\"", tc, name);
-       } else {
-               bt_value_freeze(value);
-               BT_LIB_LOGD("Set trace class's environment entry: "
-                       "%![tc-]+T, entry-name=\"%s\"", tc, name);
-       }
-
-       return ret;
-}
-
-enum bt_trace_class_set_environment_entry_status
-bt_trace_class_set_environment_entry_string(
-               struct bt_trace_class *tc, const char *name, const char *value)
-{
-       int ret;
-       struct bt_value *value_obj;
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       BT_ASSERT_PRE_NON_NULL(name, "Name");
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
-       value_obj = bt_value_string_create_init(value);
-       if (!value_obj) {
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot create a string value object.");
-               ret = -1;
-               goto end;
-       }
-
-       /* set_environment_entry() logs errors */
-       ret = set_environment_entry(tc, name, value_obj);
-
-end:
-       bt_object_put_ref(value_obj);
-       return ret;
-}
-
-enum bt_trace_class_set_environment_entry_status
-bt_trace_class_set_environment_entry_integer(
-               struct bt_trace_class *tc, const char *name, int64_t value)
-{
-       int ret;
-       struct bt_value *value_obj;
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       BT_ASSERT_PRE_NON_NULL(name, "Name");
-       value_obj = bt_value_signed_integer_create_init(value);
-       if (!value_obj) {
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot create an integer value object.");
-               ret = BT_FUNC_STATUS_MEMORY_ERROR;
-               goto end;
-       }
-
-       /* set_environment_entry() logs errors */
-       ret = set_environment_entry(tc, name, value_obj);
-
-end:
-       bt_object_put_ref(value_obj);
-       return ret;
-}
-
-uint64_t bt_trace_class_get_environment_entry_count(const struct bt_trace_class *tc)
-{
-       int64_t ret;
-
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       ret = bt_attributes_get_count(tc->environment);
-       BT_ASSERT(ret >= 0);
-       return (uint64_t) ret;
-}
-
-void bt_trace_class_borrow_environment_entry_by_index_const(
-               const struct bt_trace_class *tc, uint64_t index,
-               const char **name, const struct bt_value **value)
-{
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       BT_ASSERT_PRE_NON_NULL(name, "Name");
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
-       BT_ASSERT_PRE_VALID_INDEX(index,
-               bt_attributes_get_count(tc->environment));
-       *value = bt_attributes_borrow_field_value(tc->environment, index);
-       BT_ASSERT(*value);
-       *name = bt_attributes_get_field_name(tc->environment, index);
-       BT_ASSERT(*name);
-}
-
-const struct bt_value *bt_trace_class_borrow_environment_entry_value_by_name_const(
-               const struct bt_trace_class *tc, const char *name)
-{
-       BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
-       BT_ASSERT_PRE_NON_NULL(name, "Name");
-       return bt_attributes_borrow_field_value_by_name(tc->environment,
-               name);
-}
-
 uint64_t bt_trace_class_get_stream_class_count(const struct bt_trace_class *tc)
 {
        BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
index 09f1e7d497755347f32a3ce68e56b0e11c095043..589da127a315b5747e963f599e9fd6f3c54eb1c4 100644 (file)
 struct bt_trace_class {
        struct bt_object base;
 
-       struct {
-               GString *str;
-
-               /* NULL or `str->str` above */
-               const char *value;
-       } name;
-
-       struct {
-               uint8_t uuid[BABELTRACE_UUID_LEN];
-
-               /* NULL or `uuid` above */
-               bt_uuid value;
-       } uuid;
-
-       struct bt_value *environment;
-
        /* Array of `struct bt_stream_class *` */
        GPtrArray *stream_classes;
 
index b7fca04bc23705f3ce615e15d5e6a548baa6d2e8..ce76ce5e92d70d8e3c2e47384d923f1851b7a296 100644 (file)
@@ -118,6 +118,12 @@ void destroy_trace(struct bt_object *obj)
                trace->name.value = NULL;
        }
 
+       if (trace->environment) {
+               BT_LOGD_STR("Destroying environment attributes.");
+               bt_attributes_destroy(trace->environment);
+               trace->environment = NULL;
+       }
+
        if (trace->streams) {
                BT_LOGD_STR("Destroying streams.");
                g_ptr_array_free(trace->streams, TRUE);
@@ -167,6 +173,12 @@ struct bt_trace *bt_trace_create(struct bt_trace_class *tc)
                goto error;
        }
 
+       trace->environment = bt_attributes_create();
+       if (!trace->environment) {
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty attributes object.");
+               goto error;
+       }
+
        trace->destruction_listeners = g_array_new(FALSE, TRUE,
                sizeof(struct bt_trace_destruction_listener_elem));
        if (!trace->destruction_listeners) {
@@ -204,6 +216,145 @@ enum bt_trace_set_name_status bt_trace_set_name(struct bt_trace *trace,
        return BT_FUNC_STATUS_OK;
 }
 
+bt_uuid bt_trace_get_uuid(const struct bt_trace *trace)
+{
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       return trace->uuid.value;
+}
+
+void bt_trace_set_uuid(struct bt_trace *trace, bt_uuid uuid)
+{
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(uuid, "UUID");
+       BT_ASSERT_PRE_TRACE_HOT(trace);
+       memcpy(trace->uuid.uuid, uuid, BABELTRACE_UUID_LEN);
+       trace->uuid.value = trace->uuid.uuid;
+       BT_LIB_LOGD("Set trace's UUID: %!+t", trace);
+}
+
+BT_ASSERT_FUNC
+static
+bool trace_has_environment_entry(const struct bt_trace *trace, const char *name)
+{
+       BT_ASSERT(trace);
+
+       return bt_attributes_borrow_field_value_by_name(
+               trace->environment, name) != NULL;
+}
+
+static
+enum bt_trace_set_environment_entry_status set_environment_entry(
+               struct bt_trace *trace,
+               const char *name, struct bt_value *value)
+{
+       int ret;
+
+       BT_ASSERT(trace);
+       BT_ASSERT(name);
+       BT_ASSERT(value);
+       BT_ASSERT_PRE(!trace->frozen ||
+               !trace_has_environment_entry(trace, name),
+               "Trace is frozen: cannot replace environment entry: "
+               "%![trace-]+t, entry-name=\"%s\"", trace, name);
+       ret = bt_attributes_set_field_value(trace->environment, name,
+               value);
+       if (ret) {
+               ret = BT_FUNC_STATUS_MEMORY_ERROR;
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot set trace's environment entry: "
+                       "%![trace-]+t, entry-name=\"%s\"", trace, name);
+       } else {
+               bt_value_freeze(value);
+               BT_LIB_LOGD("Set trace's environment entry: "
+                       "%![trace-]+t, entry-name=\"%s\"", trace, name);
+       }
+
+       return ret;
+}
+
+enum bt_trace_set_environment_entry_status
+bt_trace_set_environment_entry_string(
+               struct bt_trace *trace, const char *name, const char *value)
+{
+       int ret;
+       struct bt_value *value_obj;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       value_obj = bt_value_string_create_init(value);
+       if (!value_obj) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create a string value object.");
+               ret = -1;
+               goto end;
+       }
+
+       /* set_environment_entry() logs errors */
+       ret = set_environment_entry(trace, name, value_obj);
+
+end:
+       bt_object_put_ref(value_obj);
+       return ret;
+}
+
+enum bt_trace_set_environment_entry_status
+bt_trace_set_environment_entry_integer(
+               struct bt_trace *trace, const char *name, int64_t value)
+{
+       int ret;
+       struct bt_value *value_obj;
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       value_obj = bt_value_signed_integer_create_init(value);
+       if (!value_obj) {
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create an integer value object.");
+               ret = BT_FUNC_STATUS_MEMORY_ERROR;
+               goto end;
+       }
+
+       /* set_environment_entry() logs errors */
+       ret = set_environment_entry(trace, name, value_obj);
+
+end:
+       bt_object_put_ref(value_obj);
+       return ret;
+}
+
+uint64_t bt_trace_get_environment_entry_count(const struct bt_trace *trace)
+{
+       int64_t ret;
+
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       ret = bt_attributes_get_count(trace->environment);
+       BT_ASSERT(ret >= 0);
+       return (uint64_t) ret;
+}
+
+void bt_trace_borrow_environment_entry_by_index_const(
+               const struct bt_trace *trace, uint64_t index,
+               const char **name, const struct bt_value **value)
+{
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_VALID_INDEX(index,
+               bt_attributes_get_count(trace->environment));
+       *value = bt_attributes_borrow_field_value(trace->environment, index);
+       BT_ASSERT(*value);
+       *name = bt_attributes_get_field_name(trace->environment, index);
+       BT_ASSERT(*name);
+}
+
+const struct bt_value *bt_trace_borrow_environment_entry_value_by_name_const(
+               const struct bt_trace *trace, const char *name)
+{
+       BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+       BT_ASSERT_PRE_NON_NULL(name, "Name");
+       return bt_attributes_borrow_field_value_by_name(trace->environment,
+               name);
+}
+
 uint64_t bt_trace_get_stream_count(const struct bt_trace *trace)
 {
        BT_ASSERT_PRE_NON_NULL(trace, "Trace");
index f10cdba9e50176ebe94f6fdc4e7088d25c7b954f..c5c244b58dcf29be9dbaf1a23a63e8c2ace57c46 100644 (file)
@@ -55,6 +55,15 @@ struct bt_trace {
                const char *value;
        } name;
 
+       struct {
+               uint8_t uuid[BABELTRACE_UUID_LEN];
+
+               /* NULL or `uuid` above */
+               bt_uuid value;
+       } uuid;
+
+       struct bt_value *environment;
+
        /* Array of `struct bt_stream *` */
        GPtrArray *streams;
 
index 0de440519329c2866d73d883138af55e42bfee98..2e1d4d0335b647e516f93ff5dfb7e4237f263a1e 100644 (file)
@@ -37,7 +37,9 @@ libctf_ast_la_SOURCES = \
        ctf-meta-update-stream-class-config.c \
        ctf-meta-warn-meaningless-header-fields.c \
        ctf-meta-translate.c \
-       ctf-meta-resolve.c
+       ctf-meta-resolve.c \
+       ctf-meta-configure-ir-trace.c \
+       ctf-meta-configure-ir-trace.h
 
 libctf_ast_la_LIBADD = $(UUID_LIBS)
 
diff --git a/src/plugins/ctf/common/metadata/ctf-meta-configure-ir-trace.c b/src/plugins/ctf/common/metadata/ctf-meta-configure-ir-trace.c
new file mode 100644 (file)
index 0000000..727a501
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2019 - 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.
+ */
+
+#include <babeltrace2/babeltrace.h>
+
+#include "ctf-meta-configure-ir-trace.h"
+
+BT_HIDDEN
+int ctf_trace_class_configure_ir_trace(struct ctf_trace_class *tc,
+               bt_trace *ir_trace)
+{
+       int ret = 0;
+       uint64_t i;
+
+       BT_ASSERT(tc);
+       BT_ASSERT(ir_trace);
+
+       if (tc->is_uuid_set) {
+               bt_trace_set_uuid(ir_trace, tc->uuid);
+       }
+
+       for (i = 0; i < tc->env_entries->len; i++) {
+               struct ctf_trace_class_env_entry *env_entry =
+                       ctf_trace_class_borrow_env_entry_by_index(tc, i);
+
+               switch (env_entry->type) {
+               case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT:
+                       ret = bt_trace_set_environment_entry_integer(
+                               ir_trace, env_entry->name->str,
+                               env_entry->value.i);
+                       break;
+               case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR:
+                       ret = bt_trace_set_environment_entry_string(
+                               ir_trace, env_entry->name->str,
+                               env_entry->value.str->str);
+                       break;
+               default:
+                       abort();
+               }
+
+               if (ret) {
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
diff --git a/src/plugins/ctf/common/metadata/ctf-meta-configure-ir-trace.h b/src/plugins/ctf/common/metadata/ctf-meta-configure-ir-trace.h
new file mode 100644 (file)
index 0000000..1430869
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef _CTF_META_CONFIGURE_IR_TRACE_H
+#define _CTF_META_CONFIGURE_IR_TRACE_H
+
+/*
+ * Copyright 2019 - 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.
+ */
+
+#include "common/macros.h"
+
+#include "ctf-meta.h"
+
+BT_HIDDEN
+int ctf_trace_class_configure_ir_trace(struct ctf_trace_class *tc,
+               bt_trace *ir_trace);
+
+#endif /* _CTF_META_CONFIGURE_IR_TRACE_H */
index 9f6b32e5d122af3d7e45ae367cbaf8f0811ce196..c9a720309cf64e51ef9218bd3c09ef87deb9a247 100644 (file)
@@ -540,34 +540,6 @@ int ctf_trace_class_to_ir(struct ctx *ctx)
                goto end;
        }
 
-       if (ctx->tc->is_uuid_set) {
-               bt_trace_class_set_uuid(ctx->ir_tc, ctx->tc->uuid);
-       }
-
-       for (i = 0; i < ctx->tc->env_entries->len; i++) {
-               struct ctf_trace_class_env_entry *env_entry =
-                       ctf_trace_class_borrow_env_entry_by_index(ctx->tc, i);
-
-               switch (env_entry->type) {
-               case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT:
-                       ret = bt_trace_class_set_environment_entry_integer(
-                               ctx->ir_tc, env_entry->name->str,
-                               env_entry->value.i);
-                       break;
-               case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR:
-                       ret = bt_trace_class_set_environment_entry_string(
-                               ctx->ir_tc, env_entry->name->str,
-                               env_entry->value.str->str);
-                       break;
-               default:
-                       abort();
-               }
-
-               if (ret) {
-                       goto end;
-               }
-       }
-
        for (i = 0; i < ctx->tc->clock_classes->len; i++) {
                struct ctf_clock_class *cc = ctx->tc->clock_classes->pdata[i];
 
index 6ae88dfb026e6546bf59bef9a89ad618e00141b4..7585ac745735c5f75a97aa1e9c76c4fd42405303 100644 (file)
@@ -120,11 +120,11 @@ struct fs_sink_ctf_event_class {
        struct fs_sink_ctf_field_class *payload_fc;
 };
 
-struct fs_sink_ctf_trace_class;
+struct fs_sink_ctf_trace;
 
 struct fs_sink_ctf_stream_class {
        /* Weak */
-       struct fs_sink_ctf_trace_class *tc;
+       struct fs_sink_ctf_trace *trace;
 
        /* Weak */
        const bt_stream_class *ir_sc;
@@ -155,7 +155,10 @@ struct fs_sink_ctf_stream_class {
        GHashTable *event_classes_from_ir;
 };
 
-struct fs_sink_ctf_trace_class {
+struct fs_sink_ctf_trace {
+       /* Weak */
+       const bt_trace *ir_trace;
+
        /* Weak */
        const bt_trace_class *ir_tc;
 
@@ -715,16 +718,16 @@ void fs_sink_ctf_event_class_destroy(struct fs_sink_ctf_event_class *ec)
 
 static inline
 struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create(
-               struct fs_sink_ctf_trace_class *tc,
+               struct fs_sink_ctf_trace *trace,
                const bt_stream_class *ir_sc)
 {
        struct fs_sink_ctf_stream_class *sc =
                g_new0(struct fs_sink_ctf_stream_class, 1);
 
-       BT_ASSERT(tc);
+       BT_ASSERT(trace);
        BT_ASSERT(ir_sc);
        BT_ASSERT(sc);
-       sc->tc = tc;
+       sc->trace = trace;
        sc->ir_sc = ir_sc;
        sc->default_clock_class =
                bt_stream_class_borrow_default_clock_class_const(ir_sc);
@@ -756,7 +759,7 @@ struct fs_sink_ctf_stream_class *fs_sink_ctf_stream_class_create(
                                ir_sc);
        }
 
-       g_ptr_array_add(tc->stream_classes, sc);
+       g_ptr_array_add(trace->stream_classes, sc);
        return sc;
 }
 
@@ -798,42 +801,42 @@ void fs_sink_ctf_stream_class_append_event_class(
 }
 
 static inline
-void fs_sink_ctf_trace_class_destroy(struct fs_sink_ctf_trace_class *tc)
+void fs_sink_ctf_trace_destroy(struct fs_sink_ctf_trace *trace)
 {
-       if (!tc) {
+       if (!trace) {
                return;
        }
 
-       if (tc->stream_classes) {
-               g_ptr_array_free(tc->stream_classes, TRUE);
-               tc->stream_classes = NULL;
+       if (trace->stream_classes) {
+               g_ptr_array_free(trace->stream_classes, TRUE);
+               trace->stream_classes = NULL;
        }
 
-       g_free(tc);
+       g_free(trace);
 }
 
 static inline
-struct fs_sink_ctf_trace_class *fs_sink_ctf_trace_class_create(
-               const bt_trace_class *ir_tc)
+struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
 {
-       struct fs_sink_ctf_trace_class *tc =
-               g_new0(struct fs_sink_ctf_trace_class, 1);
+       struct fs_sink_ctf_trace *trace =
+               g_new0(struct fs_sink_ctf_trace, 1);
 
-       BT_ASSERT(tc);
+       BT_ASSERT(trace);
 
-       if (bt_uuid_generate(tc->uuid)) {
-               fs_sink_ctf_trace_class_destroy(tc);
-               tc = NULL;
+       if (bt_uuid_generate(trace->uuid)) {
+               fs_sink_ctf_trace_destroy(trace);
+               trace = NULL;
                goto end;
        }
 
-       tc->ir_tc = ir_tc;
-       tc->stream_classes = g_ptr_array_new_with_free_func(
+       trace->ir_trace = ir_trace;
+       trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
+       trace->stream_classes = g_ptr_array_new_with_free_func(
                (GDestroyNotify) fs_sink_ctf_stream_class_destroy);
-       BT_ASSERT(tc->stream_classes);
+       BT_ASSERT(trace->stream_classes);
 
 end:
-       return tc;
+       return trace;
 }
 
 static inline
index 921dafa3020328c9bfdb418418603ec2cb59f6ef..d622a9c357ab64ea951025f224125f789e677e79 100644 (file)
@@ -165,7 +165,7 @@ struct fs_sink_stream *fs_sink_stream_create(struct fs_sink_trace *trace,
        stream->prev_packet_state.discarded_events_counter = UINT64_C(-1);
        stream->prev_packet_state.seq_num = UINT64_C(-1);
        ret = try_translate_stream_class_trace_ir_to_ctf_ir(trace->fs_sink,
-               trace->tc, bt_stream_borrow_class_const(ir_stream),
+               trace->trace, bt_stream_borrow_class_const(ir_stream),
                &stream->sc);
        if (ret) {
                goto error;
@@ -569,7 +569,7 @@ int fs_sink_stream_open_packet(struct fs_sink_stream *stream,
        /* Packet header: UUID */
        for (i = 0; i < BABELTRACE_UUID_LEN; i++) {
                ret = bt_ctfser_write_byte_aligned_unsigned_int(&stream->ctfser,
-                       (uint64_t) stream->sc->tc->uuid[i], 8, 8, BYTE_ORDER);
+                       (uint64_t) stream->sc->trace->uuid[i], 8, 8, BYTE_ORDER);
                if (ret) {
                        BT_COMP_LOGE("Error writing packet header UUID: stream-file-name=%s",
                                stream->file_name->str);
index 07d78f764b7e468730edd15853d6eed6a348f9c5..d97816df4320f7fe9b5f7d9d6160212b1e96bdc7 100644 (file)
@@ -164,12 +164,12 @@ end:
 
 static
 int append_lttng_trace_path_ust_uid(const struct fs_sink_trace *trace,
-               GString *path, const bt_trace_class *tc)
+               GString *path, const bt_trace *tc)
 {
        const bt_value *v;
        int ret;
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_id");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_id");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_buffering_id\"");
                goto error;
@@ -178,7 +178,7 @@ int append_lttng_trace_path_ust_uid(const struct fs_sink_trace *trace,
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64,
                bt_value_signed_integer_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "isa_length");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "isa_length");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"isa_length\"");
                goto error;
@@ -199,13 +199,13 @@ end:
 
 static
 int append_lttng_trace_path_ust_pid(const struct fs_sink_trace *trace,
-               GString *path, const bt_trace_class *tc)
+               GString *path, const bt_trace *tc)
 {
        const bt_value *v;
        const char *datetime;
        int ret;
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "procname");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "procname");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"procname\"");
                goto error;
@@ -213,7 +213,7 @@ int append_lttng_trace_path_ust_pid(const struct fs_sink_trace *trace,
 
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", bt_value_string_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "vpid");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"vpid\"");
                goto error;
@@ -221,7 +221,7 @@ int append_lttng_trace_path_ust_pid(const struct fs_sink_trace *trace,
 
        g_string_append_printf(path, "-%" PRId64, bt_value_signed_integer_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid_datetime");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(tc, "vpid_datetime");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"vpid_datetime\"");
                goto error;
@@ -252,7 +252,6 @@ end:
 static
 GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 {
-       const bt_trace_class *tc;
        const bt_value *v;
        const char *tracer_name, *domain, *datetime;
        int64_t tracer_major, tracer_minor;
@@ -263,9 +262,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                goto error;
        }
 
-       tc = bt_trace_borrow_class_const(trace->ir_trace);
-
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_name");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "tracer_name");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_name\"");
                goto error;
@@ -279,7 +277,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                goto error;
        }
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_major");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "tracer_major");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_major\"");
                goto error;
@@ -287,7 +286,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        tracer_major = bt_value_signed_integer_get(v);
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_minor");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "tracer_minor");
        if (!v || !bt_value_is_signed_integer(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_minor\"");
                goto error;
@@ -301,7 +301,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                goto error;
        }
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "hostname");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "hostname");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_hostname\"");
                goto error;
@@ -309,7 +310,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        g_string_assign(path, bt_value_string_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "trace_name");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "trace_name");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"trace_name\"");
                goto error;
@@ -317,7 +319,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", bt_value_string_get(v));
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "trace_creation_datetime");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "trace_creation_datetime");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"trace_creation_datetime\"");
                goto error;
@@ -331,7 +334,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
 
        g_string_append_printf(path, "-%s", datetime);
 
-       v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "domain");
+       v = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace->ir_trace, "domain");
        if (!v || !bt_value_is_string(v)) {
                BT_COMP_LOGI_STR("Couldn't get environment value: name=\"domain\"");
                goto error;
@@ -343,7 +347,8 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
        if (g_str_equal(domain, "ust")) {
                const char *tracer_buffering_scheme;
 
-               v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_scheme");
+               v = bt_trace_borrow_environment_entry_value_by_name_const(
+                       trace->ir_trace, "tracer_buffering_scheme");
                if (!v || !bt_value_is_string(v)) {
                        BT_COMP_LOGI_STR("Couldn't get environment value: name=\"tracer_buffering_scheme\"");
                        goto error;
@@ -353,11 +358,13 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
                g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", tracer_buffering_scheme);
 
                if (g_str_equal(tracer_buffering_scheme, "uid")) {
-                       if (append_lttng_trace_path_ust_uid(trace, path, tc)) {
+                       if (append_lttng_trace_path_ust_uid(trace, path,
+                                       trace->ir_trace)) {
                                goto error;
                        }
                } else if (g_str_equal(tracer_buffering_scheme, "pid")){
-                       if (append_lttng_trace_path_ust_pid(trace, path, tc)) {
+                       if (append_lttng_trace_path_ust_pid(trace, path,
+                                       trace->ir_trace)) {
                                goto error;
                        }
                } else {
@@ -493,7 +500,7 @@ void fs_sink_trace_destroy(struct fs_sink_trace *trace)
 
        tsdl = g_string_new(NULL);
        BT_ASSERT(tsdl);
-       translate_trace_class_ctf_ir_to_tsdl(trace->tc, tsdl);
+       translate_trace_ctf_ir_to_tsdl(trace->trace, tsdl);
 
        BT_ASSERT(trace->metadata_path);
        fh = fopen(trace->metadata_path->str, "wb");
@@ -524,8 +531,8 @@ void fs_sink_trace_destroy(struct fs_sink_trace *trace)
        g_string_free(trace->metadata_path, TRUE);
        trace->metadata_path = NULL;
 
-       fs_sink_ctf_trace_class_destroy(trace->tc);
-       trace->tc = NULL;
+       fs_sink_ctf_trace_destroy(trace->trace);
+       trace->trace = NULL;
        g_free(trace);
 
 end:
@@ -576,9 +583,8 @@ struct fs_sink_trace *fs_sink_trace_create(struct fs_sink_comp *fs_sink,
        trace->fs_sink = fs_sink;
        trace->ir_trace = ir_trace;
        trace->ir_trace_destruction_listener_id = UINT64_C(-1);
-       trace->tc = translate_trace_class_trace_ir_to_ctf_ir(
-               fs_sink, bt_trace_borrow_class_const(ir_trace));
-       if (!trace->tc) {
+       trace->trace = translate_trace_trace_ir_to_ctf_ir(fs_sink, ir_trace);
+       if (!trace->trace) {
                goto error;
        }
 
index 9ca03d1bcf11caecf4af41b43895fd580ef8c7c5..6b982fa38a409037f7f5935a107088d80d6cc6df 100644 (file)
@@ -39,14 +39,14 @@ struct fs_sink_trace {
        struct fs_sink_comp *fs_sink;
 
        /* Owned by this */
-       struct fs_sink_ctf_trace_class *tc;
+       struct fs_sink_ctf_trace *trace;
 
        /*
-        * Weak reference: this object does not own it, and `tc` above
-        * does not own its trace IR trace class either. Instead, we add
-        * a "trace destruction" listener (in create_trace()) so that
-        * this object gets destroyed when the trace object is
-        * destroyed.
+        * Weak reference: this object does not own it, and `trace`
+        * above does not own its trace IR trace and trace class either.
+        * Instead, we add a "trace destruction" listener (in
+        * create_trace()) so that this object gets destroyed when the
+        * trace object is destroyed.
         *
         * Otherwise (with a strong reference), we would keep this trace
         * object alive until the upstream message iterator ends. This
index 4c0653a988024f94d7e49c0a3bebc6b862968dfe..4fdd6241b13dfdec9816b49218232c75c33a9e18 100644 (file)
@@ -792,7 +792,7 @@ void append_stream_class(struct ctx *ctx,
 }
 
 BT_HIDDEN
-void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
+void translate_trace_ctf_ir_to_tsdl(struct fs_sink_ctf_trace *trace,
                GString *tsdl)
 {
        struct ctx ctx = {
@@ -817,7 +817,7 @@ void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
        g_string_append(tsdl, "minor = 8;\n");
        append_indent(&ctx);
        g_string_append(tsdl, "uuid = ");
-       append_uuid(&ctx, tc->uuid);
+       append_uuid(&ctx, trace->uuid);
        g_string_append(tsdl, ";\n");
        append_indent(&ctx);
        g_string_append(tsdl, "byte_order = ");
@@ -858,8 +858,8 @@ void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
        /* End trace class */
        append_end_block_semi_nl_nl(&ctx);
 
-       /* Trace class environment */
-       count = bt_trace_class_get_environment_entry_count(tc->ir_tc);
+       /* Trace environment */
+       count = bt_trace_get_environment_entry_count(trace->ir_trace);
        if (count > 0) {
                append_indent(&ctx);
                g_string_append(tsdl, "env {\n");
@@ -869,8 +869,8 @@ void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
                        const char *name;
                        const bt_value *val;
 
-                       bt_trace_class_borrow_environment_entry_by_index_const(
-                               tc->ir_tc, i, &name, &val);
+                       bt_trace_borrow_environment_entry_by_index_const(
+                               trace->ir_trace, i, &name, &val);
                        append_indent(&ctx);
                        g_string_append_printf(tsdl, "%s = ", name);
 
@@ -885,7 +885,7 @@ void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
                        default:
                                /*
                                 * This is checked in
-                                * translate_trace_class_trace_ir_to_ctf_ir().
+                                * translate_trace_trace_ir_to_ctf_ir().
                                 */
                                abort();
                        }
@@ -898,7 +898,7 @@ void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
        }
 
        /* Stream classes and their event classes */
-       for (i = 0; i < tc->stream_classes->len; i++) {
-               append_stream_class(&ctx, tc->stream_classes->pdata[i]);
+       for (i = 0; i < trace->stream_classes->len; i++) {
+               append_stream_class(&ctx, trace->stream_classes->pdata[i]);
        }
 }
index 8490629dea17f3b9fd6ae257b252ee4e79a35466..9c225805b2145b6fe57ef7740a6daa0ead19d5b5 100644 (file)
@@ -29,7 +29,7 @@
 #include "fs-sink-ctf-meta.h"
 
 BT_HIDDEN
-void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
+void translate_trace_ctf_ir_to_tsdl(struct fs_sink_ctf_trace *trace,
                GString *tsdl);
 
 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_TRANSLATE_CTF_IR_TO_TSDL_H */
index 4d6f572ac1760df430335f2270d82a6d2bac7051..1534c96cf2da7caf118ffc7f20f45297da821646 100644 (file)
@@ -1115,15 +1115,15 @@ end:
        return ret;
 }
 
-bool default_clock_class_name_exists(struct fs_sink_ctf_trace_class *tc,
+bool default_clock_class_name_exists(struct fs_sink_ctf_trace *trace,
                const char *name)
 {
        bool exists = false;
        uint64_t i;
 
-       for (i = 0; i < tc->stream_classes->len; i++) {
+       for (i = 0; i < trace->stream_classes->len; i++) {
                struct fs_sink_ctf_stream_class *sc =
-                       tc->stream_classes->pdata[i];
+                       trace->stream_classes->pdata[i];
 
                if (sc->default_clock_class_name->len == 0) {
                        /* No default clock class */
@@ -1149,7 +1149,7 @@ void make_unique_default_clock_class_name(struct fs_sink_ctf_stream_class *sc)
        g_string_assign(sc->default_clock_class_name, "");
        sprintf(buf, "default");
 
-       while (default_clock_class_name_exists(sc->tc, buf)) {
+       while (default_clock_class_name_exists(sc->trace, buf)) {
                sprintf(buf, "default%u", suffix);
                suffix++;
        }
@@ -1159,17 +1159,17 @@ void make_unique_default_clock_class_name(struct fs_sink_ctf_stream_class *sc)
 
 static
 int translate_stream_class(struct fs_sink_comp *fs_sink,
-               struct fs_sink_ctf_trace_class *tc,
+               struct fs_sink_ctf_trace *trace,
                const bt_stream_class *ir_sc,
                struct fs_sink_ctf_stream_class **out_sc)
 {
        int ret = 0;
        struct ctx ctx;
 
-       BT_ASSERT(tc);
+       BT_ASSERT(trace);
        BT_ASSERT(ir_sc);
        ctx_init(&ctx, fs_sink);
-       *out_sc = fs_sink_ctf_stream_class_create(tc, ir_sc);
+       *out_sc = fs_sink_ctf_stream_class_create(trace, ir_sc);
        BT_ASSERT(*out_sc);
 
        /* Set default clock class's protected name, if any */
@@ -1234,46 +1234,46 @@ end:
 BT_HIDDEN
 int try_translate_stream_class_trace_ir_to_ctf_ir(
                struct fs_sink_comp *fs_sink,
-               struct fs_sink_ctf_trace_class *tc,
+               struct fs_sink_ctf_trace *trace,
                const bt_stream_class *ir_sc,
                struct fs_sink_ctf_stream_class **out_sc)
 {
        int ret = 0;
        uint64_t i;
 
-       BT_ASSERT(tc);
+       BT_ASSERT(trace);
        BT_ASSERT(ir_sc);
 
-       for (i = 0; i < tc->stream_classes->len; i++) {
-               *out_sc = tc->stream_classes->pdata[i];
+       for (i = 0; i < trace->stream_classes->len; i++) {
+               *out_sc = trace->stream_classes->pdata[i];
 
                if ((*out_sc)->ir_sc == ir_sc) {
                        goto end;
                }
        }
 
-       ret = translate_stream_class(fs_sink, tc, ir_sc, out_sc);
+       ret = translate_stream_class(fs_sink, trace, ir_sc, out_sc);
 
 end:
        return ret;
 }
 
 BT_HIDDEN
-struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
-               struct fs_sink_comp *fs_sink, const bt_trace_class *ir_tc)
+struct fs_sink_ctf_trace *translate_trace_trace_ir_to_ctf_ir(
+               struct fs_sink_comp *fs_sink, const bt_trace *ir_trace)
 {
        uint64_t count;
        uint64_t i;
-       struct fs_sink_ctf_trace_class *tc = NULL;
+       struct fs_sink_ctf_trace *trace = NULL;
 
-       /* Check that trace class's environment is TSDL-compatible */
-       count = bt_trace_class_get_environment_entry_count(ir_tc);
+       /* Check that trace's environment is TSDL-compatible */
+       count = bt_trace_get_environment_entry_count(ir_trace);
        for (i = 0; i < count; i++) {
                const char *name;
                const bt_value *val;
 
-               bt_trace_class_borrow_environment_entry_by_index_const(
-                       ir_tc, i, &name, &val);
+               bt_trace_borrow_environment_entry_by_index_const(
+                       ir_trace, i, &name, &val);
 
                if (!fs_sink_ctf_ist_valid_identifier(name)) {
                        BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, fs_sink->log_level,
@@ -1298,9 +1298,9 @@ struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
                }
        }
 
-       tc = fs_sink_ctf_trace_class_create(ir_tc);
-       BT_ASSERT(tc);
+       trace = fs_sink_ctf_trace_create(ir_trace);
+       BT_ASSERT(trace);
 
 end:
-       return tc;
+       return trace;
 }
index 495667e37db33447d449146c3e32d1cf0a9a732a..7b2a81bcd480cc7e4a0b878db0727aab48ce77f3 100644 (file)
@@ -39,12 +39,12 @@ int try_translate_event_class_trace_ir_to_ctf_ir(
 BT_HIDDEN
 int try_translate_stream_class_trace_ir_to_ctf_ir(
                struct fs_sink_comp *fs_sink,
-               struct fs_sink_ctf_trace_class *tc,
+               struct fs_sink_ctf_trace *trace,
                const bt_stream_class *ir_sc,
                struct fs_sink_ctf_stream_class **out_sc);
 
 BT_HIDDEN
-struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
-               struct fs_sink_comp *fs_sink, const bt_trace_class *ir_tc);
+struct fs_sink_ctf_trace *translate_trace_trace_ir_to_ctf_ir(
+               struct fs_sink_comp *fs_sink, const bt_trace *ir_trace);
 
 #endif /* BABELTRACE_PLUGIN_CTF_FS_SINK_TRANSLATE_TRACE_IR_TO_CTF_IR_H */
index 84dae6a1b107b88582af9ddbe2a4af0126f2c8d4..4ad1853927948fd93fac81f89724257951a9b17b 100644 (file)
@@ -42,6 +42,7 @@
 #include "data-stream-file.h"
 #include "file.h"
 #include "../common/metadata/decoder.h"
+#include "../common/metadata/ctf-meta-configure-ir-trace.h"
 #include "../common/msg-iter/msg-iter.h"
 #include "query.h"
 
@@ -980,7 +981,6 @@ int set_trace_name(bt_trace *trace, const char *name_suffix,
                bt_logging_level log_level, bt_self_component *self_comp)
 {
        int ret = 0;
-       const bt_trace_class *tc = bt_trace_borrow_class_const(trace);
        const bt_value *val;
        GString *name;
 
@@ -995,8 +995,8 @@ int set_trace_name(bt_trace *trace, const char *name_suffix,
         * Check if we have a trace environment string value named `hostname`.
         * If so, use it as the trace name's prefix.
         */
-       val = bt_trace_class_borrow_environment_entry_value_by_name_const(
-               tc, "hostname");
+       val = bt_trace_borrow_environment_entry_value_by_name_const(
+               trace, "hostname");
        if (val && bt_value_is_string(val)) {
                g_string_append(name, bt_value_string_get(val));
 
@@ -1077,6 +1077,12 @@ struct ctf_fs_trace *ctf_fs_trace_create(bt_self_component *self_comp,
        }
 
        if (ctf_fs_trace->trace) {
+               ret = ctf_trace_class_configure_ir_trace(
+                       ctf_fs_trace->metadata->tc, ctf_fs_trace->trace);
+               if (ret) {
+                       goto error;
+               }
+
                ret = set_trace_name(ctf_fs_trace->trace, name, log_level,
                        self_comp);
                if (ret) {
index b52e179617ee0c7b547637dca91ae306b2c03748..8e7ca952797454849756735c0c1805ebb951b527 100644 (file)
@@ -63,8 +63,6 @@ struct ctf_fs_metadata {
        /* Weak (owned by `decoder` above) */
        struct ctf_trace_class *tc;
 
-       /* Owned by this */
-
        /* Owned by this */
        char *text;
 
index f4d69ffc9398a2a2434386d756c03dd405a12c5c..8475c569633bd022170793dbf5003a1118a90d2d 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "metadata.h"
 #include "../common/metadata/decoder.h"
+#include "../common/metadata/ctf-meta-configure-ir-trace.h"
 
 #define TSDL_MAGIC     0x75d11d57
 
@@ -224,10 +225,21 @@ enum lttng_live_iterator_status lttng_live_metadata_update(
        switch (decoder_status) {
        case CTF_METADATA_DECODER_STATUS_OK:
                if (!trace->trace_class) {
+                       struct ctf_trace_class *tc =
+                               ctf_metadata_decoder_borrow_ctf_trace_class(
+                                       metadata->decoder);
+
                        trace->trace_class =
                                ctf_metadata_decoder_get_ir_trace_class(
                                                metadata->decoder);
                        trace->trace = bt_trace_create(trace->trace_class);
+                       if (!trace->trace) {
+                               goto error;
+                       }
+                       if (ctf_trace_class_configure_ir_trace(tc,
+                                       trace->trace)) {
+                               goto error;
+                       }
                        if (!stream_classes_all_have_default_clock_class(
                                        trace->trace_class, log_level,
                                        self_comp)) {
index feb8347b92a27cf1a4bc55ec57612d66e20ee85f..60c52e5d78bbb8dcf59f1bc7c913f24f87182190 100644 (file)
@@ -41,6 +41,7 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace,
 {
        bt_trace_set_name_status status;
        const char *trace_name;
+       uint64_t i, env_field_count;
 
        BT_COMP_LOGD("Copying content of trace: in-t-addr=%p, out-t-addr=%p",
                        in_trace, out_trace);
@@ -56,6 +57,56 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace,
                }
        }
 
+       /*
+        * Do not copy the trace UUID as it may be modified and should
+        * no longer have the same UUID.
+        */
+
+       /*
+        * Go over all the entries in the environment section of the
+        * trace and copy the content to the new trace.
+        */
+       env_field_count = bt_trace_get_environment_entry_count(in_trace);
+       for (i = 0; i < env_field_count; i++) {
+               const char *value_name;
+               const bt_value *value = NULL;
+               bt_trace_set_environment_entry_status set_env_status;
+
+               bt_trace_borrow_environment_entry_by_index_const(
+                       in_trace, i, &value_name, &value);
+
+               BT_COMP_LOGD("Copying trace environnement entry: "
+                       "index=%" PRId64 ", value-addr=%p, value-name=%s",
+                       i, value, value_name);
+
+               BT_ASSERT(value_name);
+               BT_ASSERT(value);
+
+               if (bt_value_is_signed_integer(value)) {
+                       set_env_status =
+                               bt_trace_set_environment_entry_integer(
+                                               out_trace, value_name,
+                                               bt_value_signed_integer_get(
+                                                       value));
+               } else if (bt_value_is_string(value)) {
+                       set_env_status =
+                               bt_trace_set_environment_entry_string(
+                                       out_trace, value_name,
+                                       bt_value_string_get(value));
+               } else {
+                       abort();
+               }
+
+               if (set_env_status !=
+                               BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK) {
+                       BT_COMP_LOGE("Cannot copy trace's environment: "
+                               "trace-addr=%p, name=\"%s\"",
+                               out_trace, trace_name);
+                       bt_current_thread_clear_error();
+                       goto end;
+               }
+       }
+
        BT_COMP_LOGD("Copied content of trace: in-t-addr=%p, out-t-addr=%p",
                        in_trace, out_trace);
 end:
index 2b3970fca43dd538fcf62b1f7cca084c6e10dd8f..ce76cce52d5262df463b9368a4d7e8ba363118ab 100644 (file)
@@ -43,79 +43,15 @@ int copy_trace_class_content(const bt_trace_class *in_trace_class,
                bt_trace_class *out_trace_class, bt_logging_level log_level,
                bt_self_component *self_comp)
 {
-       int ret = 0;
-       uint64_t i, env_field_count;
-       const char *in_trace_class_name;
-
        BT_COMP_LOGD("Copying content of trace class: in-tc-addr=%p, out-tc-addr=%p",
                        in_trace_class, out_trace_class);
 
        /* Use the same stream class ids as in the origin trace class. */
        bt_trace_class_set_assigns_automatic_stream_class_id(out_trace_class,
                        BT_FALSE);
-
-       in_trace_class_name = bt_trace_class_get_name(in_trace_class);
-       if (in_trace_class_name) {
-               bt_trace_class_set_name_status status;
-
-               status = bt_trace_class_set_name(out_trace_class,
-                       in_trace_class_name);
-               if (status != BT_TRACE_CLASS_SET_NAME_STATUS_OK) {
-                       bt_current_thread_clear_error();
-               }
-       }
-
-       /*
-        * Do not copy the trace class UUID as it may be modified and should no
-        * longer have the same UUID.
-        */
-
-       /*
-        * Go over all the entries in the environment section of the trace class
-        * and copy the content to the new trace class.
-        */
-       env_field_count = bt_trace_class_get_environment_entry_count(in_trace_class);
-       for (i = 0; i < env_field_count; i++) {
-               const char *value_name;
-               const bt_value *value = NULL;
-               bt_trace_class_set_environment_entry_status set_env_status;
-
-               bt_trace_class_borrow_environment_entry_by_index_const(
-                       in_trace_class, i, &value_name, &value);
-
-               BT_COMP_LOGD("Copying trace class environnement entry: "
-                       "index=%" PRId64 ", value-addr=%p, value-name=%s",
-                       i, value, value_name);
-
-               BT_ASSERT(value_name);
-               BT_ASSERT(value);
-
-               if (bt_value_is_signed_integer(value)) {
-                       set_env_status =
-                               bt_trace_class_set_environment_entry_integer(
-                                               out_trace_class, value_name,
-                                               bt_value_signed_integer_get(
-                                                       value));
-               } else if (bt_value_is_string(value)) {
-                       set_env_status =
-                               bt_trace_class_set_environment_entry_string(
-                                       out_trace_class, value_name,
-                                       bt_value_string_get(value));
-               } else {
-                       abort();
-               }
-
-               if (set_env_status !=
-                               BT_TRACE_CLASS_SET_ENVIRONMENT_ENTRY_STATUS_OK) {
-                       ret = -1;
-                       goto error;
-               }
-       }
-
        BT_COMP_LOGD("Copied content of trace class: in-tc-addr=%p, out-tc-addr=%p",
                        in_trace_class, out_trace_class);
-error:
-       return ret;
+       return 0;
 }
 
 static
index cd48a87c7b3e003e7a0a0d6acf221a4fb070a654..47a29326313fe5b1aba827dbc07f654bb873b3a6 100644 (file)
@@ -53,9 +53,6 @@ const char * const with_metadata_param_name = "with-metadata";
 static
 const char * const with_time_param_name = "with-time";
 
-static
-const char * const with_trace_class_name_param_name = "with-trace-class-name";
-
 static
 const char * const with_trace_name_param_name = "with-trace-name";
 
@@ -322,14 +319,6 @@ int configure_details_comp(struct details_comp *details_comp,
                goto error;
        }
 
-       /* With trace class name? */
-       ret = configure_bool_opt(details_comp, params,
-               with_trace_class_name_param_name,
-               true, &details_comp->cfg.with_trace_class_name);
-       if (ret) {
-               goto error;
-       }
-
        /* With trace name? */
        ret = configure_bool_opt(details_comp, params,
                with_trace_name_param_name,
@@ -381,8 +370,6 @@ void log_configuration(bt_self_component_sink *comp,
        BT_COMP_LOGI("  Compact: %d", details_comp->cfg.compact);
        BT_COMP_LOGI("  With metadata: %d", details_comp->cfg.with_meta);
        BT_COMP_LOGI("  With time: %d", details_comp->cfg.with_time);
-       BT_COMP_LOGI("  With trace class name: %d",
-               details_comp->cfg.with_trace_class_name);
        BT_COMP_LOGI("  With trace name: %d", details_comp->cfg.with_trace_name);
        BT_COMP_LOGI("  With stream class name: %d",
                details_comp->cfg.with_stream_class_name);
index f475c9d067d05493b173234261d46eda80a2b540..71f8882d2530e5e17926c99f1fa4bd4019d74029 100644 (file)
@@ -97,9 +97,6 @@ struct details_comp {
                /* Write message's time */
                bool with_time;
 
-               /* Write trace class's name */
-               bool with_trace_class_name;
-
                /* Write trace's name */
                bool with_trace_name;
 
index 3ea4d41c97fbdbaf38ec42f20fdbcc678ad6417c..b102485b48b519b40f3701271a29cec0bc0a6d27 100644 (file)
@@ -1121,97 +1121,12 @@ static
 void write_trace_class(struct details_write_ctx *ctx, const bt_trace_class *tc)
 {
        GPtrArray *stream_classes = g_ptr_array_new();
-       GPtrArray *env_names = g_ptr_array_new();
-       uint64_t env_count;
        uint64_t i;
        bool printed_prop = false;
 
        write_indent(ctx);
        write_obj_type_name(ctx, "Trace class");
 
-       /* Write name */
-       if (ctx->details_comp->cfg.with_trace_class_name) {
-               const char *name = bt_trace_class_get_name(tc);
-
-               if (name) {
-                       g_string_append(ctx->str, " `");
-                       write_str_prop_value(ctx, name);
-                       g_string_append(ctx->str, "`");
-               }
-       }
-
-       /* Write properties */
-       incr_indent(ctx);
-
-       if (ctx->details_comp->cfg.with_uuid) {
-               bt_uuid uuid = bt_trace_class_get_uuid(tc);
-
-               if (uuid) {
-                       if (!printed_prop) {
-                               g_string_append(ctx->str, ":\n");
-                               printed_prop = true;
-                       }
-
-                       write_uuid_prop_line(ctx, "UUID", uuid);
-               }
-       }
-
-       /* Write environment */
-       env_count = bt_trace_class_get_environment_entry_count(tc);
-       if (env_count > 0) {
-               if (!printed_prop) {
-                       g_string_append(ctx->str, ":\n");
-                       printed_prop = true;
-               }
-
-               write_indent(ctx);
-               write_prop_name(ctx, "Environment");
-               g_string_append(ctx->str, " (");
-               write_uint_prop_value(ctx, env_count);
-               g_string_append_printf(ctx->str, " entr%s):",
-                       env_count == 1 ? "y" : "ies");
-               write_nl(ctx);
-               incr_indent(ctx);
-
-               for (i = 0; i < env_count; i++) {
-                       const char *name;
-                       const bt_value *value;
-
-                       bt_trace_class_borrow_environment_entry_by_index_const(
-                               tc, i, &name, &value);
-                       g_ptr_array_add(env_names, (gpointer) name);
-               }
-
-               g_ptr_array_sort(env_names, (GCompareFunc) compare_strings);
-
-               for (i = 0; i < env_names->len; i++) {
-                       const char *name = env_names->pdata[i];
-                       const bt_value *value =
-                               bt_trace_class_borrow_environment_entry_value_by_name_const(
-                                       tc, name);
-
-                       BT_ASSERT(value);
-                       write_compound_member_name(ctx, name);
-                       write_sp(ctx);
-
-                       if (bt_value_get_type(value) ==
-                                       BT_VALUE_TYPE_SIGNED_INTEGER) {
-                               write_int_prop_value(ctx,
-                                       bt_value_signed_integer_get(value));
-                       } else if (bt_value_get_type(value) ==
-                                       BT_VALUE_TYPE_STRING) {
-                               write_str_prop_value(ctx,
-                                       bt_value_string_get(value));
-                       } else {
-                               abort();
-                       }
-
-                       write_nl(ctx);
-               }
-
-               decr_indent(ctx);
-       }
-
        for (i = 0; i < bt_trace_class_get_stream_class_count(tc); i++) {
                g_ptr_array_add(stream_classes,
                        (gpointer) bt_trace_class_borrow_stream_class_by_index_const(
@@ -1227,18 +1142,18 @@ void write_trace_class(struct details_write_ctx *ctx, const bt_trace_class *tc)
                }
        }
 
+       incr_indent(ctx);
+
        for (i = 0; i < stream_classes->len; i++) {
                write_stream_class(ctx, stream_classes->pdata[i]);
        }
 
-       decr_indent(ctx);
-
        if (!printed_prop) {
                write_nl(ctx);
        }
 
+       decr_indent(ctx);
        g_ptr_array_free(stream_classes, TRUE);
-       g_ptr_array_free(env_names, TRUE);
 }
 
 static
@@ -1716,10 +1631,11 @@ static
 void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
 {
        const char *name;
-       const bt_trace_class *tc = bt_trace_borrow_class_const(trace);
        GPtrArray *streams = g_ptr_array_new();
        uint64_t i;
        bool printed_prop = false;
+       GPtrArray *env_names = g_ptr_array_new();
+       uint64_t env_count;
 
        write_indent(ctx);
        write_obj_type_name(ctx, "Trace");
@@ -1737,29 +1653,74 @@ void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
        /* Write properties */
        incr_indent(ctx);
 
-       if (ctx->details_comp->cfg.with_trace_class_name) {
-               name = bt_trace_class_get_name(tc);
-               if (name) {
+       /* Write UUID */
+       if (ctx->details_comp->cfg.with_uuid) {
+               bt_uuid uuid = bt_trace_get_uuid(trace);
+
+               if (uuid) {
                        if (!printed_prop) {
                                g_string_append(ctx->str, ":\n");
                                printed_prop = true;
                        }
 
-                       write_str_prop_line(ctx, "Class name", name);
+                       write_uuid_prop_line(ctx, "UUID", uuid);
                }
        }
 
-       if (ctx->details_comp->cfg.with_uuid) {
-               bt_uuid uuid = bt_trace_class_get_uuid(tc);
+       /* Write environment */
+       env_count = bt_trace_get_environment_entry_count(trace);
+       if (env_count > 0) {
+               if (!printed_prop) {
+                       g_string_append(ctx->str, ":\n");
+                       printed_prop = true;
+               }
 
-               if (uuid) {
-                       if (!printed_prop) {
-                               g_string_append(ctx->str, ":\n");
-                               printed_prop = true;
+               write_indent(ctx);
+               write_prop_name(ctx, "Environment");
+               g_string_append(ctx->str, " (");
+               write_uint_prop_value(ctx, env_count);
+               g_string_append_printf(ctx->str, " entr%s):",
+                       env_count == 1 ? "y" : "ies");
+               write_nl(ctx);
+               incr_indent(ctx);
+
+               for (i = 0; i < env_count; i++) {
+                       const char *name;
+                       const bt_value *value;
+
+                       bt_trace_borrow_environment_entry_by_index_const(
+                               trace, i, &name, &value);
+                       g_ptr_array_add(env_names, (gpointer) name);
+               }
+
+               g_ptr_array_sort(env_names, (GCompareFunc) compare_strings);
+
+               for (i = 0; i < env_names->len; i++) {
+                       const char *name = env_names->pdata[i];
+                       const bt_value *value =
+                               bt_trace_borrow_environment_entry_value_by_name_const(
+                                       trace, name);
+
+                       BT_ASSERT(value);
+                       write_compound_member_name(ctx, name);
+                       write_sp(ctx);
+
+                       if (bt_value_get_type(value) ==
+                                       BT_VALUE_TYPE_SIGNED_INTEGER) {
+                               write_int_prop_value(ctx,
+                                       bt_value_signed_integer_get(value));
+                       } else if (bt_value_get_type(value) ==
+                                       BT_VALUE_TYPE_STRING) {
+                               write_str_prop_value(ctx,
+                                       bt_value_string_get(value));
+                       } else {
+                               abort();
                        }
 
-                       write_uuid_prop_line(ctx, "Class UUID", uuid);
+                       write_nl(ctx);
                }
+
+               decr_indent(ctx);
        }
 
        for (i = 0; i < bt_trace_get_stream_count(trace); i++) {
@@ -1796,6 +1757,7 @@ void write_trace(struct details_write_ctx *ctx, const bt_trace *trace)
        }
 
        g_ptr_array_free(streams, TRUE);
+       g_ptr_array_free(env_names, TRUE);
 }
 
 static
index ed4f3a38488c132a0e66ab120ce4a06c2918fe35..80651f15fa97e23a4b54df71d4186d1e6461e2d1 100644 (file)
@@ -295,8 +295,6 @@ int print_event_header(struct pretty_component *pretty,
        bool print_names = pretty->options.print_header_field_names;
        int ret = 0;
        const bt_event_class *event_class = NULL;
-       const bt_stream_class *stream_class = NULL;
-       const bt_trace_class *trace_class = NULL;
        const bt_packet *packet = NULL;
        const bt_stream *stream = NULL;
        const bt_trace *trace = NULL;
@@ -306,8 +304,6 @@ int print_event_header(struct pretty_component *pretty,
        bt_property_availability prop_avail;
 
        event_class = bt_event_borrow_class_const(event);
-       stream_class = bt_event_class_borrow_stream_class_const(event_class);
-       trace_class = bt_stream_class_borrow_trace_class_const(stream_class);
        packet = bt_event_borrow_packet_const(event);
        stream = bt_packet_borrow_stream_const(packet);
        trace = bt_stream_borrow_trace_const(stream);
@@ -337,8 +333,8 @@ int print_event_header(struct pretty_component *pretty,
        if (pretty->options.print_trace_hostname_field) {
                const bt_value *hostname_str;
 
-               hostname_str = bt_trace_class_borrow_environment_entry_value_by_name_const(
-                       trace_class, "hostname");
+               hostname_str = bt_trace_borrow_environment_entry_value_by_name_const(
+                       trace, "hostname");
                if (hostname_str) {
                        const char *str;
 
@@ -356,8 +352,8 @@ int print_event_header(struct pretty_component *pretty,
        if (pretty->options.print_trace_domain_field) {
                const bt_value *domain_str;
 
-               domain_str = bt_trace_class_borrow_environment_entry_value_by_name_const(
-                       trace_class, "domain");
+               domain_str = bt_trace_borrow_environment_entry_value_by_name_const(
+                       trace, "domain");
                if (domain_str) {
                        const char *str;
 
@@ -377,8 +373,8 @@ int print_event_header(struct pretty_component *pretty,
        if (pretty->options.print_trace_procname_field) {
                const bt_value *procname_str;
 
-               procname_str = bt_trace_class_borrow_environment_entry_value_by_name_const(
-                       trace_class, "procname");
+               procname_str = bt_trace_borrow_environment_entry_value_by_name_const(
+                       trace, "procname");
                if (procname_str) {
                        const char *str;
 
@@ -398,8 +394,8 @@ int print_event_header(struct pretty_component *pretty,
        if (pretty->options.print_trace_vpid_field) {
                const bt_value *vpid_value;
 
-               vpid_value = bt_trace_class_borrow_environment_entry_value_by_name_const(
-                       trace_class, "vpid");
+               vpid_value = bt_trace_borrow_environment_entry_value_by_name_const(
+                       trace, "vpid");
                if (vpid_value) {
                        int64_t value;
 
@@ -1242,8 +1238,7 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
        }
 
        /* Trace UUID */
-       trace_uuid = bt_trace_class_get_uuid(
-               bt_trace_borrow_class_const(trace));
+       trace_uuid = bt_trace_get_uuid(trace);
 
        /* Format message */
        g_string_assign(pretty->string, "");
index 6e453ba999cee24128e2f42cb80e1bfe64891804..85615b4b515ba7d001e15fc80661af24c848daa3 100644 (file)
@@ -16,6 +16,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
 
+import uuid
 import unittest
 from utils import get_default_trace_class
 
@@ -26,20 +27,37 @@ class TraceTestCase(unittest.TestCase):
 
     def test_create_default(self):
         trace = self._tc()
-        self.assertEqual(trace.name, None)
-
-    def test_create_full(self):
-        trace = self._tc(name='my name')
-        self.assertEqual(trace.name, 'my name')
+        self.assertIsNone(trace.name)
+        self.assertIsNone(trace.uuid)
+        self.assertEqual(len(trace.env), 0)
 
     def test_create_invalid_name(self):
         with self.assertRaises(TypeError):
             self._tc(name=17)
 
     def test_attr_trace_class(self):
-        trace = self._tc(name='my name')
+        trace = self._tc()
         self.assertEqual(trace.cls.addr, self._tc.addr)
 
+    def test_attr_name(self):
+        trace = self._tc(name='mein trace')
+        self.assertEqual(trace.name, 'mein trace')
+
+    def test_attr_uuid(self):
+        trace = self._tc(uuid=uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b'))
+        self.assertEqual(trace.uuid, uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b'))
+
+    def test_env_get(self):
+        trace = self._tc(env={'hello': 'you', 'foo': -5})
+        self.assertEqual(trace.env['hello'], 'you')
+        self.assertEqual(trace.env['foo'], -5)
+
+    def test_env_get_non_existent(self):
+        trace = self._tc(env={'hello': 'you', 'foo': -5})
+
+        with self.assertRaises(KeyError):
+            trace.env['lel']
+
     def test_len(self):
         trace = self._tc()
         sc = self._tc.create_stream_class()
index 466381e814d3f1d68a57f4319bd6a492dd196276..1b4b2a7ee30a939d48c2163786f0d9d08a3cbff5 100644 (file)
@@ -16,7 +16,6 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
 
-import uuid
 import unittest
 import bt2
 from utils import run_in_component_init, get_default_trace_class
@@ -31,18 +30,8 @@ class TraceClassTestCase(unittest.TestCase):
         tc = run_in_component_init(f)
 
         self.assertEqual(len(tc), 0)
-        self.assertEqual(len(tc.env), 0)
-        self.assertIsNone(tc.uuid)
         self.assertTrue(tc.assigns_automatic_stream_class_id)
 
-    def test_uuid(self):
-        def f(comp_self):
-            return comp_self._create_trace_class(uuid=uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b'))
-
-        tc = run_in_component_init(f)
-
-        self.assertEqual(tc.uuid, uuid.UUID('da7d6b6f-3108-4706-89bd-ab554732611b'))
-
     def test_automatic_stream_class_id(self):
         def f(comp_self):
             return comp_self._create_trace_class(assigns_automatic_stream_class_id=True)
@@ -87,24 +76,6 @@ class TraceClassTestCase(unittest.TestCase):
         with self.assertRaises(ValueError):
             tc.create_stream_class()
 
-    def test_env_get(self):
-        def f(comp_self):
-            return comp_self._create_trace_class(env={'hello': 'you', 'foo': -5})
-
-        tc = run_in_component_init(f)
-
-        self.assertEqual(tc.env['hello'], 'you')
-        self.assertEqual(tc.env['foo'], -5)
-
-    def test_env_get_non_existent(self):
-        def f(comp_self):
-            return comp_self._create_trace_class(env={'hello': 'you', 'foo': -5})
-
-        tc = run_in_component_init(f)
-
-        with self.assertRaises(KeyError):
-            tc.env['lel']
-
     @staticmethod
     def _create_trace_class_with_some_stream_classes():
         def f(comp_self):
index 514049001b31978a4016967605dd47568cbe76de..a22778faefae602d358d1a30d1791e96dc658612 100644 (file)
@@ -1,5 +1,4 @@
 Trace class:
-  UUID: 2a6422d0-6cee-11e0-8c08-cb07d7b3a564
   Stream class (ID 0):
     Packets have beginning default clock snapshot: No
     Packets have end default clock snapshot: No
@@ -14,7 +13,7 @@ Trace class:
 {Trace 0, Stream class ID 0, Stream ID 0}
 Stream beginning:
   Trace:
-    Class UUID: 2a6422d0-6cee-11e0-8c08-cb07d7b3a564
+    UUID: 2a6422d0-6cee-11e0-8c08-cb07d7b3a564
     Stream (ID 0, Class ID 0)
 
 [Unknown]
This page took 0.059005 seconds and 4 git commands to generate.