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);
#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_* */
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);
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(
#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_* */
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);
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)
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
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):
_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)
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
_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:
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.
yield id
- @property
- def env(self):
- return _TraceClassEnv(self)
-
def create_stream_class(self, id=None,
name=None,
packet_context_field_class=None,
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));
return;
}
+ if (trace->uuid.value) {
+ BUF_APPEND_UUID(trace->uuid.value);
+ }
+
BUF_APPEND(", %sis-frozen=%d", PRFIELD(trace->frozen));
if (trace->streams) {
#include <string.h>
#include <stdlib.h>
-#include "attributes.h"
#include "clock-class.h"
#include "event-class.h"
#include "event.h"
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);
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) {
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,
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");
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;
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);
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) {
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");
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;
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)
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+#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 */
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];
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;
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;
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);
ir_sc);
}
- g_ptr_array_add(tc->stream_classes, sc);
+ g_ptr_array_add(trace->stream_classes, sc);
return sc;
}
}
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
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;
/* 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);
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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 {
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");
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:
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;
}
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
}
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 = {
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 = ");
/* 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");
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);
default:
/*
* This is checked in
- * translate_trace_class_trace_ir_to_ctf_ir().
+ * translate_trace_trace_ir_to_ctf_ir().
*/
abort();
}
}
/* 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]);
}
}
#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 */
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 */
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++;
}
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 */
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,
}
}
- 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;
}
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 */
#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"
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;
* 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));
}
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) {
/* Weak (owned by `decoder` above) */
struct ctf_trace_class *tc;
- /* Owned by this */
-
/* Owned by this */
char *text;
#include "metadata.h"
#include "../common/metadata/decoder.h"
+#include "../common/metadata/ctf-meta-configure-ir-trace.h"
#define TSDL_MAGIC 0x75d11d57
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)) {
{
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);
}
}
+ /*
+ * 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:
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
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";
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,
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);
/* 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;
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(
}
}
+ 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
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");
/* 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++) {
}
g_ptr_array_free(streams, TRUE);
+ g_ptr_array_free(env_names, TRUE);
}
static
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;
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);
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;
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;
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;
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;
}
/* 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, "");
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import uuid
import unittest
from utils import get_default_trace_class
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()
# 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
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)
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):
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
{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]