#define BT_LOG_TAG "TRACE"
#include <babeltrace/lib-logging-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <babeltrace/ctf-ir/trace-internal.h>
#include <babeltrace/ctf-ir/clock-class-internal.h>
#include <babeltrace/ctf-ir/stream-internal.h>
#include <babeltrace/ctf-ir/event-class-internal.h>
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/ctf-writer/clock-internal.h>
+#include <babeltrace/ctf-ir/field-wrapper-internal.h>
#include <babeltrace/ctf-ir/field-types-internal.h>
#include <babeltrace/ctf-ir/attributes-internal.h>
#include <babeltrace/ctf-ir/validation-internal.h>
void *data;
};
-static
-void bt_trace_destroy(struct bt_object *obj);
-static
-void bt_trace_freeze(struct bt_trace *trace);
+static inline
+void bt_trace_finalize(struct bt_trace *trace)
+{
+ BT_LOGD("Finalizing trace object: addr=%p, name=\"%s\"",
+ trace, bt_trace_get_name(trace));
-static
-const unsigned int field_type_aliases_alignments[] = {
- [FIELD_TYPE_ALIAS_UINT5_T] = 1,
- [FIELD_TYPE_ALIAS_UINT8_T ... FIELD_TYPE_ALIAS_UINT16_T] = 8,
- [FIELD_TYPE_ALIAS_UINT27_T] = 1,
- [FIELD_TYPE_ALIAS_UINT32_T ... FIELD_TYPE_ALIAS_UINT64_T] = 8,
-};
+ if (trace->environment) {
+ BT_LOGD_STR("Destroying environment attributes.");
+ bt_attributes_destroy(trace->environment);
+ }
-static
-const unsigned int field_type_aliases_sizes[] = {
- [FIELD_TYPE_ALIAS_UINT5_T] = 5,
- [FIELD_TYPE_ALIAS_UINT8_T] = 8,
- [FIELD_TYPE_ALIAS_UINT16_T] = 16,
- [FIELD_TYPE_ALIAS_UINT27_T] = 27,
- [FIELD_TYPE_ALIAS_UINT32_T] = 32,
- [FIELD_TYPE_ALIAS_UINT64_T] = 64,
-};
+ if (trace->name) {
+ g_string_free(trace->name, TRUE);
+ }
-struct bt_trace *bt_trace_create(void)
+ if (trace->clock_classes) {
+ BT_LOGD_STR("Putting clock classes.");
+ g_ptr_array_free(trace->clock_classes, TRUE);
+ }
+
+ if (trace->streams) {
+ BT_LOGD_STR("Destroying streams.");
+ g_ptr_array_free(trace->streams, TRUE);
+ }
+
+ if (trace->stream_classes) {
+ BT_LOGD_STR("Destroying stream classes.");
+ g_ptr_array_free(trace->stream_classes, TRUE);
+ }
+
+ BT_LOGD_STR("Putting packet header field type.");
+ bt_put(trace->packet_header_field_type);
+}
+
+static
+void bt_trace_destroy(struct bt_object *obj)
{
- struct bt_trace *trace = NULL;
+ struct bt_trace *trace = (void *) obj;
- trace = g_new0(struct bt_trace, 1);
- if (!trace) {
- BT_LOGE_STR("Failed to allocate one trace.");
- goto error;
+ BT_LOGD("Destroying trace object: addr=%p, name=\"%s\"",
+ trace, bt_trace_get_name(trace));
+
+ /*
+ * Call remove listeners first so that everything else still
+ * exists in the trace.
+ */
+ if (trace->is_static_listeners) {
+ size_t i;
+
+ for (i = 0; i < trace->is_static_listeners->len; i++) {
+ struct bt_trace_is_static_listener_elem elem =
+ g_array_index(trace->is_static_listeners,
+ struct bt_trace_is_static_listener_elem, i);
+
+ if (elem.removed) {
+ elem.removed(trace, elem.data);
+ }
+ }
+
+ g_array_free(trace->is_static_listeners, TRUE);
}
- BT_LOGD_STR("Creating trace object.");
+ if (trace->listeners) {
+ g_ptr_array_free(trace->listeners, TRUE);
+ }
+
+ bt_object_pool_finalize(&trace->packet_header_field_pool);
+ bt_trace_finalize(trace);
+ g_free(trace);
+}
+
+static inline
+int bt_trace_initialize(struct bt_trace *trace,
+ bt_object_release_func release_func)
+{
+ int ret = 0;
+
+ BT_LOGD_STR("Initializing trace object.");
trace->native_byte_order = BT_BYTE_ORDER_UNSPECIFIED;
- bt_object_init(trace, bt_trace_destroy);
- trace->clocks = g_ptr_array_new_with_free_func(
+ bt_object_init_shared_with_parent(&trace->base, release_func);
+ trace->clock_classes = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_put);
- if (!trace->clocks) {
+ if (!trace->clock_classes) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
}
trace->streams = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_object_release);
+ (GDestroyNotify) bt_object_try_spec_release);
if (!trace->streams) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
}
trace->stream_classes = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_object_release);
+ (GDestroyNotify) bt_object_try_spec_release);
if (!trace->stream_classes) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
goto error;
}
+ BT_LOGD("Initialized trace object: addr=%p", trace);
+ goto end;
+
+error:
+ ret = -1;
+
+end:
+ return ret;
+}
+
+static
+void free_packet_header_field(struct bt_field_wrapper *field_wrapper,
+ struct bt_trace *trace)
+{
+ bt_field_wrapper_destroy(field_wrapper);
+}
+
+struct bt_trace *bt_trace_create(void)
+{
+ struct bt_trace *trace = NULL;
+ int ret;
+
+ BT_LOGD_STR("Creating trace object.");
+ trace = g_new0(struct bt_trace, 1);
+ if (!trace) {
+ BT_LOGE_STR("Failed to allocate one trace.");
+ goto error;
+ }
+
+ ret = bt_trace_initialize(trace, bt_trace_destroy);
+ if (ret) {
+ /* bt_trace_initialize() logs errors */
+ goto error;
+ }
+
trace->listeners = g_ptr_array_new_with_free_func(
(GDestroyNotify) g_free);
if (!trace->listeners) {
goto error;
}
+ ret = bt_object_pool_initialize(&trace->packet_header_field_pool,
+ (bt_object_pool_new_object_func) bt_field_wrapper_new,
+ (bt_object_pool_destroy_object_func) free_packet_header_field,
+ trace);
+ if (ret) {
+ BT_LOGE("Failed to initialize packet header field pool: ret=%d",
+ ret);
+ goto error;
+ }
+
BT_LOGD("Created trace object: addr=%p", trace);
return trace;
const char *bt_trace_get_name(struct bt_trace *trace)
{
- const char *name = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- if (!trace->name) {
- goto end;
- }
-
- name = trace->name->str;
-end:
- return name;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return trace->name ? trace->name->str : NULL;
}
int bt_trace_set_name(struct bt_trace *trace, const char *name)
const unsigned char *bt_trace_get_uuid(struct bt_trace *trace)
{
- return trace && trace->uuid_set ? trace->uuid : NULL;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return trace->uuid_set ? trace->uuid : NULL;
}
-int bt_trace_set_uuid(struct bt_trace *trace, const unsigned char *uuid)
+int bt_trace_set_uuid(struct bt_trace *trace,
+ const unsigned char *uuid)
{
int ret = 0;
return ret;
}
-void bt_trace_destroy(struct bt_object *obj)
-{
- struct bt_trace *trace;
-
- trace = container_of(obj, struct bt_trace, base);
-
- BT_LOGD("Destroying trace object: addr=%p, name=\"%s\"",
- trace, bt_trace_get_name(trace));
-
- /*
- * Call remove listeners first so that everything else still
- * exists in the trace.
- */
- if (trace->is_static_listeners) {
- size_t i;
-
- for (i = 0; i < trace->is_static_listeners->len; i++) {
- struct bt_trace_is_static_listener_elem elem =
- g_array_index(trace->is_static_listeners,
- struct bt_trace_is_static_listener_elem, i);
-
- if (elem.removed) {
- elem.removed(trace, elem.data);
- }
- }
-
- g_array_free(trace->is_static_listeners, TRUE);
- }
-
- if (trace->listeners) {
- g_ptr_array_free(trace->listeners, TRUE);
- }
-
- if (trace->environment) {
- BT_LOGD_STR("Destroying environment attributes.");
- bt_attributes_destroy(trace->environment);
- }
-
- if (trace->name) {
- g_string_free(trace->name, TRUE);
- }
-
- if (trace->clocks) {
- BT_LOGD_STR("Putting clock classes.");
- g_ptr_array_free(trace->clocks, TRUE);
- }
-
- if (trace->streams) {
- BT_LOGD_STR("Destroying streams.");
- g_ptr_array_free(trace->streams, TRUE);
- }
-
- if (trace->stream_classes) {
- BT_LOGD_STR("Destroying stream classes.");
- g_ptr_array_free(trace->stream_classes, TRUE);
- }
-
- BT_LOGD_STR("Putting packet header field type.");
- bt_put(trace->packet_header_type);
- g_free(trace);
-}
-
int bt_trace_set_environment_field(struct bt_trace *trace,
const char *name, struct bt_value *value)
{
goto end;
}
+ if (trace->is_static) {
+ BT_LOGW("Invalid parameter: trace is static: "
+ "addr=%p, name=\"%s\"",
+ trace, bt_trace_get_name(trace));
+ ret = -1;
+ goto end;
+ }
+
if (!bt_identifier_is_valid(name)) {
BT_LOGW("Invalid parameter: environment field's name is not a valid CTF identifier: "
"trace-addr=%p, trace-name=\"%s\", "
goto end;
}
- if (trace->is_static) {
- BT_LOGW("Invalid parameter: trace is static: "
- "addr=%p, name=\"%s\"",
- trace, bt_trace_get_name(trace));
- ret = -1;
- goto end;
- }
-
if (trace->frozen) {
/*
* New environment fields may be added to a frozen trace,
* The object passed is frozen like all other attributes.
*/
struct bt_value *attribute =
- bt_attributes_get_field_value_by_name(
+ bt_attributes_borrow_field_value_by_name(
trace->environment, name);
if (attribute) {
"trace-addr=%p, trace-name=\"%s\", "
"env-name=\"%s\"",
trace, bt_trace_get_name(trace), name);
- BT_PUT(attribute);
ret = -1;
goto end;
}
return ret;
}
-int bt_trace_set_environment_field_integer(struct bt_trace *trace,
- const char *name, int64_t value)
+int bt_trace_set_environment_field_integer(
+ struct bt_trace *trace, const char *name, int64_t value)
{
int ret = 0;
struct bt_value *env_value_integer_obj = NULL;
int64_t bt_trace_get_environment_field_count(struct bt_trace *trace)
{
- int64_t ret = 0;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- ret = (int64_t) -1;
- goto end;
- }
+ int64_t ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
ret = bt_attributes_get_count(trace->environment);
BT_ASSERT(ret >= 0);
-
-end:
return ret;
}
bt_trace_get_environment_field_name_by_index(struct bt_trace *trace,
uint64_t index)
{
- const char *ret = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- ret = bt_attributes_get_field_name(trace->environment, index);
-
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return bt_attributes_get_field_name(trace->environment, index);
}
-struct bt_value *bt_trace_get_environment_field_value_by_index(
+struct bt_value *bt_trace_borrow_environment_field_value_by_index(
struct bt_trace *trace, uint64_t index)
{
- struct bt_value *ret = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- ret = bt_attributes_get_field_value(trace->environment, index);
-
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return bt_attributes_borrow_field_value(trace->environment, index);
}
-struct bt_value *bt_trace_get_environment_field_value_by_name(
+struct bt_value *bt_trace_borrow_environment_field_value_by_name(
struct bt_trace *trace, const char *name)
{
- struct bt_value *ret = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- if (!name) {
- BT_LOGW_STR("Invalid parameter: name is NULL.");
- goto end;
- }
-
- ret = bt_attributes_get_field_value_by_name(trace->environment,
+ 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);
-
-end:
- return ret;
}
int bt_trace_add_clock_class(struct bt_trace *trace,
}
bt_get(clock_class);
- g_ptr_array_add(trace->clocks, clock_class);
+ g_ptr_array_add(trace->clock_classes, clock_class);
if (trace->frozen) {
BT_LOGV_STR("Freezing added clock class because trace is frozen.");
int64_t bt_trace_get_clock_class_count(struct bt_trace *trace)
{
- int64_t ret = (int64_t) -1;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- ret = trace->clocks->len;
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return trace->clock_classes->len;
}
-struct bt_clock_class *bt_trace_get_clock_class_by_index(
+struct bt_clock_class *bt_trace_borrow_clock_class_by_index(
struct bt_trace *trace, uint64_t index)
{
- struct bt_clock_class *clock_class = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- if (index >= trace->clocks->len) {
- BT_LOGW("Invalid parameter: index is out of bounds: "
- "addr=%p, name=\"%s\", "
- "index=%" PRIu64 ", count=%u",
- trace, bt_trace_get_name(trace),
- index, trace->clocks->len);
- goto end;
- }
-
- clock_class = g_ptr_array_index(trace->clocks, index);
- bt_get(clock_class);
-end:
- return clock_class;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE(index < trace->clock_classes->len,
+ "Index is out of bounds: index=%" PRIu64 ", "
+ "count=%u",
+ index, trace->clock_classes->len);
+ return g_ptr_array_index(trace->clock_classes, index);
}
static
}
/* Packet header field type, if it exists, must be a structure */
- if (!bt_field_type_is_structure(packet_header_type)) {
+ if (packet_header_type->id != BT_FIELD_TYPE_ID_STRUCT) {
BT_LOGW("Invalid packet header field type: must be a structure field type if it exists: "
"ft-addr=%p, ft-id=%s",
packet_header_type,
- bt_field_type_id_string(packet_header_type->id));
+ bt_common_field_type_id_string(packet_header_type->id));
goto invalid;
}
* integer field type. Also it must be the first field of the
* packet header field type.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_header_type, "magic");
if (field_type) {
const char *field_name;
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet header field type: `magic` field must be an integer field type: "
"magic-ft-addr=%p, magic-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
goto invalid;
}
- ret = bt_field_type_structure_get_field_by_index(
+ ret = bt_field_type_structure_borrow_field_by_index(
packet_header_type, &field_name, NULL, 0);
BT_ASSERT(ret == 0);
field_type, field_name);
goto invalid;
}
-
- BT_PUT(field_type);
}
/*
* If there's a `uuid` field, it must be an array field type of
* length 16 with an 8-bit unsigned integer element field type.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_header_type, "uuid");
if (field_type) {
struct bt_field_type *elem_ft;
- if (!bt_field_type_is_array(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_ARRAY) {
BT_LOGW("Invalid packet header field type: `uuid` field must be an array field type: "
"uuid-ft-addr=%p, uuid-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
goto invalid;
}
- elem_ft = bt_field_type_array_get_element_type(field_type);
+ elem_ft = bt_field_type_array_borrow_element_field_type(field_type);
BT_ASSERT(elem_ft);
- if (!bt_field_type_is_integer(elem_ft)) {
+ if (elem_ft->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an integer field type: "
"elem-ft-addr=%p, elem-ft-id=%s",
elem_ft,
- bt_field_type_id_string(elem_ft->id));
- bt_put(elem_ft);
+ bt_common_field_type_id_string(elem_ft->id));
goto invalid;
}
if (bt_field_type_integer_is_signed(elem_ft)) {
BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an unsigned integer field type: "
"elem-ft-addr=%p", elem_ft);
- bt_put(elem_ft);
goto invalid;
}
"elem-ft-addr=%p, elem-ft-size=%u",
elem_ft,
bt_field_type_integer_get_size(elem_ft));
- bt_put(elem_ft);
goto invalid;
}
-
- bt_put(elem_ft);
- BT_PUT(field_type);
}
/*
* The `stream_id` field must exist if there's more than one
* stream classes in the trace.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_header_type, "stream_id");
if (!field_type && trace->stream_classes->len >= 1) {
* integer field type.
*/
if (field_type) {
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet header field type: `stream_id` field must be an integer field type: "
"stream-id-ft-addr=%p, stream-id-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
"stream-id-ft-addr=%p", field_type);
goto invalid;
}
-
- BT_PUT(field_type);
}
/*
* If there's a `packet_seq_num` field, it must be an unsigned
* integer field type.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_header_type, "packet_seq_num");
if (field_type) {
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet header field type: `packet_seq_num` field must be an integer field type: "
"stream-id-ft-addr=%p, packet-seq-num-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
"packet-seq-num-ft-addr=%p", field_type);
goto invalid;
}
-
- BT_PUT(field_type);
}
goto end;
is_valid = false;
end:
- bt_put(field_type);
return is_valid;
}
static
bool packet_context_field_type_is_valid(struct bt_trace *trace,
struct bt_stream_class *stream_class,
- struct bt_field_type *packet_context_type)
+ struct bt_field_type *packet_context_type,
+ bool check_ts_begin_end_mapped)
{
bool is_valid = true;
struct bt_field_type *field_type = NULL;
}
/* Packet context field type, if it exists, must be a structure */
- if (!bt_field_type_is_structure(packet_context_type)) {
+ if (packet_context_type->id != BT_FIELD_TYPE_ID_STRUCT) {
BT_LOGW("Invalid packet context field type: must be a structure field type if it exists: "
"ft-addr=%p, ft-id=%s",
packet_context_type,
- bt_field_type_id_string(packet_context_type->id));
+ bt_common_field_type_id_string(packet_context_type->id));
goto invalid;
}
* If there's a `packet_size` field, it must be an unsigned
* integer field type.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_context_type, "packet_size");
if (field_type) {
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet context field type: `packet_size` field must be an integer field type: "
"packet-size-ft-addr=%p, packet-size-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
"packet-size-ft-addr=%p", field_type);
goto invalid;
}
-
- BT_PUT(field_type);
}
/*
* If there's a `content_size` field, it must be an unsigned
* integer field type.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_context_type, "content_size");
if (field_type) {
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet context field type: `content_size` field must be an integer field type: "
"content-size-ft-addr=%p, content-size-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
"content-size-ft-addr=%p", field_type);
goto invalid;
}
-
- BT_PUT(field_type);
}
/*
* If there's a `events_discarded` field, it must be an unsigned
* integer field type.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_context_type, "events_discarded");
if (field_type) {
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet context field type: `events_discarded` field must be an integer field type: "
"events-discarded-ft-addr=%p, events-discarded-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
"events-discarded-ft-addr=%p", field_type);
goto invalid;
}
-
- BT_PUT(field_type);
}
/*
* trace, then we cannot automatically set the mapped clock
* class of this field, so it must have a mapped clock class.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_context_type, "timestamp_begin");
if (field_type) {
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet context field type: `timestamp_begin` field must be an integer field type: "
"timestamp-begin-ft-addr=%p, timestamp-begin-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
goto invalid;
}
- if (!trace->is_created_by_writer) {
+ if (check_ts_begin_end_mapped) {
struct bt_clock_class *clock_class =
- bt_field_type_integer_get_mapped_clock_class(
+ bt_field_type_integer_borrow_mapped_clock_class(
field_type);
- bt_put(clock_class);
if (!clock_class) {
BT_LOGW("Invalid packet context field type: `timestamp_begin` field must be mapped to a clock class: "
"timestamp-begin-ft-addr=%p", field_type);
goto invalid;
}
}
-
- BT_PUT(field_type);
}
/*
* trace, then we cannot automatically set the mapped clock
* class of this field, so it must have a mapped clock class.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
packet_context_type, "timestamp_end");
if (field_type) {
- if (!bt_field_type_is_integer(field_type)) {
+ if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) {
BT_LOGW("Invalid packet context field type: `timestamp_end` field must be an integer field type: "
"timestamp-end-ft-addr=%p, timestamp-end-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
goto invalid;
}
- if (!trace->is_created_by_writer) {
+ if (check_ts_begin_end_mapped) {
struct bt_clock_class *clock_class =
- bt_field_type_integer_get_mapped_clock_class(
+ bt_field_type_integer_borrow_mapped_clock_class(
field_type);
- bt_put(clock_class);
if (!clock_class) {
BT_LOGW("Invalid packet context field type: `timestamp_end` field must be mapped to a clock class: "
"timestamp-end-ft-addr=%p", field_type);
goto invalid;
}
}
-
- BT_PUT(field_type);
}
goto end;
is_valid = false;
end:
- bt_put(field_type);
return is_valid;
}
}
/* Event header field type, if it exists, must be a structure */
- if (!bt_field_type_is_structure(event_header_type)) {
+ if (event_header_type->id != BT_FIELD_TYPE_ID_STRUCT) {
BT_LOGW("Invalid event header field type: must be a structure field type if it exists: "
"ft-addr=%p, ft-id=%s",
event_header_type,
- bt_field_type_id_string(event_header_type->id));
+ bt_common_field_type_id_string(event_header_type->id));
goto invalid;
}
* field type or an enumeration field type with an unsigned
* integer container field type.
*/
- field_type = bt_field_type_structure_get_field_type_by_name(
+ field_type = bt_field_type_structure_borrow_field_type_by_name(
event_header_type, "id");
if (field_type) {
struct bt_field_type *int_ft;
- if (bt_field_type_is_integer(field_type)) {
- int_ft = bt_get(field_type);
- } else if (bt_field_type_is_enumeration(field_type)) {
- int_ft = bt_field_type_enumeration_get_container_type(
+ if (field_type->id == BT_FIELD_TYPE_ID_INTEGER) {
+ int_ft = field_type;
+ } else if (field_type->id == BT_FIELD_TYPE_ID_ENUM) {
+ int_ft = bt_field_type_enumeration_borrow_container_field_type(
field_type);
} else {
BT_LOGW("Invalid event header field type: `id` field must be an integer or enumeration field type: "
"id-ft-addr=%p, id-ft-id=%s",
field_type,
- bt_field_type_id_string(field_type->id));
+ bt_common_field_type_id_string(field_type->id));
goto invalid;
}
"id-ft-addr=%p", int_ft);
goto invalid;
}
-
- bt_put(int_ft);
- BT_PUT(field_type);
}
goto end;
is_valid = false;
end:
- bt_put(field_type);
return is_valid;
}
{
int ret = 0;
- if (trace->packet_header_type) {
+ if (trace->packet_header_field_type) {
struct bt_clock_class *clock_class = NULL;
- ret = bt_validate_single_clock_class(trace->packet_header_type,
+ ret = bt_field_type_validate_single_clock_class(
+ trace->packet_header_field_type,
&clock_class);
bt_put(clock_class);
if (ret || clock_class) {
goto end;
}
- if (!stream_class) {
- BT_LOGW_STR("Invalid parameter: stream class is NULL.");
+ if (trace->is_static) {
+ BT_LOGW_STR("Invalid parameter: trace is static.");
ret = -1;
goto end;
}
- if (trace->is_static) {
- BT_LOGW_STR("Invalid parameter: trace is static.");
+ if (!stream_class) {
+ BT_LOGW_STR("Invalid parameter: stream class is NULL.");
ret = -1;
goto end;
}
stream_class, bt_stream_class_get_name(stream_class),
bt_stream_class_get_id(stream_class));
- current_parent_trace = bt_stream_class_get_trace(stream_class);
+ current_parent_trace = bt_stream_class_borrow_trace(stream_class);
if (current_parent_trace) {
/* Stream class is already associated to a trace, abort. */
BT_LOGW("Invalid parameter: stream class is already part of a trace: "
bt_stream_class_get_event_class_count(stream_class);
BT_ASSERT(event_class_count >= 0);
- if (stream_class->clock) {
- struct bt_clock_class *stream_clock_class =
- stream_class->clock->clock_class;
-
- if (trace->is_created_by_writer) {
- /*
- * Make sure this clock was also added to the
- * trace (potentially through its CTF writer
- * owner).
- */
- size_t i;
-
- for (i = 0; i < trace->clocks->len; i++) {
- if (trace->clocks->pdata[i] ==
- stream_clock_class) {
- /* Found! */
- break;
- }
- }
-
- if (i == trace->clocks->len) {
- /* Not found */
- BT_LOGW("Stream class's clock's class is not part of the trace: "
- "clock-class-addr=%p, clock-class-name=\"%s\"",
- stream_clock_class,
- bt_clock_class_get_name(stream_clock_class));
- ret = -1;
- goto end;
- }
- } else {
- /*
- * This trace was NOT created by a CTF writer,
- * thus do not allow the stream class to add to
- * have a clock at all. Those are two
- * independent APIs (non-writer and writer
- * APIs), and isolating them simplifies things.
- */
- BT_LOGW("Cannot add stream class with a clock to a trace which was not created by a CTF writer object: "
- "clock-class-addr=%p, clock-class-name=\"%s\"",
- stream_clock_class,
- bt_clock_class_get_name(stream_clock_class));
- ret = -1;
- goto end;
- }
-
- if (stream_class->clock_class &&
- stream_class->clock_class !=
- stream_class->clock->clock_class) {
- /*
- * Stream class already has an expected clock
- * class, but it does not match its clock's
- * class.
- */
- BT_LOGW("Invalid parameter: stream class's clock's "
- "class does not match stream class's "
- "expected clock class: "
- "stream-class-addr=%p, "
- "stream-class-id=%" PRId64 ", "
- "stream-class-name=\"%s\", "
- "expected-clock-class-addr=%p, "
- "expected-clock-class-name=\"%s\"",
- stream_class,
- bt_stream_class_get_id(stream_class),
- bt_stream_class_get_name(stream_class),
- expected_clock_class,
- bt_clock_class_get_name(expected_clock_class));
- } else if (!stream_class->clock_class) {
- /*
- * Set expected clock class to stream class's
- * clock's class.
- */
- expected_clock_class =
- bt_get(stream_class->clock->clock_class);
- }
- }
-
if (!stream_class->frozen) {
/*
* Stream class is not frozen yet. Validate that the
* stream class contains at most a single clock class
* because the previous
- * bt_stream_class_add_event_class() calls did not make
- * this validation since the stream class's direct field
- * types (packet context, event header, event context)
- * could change afterwards. This stream class is about
- * to be frozen and those field types won't be changed
- * if this function succeeds.
+ * bt_stream_class_add_event_class() calls did
+ * not make this validation since the stream class's
+ * direct field types (packet context, event header,
+ * event context) could change afterwards. This stream
+ * class is about to be frozen and those field types
+ * won't be changed if this function succeeds.
*
* At this point we're also sure that the stream class's
* clock, if any, has the same class as the stream
* function is safe because it maps to the same, single
* clock class.
*/
- ret = bt_stream_class_validate_single_clock_class(stream_class,
- &expected_clock_class);
+ ret = bt_stream_class_validate_single_clock_class(
+ stream_class, &expected_clock_class);
if (ret) {
BT_LOGW("Invalid parameter: stream class or one of its "
"event classes contains a field type which is "
* class of this stream class can be validated individually.
*/
packet_header_type =
- bt_trace_get_packet_header_type(trace);
+ bt_trace_borrow_packet_header_field_type(trace);
packet_context_type =
- bt_stream_class_get_packet_context_type(stream_class);
+ bt_stream_class_borrow_packet_context_field_type(stream_class);
event_header_type =
- bt_stream_class_get_event_header_type(stream_class);
+ bt_stream_class_borrow_event_header_field_type(stream_class);
stream_event_ctx_type =
- bt_stream_class_get_event_context_type(stream_class);
+ bt_stream_class_borrow_event_context_field_type(stream_class);
BT_LOGD("Validating trace and stream class field types.");
ret = bt_validate_class_types(trace->environment,
packet_header_type, packet_context_type, event_header_type,
stream_event_ctx_type, NULL, NULL, trace->valid,
stream_class->valid, 1, &trace_sc_validation_output,
- trace_sc_validation_flags);
- BT_PUT(packet_header_type);
- BT_PUT(packet_context_type);
- BT_PUT(event_header_type);
- BT_PUT(stream_event_ctx_type);
+ trace_sc_validation_flags, bt_field_type_copy);
if (ret) {
/*
/* Validate each event class individually */
for (i = 0; i < event_class_count; i++) {
struct bt_event_class *event_class =
- bt_stream_class_get_event_class_by_index(
+ bt_stream_class_borrow_event_class_by_index(
stream_class, i);
struct bt_field_type *event_context_type = NULL;
struct bt_field_type *event_payload_type = NULL;
event_context_type =
- bt_event_class_get_context_type(event_class);
+ bt_event_class_borrow_context_field_type(
+ event_class);
event_payload_type =
- bt_event_class_get_payload_type(event_class);
+ bt_event_class_borrow_payload_field_type(
+ event_class);
/*
* It is important to use the field types returned by
trace_sc_validation_output.stream_event_ctx_type,
event_context_type, event_payload_type,
1, 1, event_class->valid, &ec_validation_outputs[i],
- ec_validation_flags);
- BT_PUT(event_context_type);
- BT_PUT(event_payload_type);
- BT_PUT(event_class);
+ ec_validation_flags, bt_field_type_copy);
if (ret) {
BT_LOGE("Failed to validate event class field types: "
if (!packet_context_field_type_is_valid(trace,
stream_class,
- trace_sc_validation_output.packet_context_type)) {
+ trace_sc_validation_output.packet_context_type, true)) {
BT_LOGW_STR("Invalid stream class's packet context field type.");
ret = -1;
goto end;
goto end;
}
- /*
- * Now is the time to automatically map specific field types of
- * the stream class's packet context and event header field
- * types to the stream class's clock's class if they are not
- * mapped to a clock class yet. We do it here because we know
- * that after this point, everything is frozen so it won't be
- * possible for the user to modify the stream class's clock, or
- * to map those field types to other clock classes.
- */
- if (trace->is_created_by_writer) {
- if (bt_stream_class_map_clock_class(stream_class,
- trace_sc_validation_output.packet_context_type,
- trace_sc_validation_output.event_header_type)) {
- BT_LOGW_STR("Cannot automatically map selected stream class's field types to stream class's clock's class.");
- ret = -1;
- goto end;
- }
- }
-
- bt_object_set_parent(stream_class, trace);
+ bt_object_set_parent(&stream_class->base, &trace->base);
g_ptr_array_add(trace->stream_classes, stream_class);
/*
for (i = 0; i < event_class_count; i++) {
struct bt_event_class *event_class =
- bt_stream_class_get_event_class_by_index(
+ bt_stream_class_borrow_event_class_by_index(
stream_class, i);
bt_validation_replace_types(NULL, NULL, event_class,
&ec_validation_outputs[i], ec_validation_flags);
event_class->valid = 1;
- BT_PUT(event_class);
/*
* Put what was not moved in
BT_MOVE(stream_class->clock_class, expected_clock_class);
}
- /* Notifiy listeners of the trace's schema modification. */
+ /* Notify listeners of the trace's schema modification. */
bt_stream_class_visit(stream_class,
bt_trace_object_modification, trace);
BT_LOGD("Added stream class to trace: "
end:
if (ret) {
- bt_object_set_parent(stream_class, NULL);
+ bt_object_set_parent(&stream_class->base, NULL);
if (ec_validation_outputs) {
for (i = 0; i < event_class_count; i++) {
g_free(ec_validation_outputs);
bt_validation_output_put_types(&trace_sc_validation_output);
- bt_put(current_parent_trace);
bt_put(expected_clock_class);
- BT_ASSERT(!packet_header_type);
- BT_ASSERT(!packet_context_type);
- BT_ASSERT(!event_header_type);
- BT_ASSERT(!stream_event_ctx_type);
return ret;
}
int64_t bt_trace_get_stream_count(struct bt_trace *trace)
{
- int64_t ret;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- ret = (int64_t) -1;
- goto end;
- }
-
- ret = (int64_t) trace->streams->len;
-
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return (int64_t) trace->streams->len;
}
-struct bt_stream *bt_trace_get_stream_by_index(
- struct bt_trace *trace,
- uint64_t index)
+struct bt_stream *bt_trace_borrow_stream_by_index(
+ struct bt_trace *trace, uint64_t index)
{
- struct bt_stream *stream = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- if (index >= trace->streams->len) {
- BT_LOGW("Invalid parameter: index is out of bounds: "
- "addr=%p, name=\"%s\", "
- "index=%" PRIu64 ", count=%u",
- trace, bt_trace_get_name(trace),
- index, trace->streams->len);
- goto end;
- }
-
- stream = bt_get(g_ptr_array_index(trace->streams, index));
-
-end:
- return stream;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE(index < trace->streams->len,
+ "Index is out of bounds: index=%" PRIu64 ", "
+ "count=%u",
+ index, trace->streams->len);
+ return g_ptr_array_index(trace->streams, index);
}
int64_t bt_trace_get_stream_class_count(struct bt_trace *trace)
{
- int64_t ret;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- ret = (int64_t) -1;
- goto end;
- }
-
- ret = (int64_t) trace->stream_classes->len;
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return (int64_t) trace->stream_classes->len;
}
-struct bt_stream_class *bt_trace_get_stream_class_by_index(
+struct bt_stream_class *bt_trace_borrow_stream_class_by_index(
struct bt_trace *trace, uint64_t index)
{
- struct bt_stream_class *stream_class = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- if (index >= trace->stream_classes->len) {
- BT_LOGW("Invalid parameter: index is out of bounds: "
- "addr=%p, name=\"%s\", "
- "index=%" PRIu64 ", count=%u",
- trace, bt_trace_get_name(trace),
- index, trace->stream_classes->len);
- goto end;
- }
-
- stream_class = g_ptr_array_index(trace->stream_classes, index);
- bt_get(stream_class);
-end:
- return stream_class;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE(index < trace->stream_classes->len,
+ "Index is out of bounds: index=%" PRIu64 ", "
+ "count=%u",
+ index, trace->stream_classes->len);
+ return g_ptr_array_index(trace->stream_classes, index);
}
-struct bt_stream_class *bt_trace_get_stream_class_by_id(
+struct bt_stream_class *bt_trace_borrow_stream_class_by_id(
struct bt_trace *trace, uint64_t id_param)
{
int i;
struct bt_stream_class *stream_class = NULL;
int64_t id = (int64_t) id_param;
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- if (id < 0) {
- BT_LOGW("Invalid parameter: invalid stream class's ID: "
- "trace-addr=%p, trace-name=\"%s\", id=%" PRIu64,
- trace, bt_trace_get_name(trace), id_param);
- goto end;
- }
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE(id >= 0,
+ "Invalid stream class ID: %" PRIu64, id_param);
for (i = 0; i < trace->stream_classes->len; i++) {
struct bt_stream_class *stream_class_candidate;
if (bt_stream_class_get_id(stream_class_candidate) ==
(int64_t) id) {
stream_class = stream_class_candidate;
- bt_get(stream_class);
goto end;
}
}
return stream_class;
}
-struct bt_clock_class *bt_trace_get_clock_class_by_name(
+struct bt_clock_class *bt_trace_borrow_clock_class_by_name(
struct bt_trace *trace, const char *name)
{
size_t i;
struct bt_clock_class *clock_class = NULL;
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- if (!name) {
- BT_LOGW_STR("Invalid parameter: name is NULL.");
- goto end;
- }
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE_NON_NULL(name, "Name");
- for (i = 0; i < trace->clocks->len; i++) {
+ for (i = 0; i < trace->clock_classes->len; i++) {
struct bt_clock_class *cur_clk =
- g_ptr_array_index(trace->clocks, i);
+ g_ptr_array_index(trace->clock_classes, i);
const char *cur_clk_name = bt_clock_class_get_name(cur_clk);
if (!cur_clk_name) {
if (!strcmp(cur_clk_name, name)) {
clock_class = cur_clk;
- bt_get(clock_class);
goto end;
}
}
BT_ASSERT(trace);
BT_ASSERT(clock_class);
- g_ptr_array_foreach(trace->clocks, value_exists, &query);
+ g_ptr_array_foreach(trace->clock_classes, value_exists, &query);
return query.found;
}
-BT_HIDDEN
-const char *get_byte_order_string(enum bt_byte_order byte_order)
-{
- const char *string;
-
- switch (byte_order) {
- case BT_BYTE_ORDER_LITTLE_ENDIAN:
- string = "le";
- break;
- case BT_BYTE_ORDER_BIG_ENDIAN:
- string = "be";
- break;
- case BT_BYTE_ORDER_NATIVE:
- string = "native";
- break;
- default:
- abort();
- }
-
- return string;
-}
-
-static
-int append_trace_metadata(struct bt_trace *trace,
- struct metadata_context *context)
-{
- unsigned char *uuid = trace->uuid;
- int ret = 0;
-
- if (trace->native_byte_order == BT_BYTE_ORDER_NATIVE ||
- trace->native_byte_order == BT_BYTE_ORDER_UNSPECIFIED) {
- BT_LOGW("Invalid parameter: trace's byte order cannot be BT_BYTE_ORDER_NATIVE or BT_BYTE_ORDER_UNSPECIFIED at this point; "
- "set it with bt_trace_set_native_byte_order(): "
- "addr=%p, name=\"%s\"",
- trace, bt_trace_get_name(trace));
- ret = -1;
- goto end;
- }
-
- g_string_append(context->string, "trace {\n");
- g_string_append(context->string, "\tmajor = 1;\n");
- g_string_append(context->string, "\tminor = 8;\n");
- BT_ASSERT(trace->native_byte_order == BT_BYTE_ORDER_LITTLE_ENDIAN ||
- trace->native_byte_order == BT_BYTE_ORDER_BIG_ENDIAN ||
- trace->native_byte_order == BT_BYTE_ORDER_NETWORK);
-
- if (trace->uuid_set) {
- g_string_append_printf(context->string,
- "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
- uuid[0], uuid[1], uuid[2], uuid[3],
- uuid[4], uuid[5], uuid[6], uuid[7],
- uuid[8], uuid[9], uuid[10], uuid[11],
- uuid[12], uuid[13], uuid[14], uuid[15]);
- }
-
- g_string_append_printf(context->string, "\tbyte_order = %s;\n",
- get_byte_order_string(trace->native_byte_order));
-
- if (trace->packet_header_type) {
- g_string_append(context->string, "\tpacket.header := ");
- context->current_indentation_level++;
- g_string_assign(context->field_name, "");
- BT_LOGD_STR("Serializing trace's packet header field type's metadata.");
- ret = bt_field_type_serialize(trace->packet_header_type,
- context);
- if (ret) {
- goto end;
- }
- context->current_indentation_level--;
- }
-
- g_string_append(context->string, ";\n};\n\n");
-end:
- return ret;
-}
-
-static
-void append_env_metadata(struct bt_trace *trace,
- struct metadata_context *context)
-{
- int64_t i;
- int64_t env_size;
-
- env_size = bt_attributes_get_count(trace->environment);
- if (env_size <= 0) {
- return;
- }
-
- g_string_append(context->string, "env {\n");
-
- for (i = 0; i < env_size; i++) {
- struct bt_value *env_field_value_obj = NULL;
- const char *entry_name;
-
- entry_name = bt_attributes_get_field_name(
- trace->environment, i);
- env_field_value_obj = bt_attributes_get_field_value(
- trace->environment, i);
-
- BT_ASSERT(entry_name);
- BT_ASSERT(env_field_value_obj);
-
- switch (bt_value_get_type(env_field_value_obj)) {
- case BT_VALUE_TYPE_INTEGER:
- {
- int ret;
- int64_t int_value;
-
- ret = bt_value_integer_get(env_field_value_obj,
- &int_value);
- BT_ASSERT(ret == 0);
- g_string_append_printf(context->string,
- "\t%s = %" PRId64 ";\n", entry_name,
- int_value);
- break;
- }
- case BT_VALUE_TYPE_STRING:
- {
- int ret;
- const char *str_value;
- char *escaped_str = NULL;
-
- ret = bt_value_string_get(env_field_value_obj,
- &str_value);
- BT_ASSERT(ret == 0);
- escaped_str = g_strescape(str_value, NULL);
- if (!escaped_str) {
- BT_LOGE("Cannot escape string: string=\"%s\"",
- str_value);
- goto loop_next;
- }
-
- g_string_append_printf(context->string,
- "\t%s = \"%s\";\n", entry_name, escaped_str);
- free(escaped_str);
- break;
- }
- default:
- goto loop_next;
- }
-
-loop_next:
- BT_PUT(env_field_value_obj);
- }
-
- g_string_append(context->string, "};\n\n");
-}
-
-char *bt_trace_get_metadata_string(struct bt_trace *trace)
-{
- char *metadata = NULL;
- struct metadata_context *context = NULL;
- int err = 0;
- size_t i;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- context = g_new0(struct metadata_context, 1);
- if (!context) {
- BT_LOGE_STR("Failed to allocate one metadata context.");
- goto end;
- }
-
- context->field_name = g_string_sized_new(DEFAULT_IDENTIFIER_SIZE);
- context->string = g_string_sized_new(DEFAULT_METADATA_STRING_SIZE);
- g_string_append(context->string, "/* CTF 1.8 */\n\n");
- if (append_trace_metadata(trace, context)) {
- /* append_trace_metadata() logs errors */
- goto error;
- }
- append_env_metadata(trace, context);
- g_ptr_array_foreach(trace->clocks,
- (GFunc)bt_clock_class_serialize, context);
-
- for (i = 0; i < trace->stream_classes->len; i++) {
- /* bt_stream_class_serialize() logs details */
- err = bt_stream_class_serialize(
- trace->stream_classes->pdata[i], context);
- if (err) {
- /* bt_stream_class_serialize() logs errors */
- goto error;
- }
- }
-
- metadata = context->string->str;
-
-error:
- g_string_free(context->string, err ? TRUE : FALSE);
- g_string_free(context->field_name, TRUE);
- g_free(context);
-
-end:
- return metadata;
-}
-
enum bt_byte_order bt_trace_get_native_byte_order(
struct bt_trace *trace)
{
- enum bt_byte_order ret = BT_BYTE_ORDER_UNKNOWN;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- ret = trace->native_byte_order;
-
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return trace->native_byte_order;
}
int bt_trace_set_native_byte_order(struct bt_trace *trace,
goto end;
}
- if (trace->is_created_by_writer &&
- byte_order == BT_BYTE_ORDER_UNSPECIFIED) {
- BT_LOGW("Invalid parameter: BT_BYTE_ORDER_UNSPECIFIED byte order is not allowed for a CTF writer trace: "
- "addr=%p, name=\"%s\"",
- trace, bt_trace_get_name(trace));
- ret = -1;
- goto end;
- }
-
if (byte_order != BT_BYTE_ORDER_LITTLE_ENDIAN &&
byte_order != BT_BYTE_ORDER_BIG_ENDIAN &&
byte_order != BT_BYTE_ORDER_NETWORK) {
BT_LOGW("Invalid parameter: invalid byte order: "
"addr=%p, name=\"%s\", bo=%s",
trace, bt_trace_get_name(trace),
- bt_byte_order_string(byte_order));
+ bt_common_byte_order_string(byte_order));
ret = -1;
goto end;
}
BT_LOGV("Set trace's native byte order: "
"addr=%p, name=\"%s\", bo=%s",
trace, bt_trace_get_name(trace),
- bt_byte_order_string(byte_order));
+ bt_common_byte_order_string(byte_order));
end:
return ret;
}
-struct bt_field_type *bt_trace_get_packet_header_type(
+struct bt_field_type *bt_trace_borrow_packet_header_field_type(
struct bt_trace *trace)
{
- struct bt_field_type *field_type = NULL;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- bt_get(trace->packet_header_type);
- field_type = trace->packet_header_type;
-end:
- return field_type;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return trace->packet_header_field_type;
}
-int bt_trace_set_packet_header_type(struct bt_trace *trace,
+int bt_trace_set_packet_header_field_type(struct bt_trace *trace,
struct bt_field_type *packet_header_type)
{
int ret = 0;
/* packet_header_type must be a structure. */
if (packet_header_type &&
- !bt_field_type_is_structure(packet_header_type)) {
+ packet_header_type->id != BT_FIELD_TYPE_ID_STRUCT) {
BT_LOGW("Invalid parameter: packet header field type must be a structure field type if it exists: "
"addr=%p, name=\"%s\", ft-addr=%p, ft-id=%s",
trace, bt_trace_get_name(trace),
packet_header_type,
- bt_field_type_id_string(packet_header_type->id));
+ bt_common_field_type_id_string(packet_header_type->id));
ret = -1;
goto end;
}
- bt_put(trace->packet_header_type);
- trace->packet_header_type = bt_get(packet_header_type);
+ bt_put(trace->packet_header_field_type);
+ trace->packet_header_field_type = bt_get(packet_header_type);
BT_LOGV("Set trace's packet header field type: "
"addr=%p, name=\"%s\", packet-context-ft-addr=%p",
trace, bt_trace_get_name(trace), packet_header_type);
return 0;
}
-BT_HIDDEN
-struct bt_field_type *get_field_type(enum field_type_alias alias)
-{
- int ret;
- unsigned int alignment, size;
- struct bt_field_type *field_type = NULL;
-
- if (alias >= NR_FIELD_TYPE_ALIAS) {
- goto end;
- }
-
- alignment = field_type_aliases_alignments[alias];
- size = field_type_aliases_sizes[alias];
- field_type = bt_field_type_integer_create(size);
- ret = bt_field_type_set_alignment(field_type, alignment);
- if (ret) {
- BT_PUT(field_type);
- }
-end:
- return field_type;
-}
-
-static
-void bt_trace_freeze(struct bt_trace *trace)
-{
- int i;
-
- if (trace->frozen) {
- return;
- }
-
- BT_LOGD("Freezing trace: addr=%p, name=\"%s\"",
- trace, bt_trace_get_name(trace));
- BT_LOGD_STR("Freezing packet header field type.");
- bt_field_type_freeze(trace->packet_header_type);
- BT_LOGD_STR("Freezing environment attributes.");
- bt_attributes_freeze(trace->environment);
-
- if (trace->clocks->len > 0) {
- BT_LOGD_STR("Freezing clock classes.");
- }
-
- for (i = 0; i < trace->clocks->len; i++) {
- struct bt_clock_class *clock_class =
- g_ptr_array_index(trace->clocks, i);
-
- bt_clock_class_freeze(clock_class);
- }
-
- trace->frozen = 1;
-}
-
bt_bool bt_trace_is_static(struct bt_trace *trace)
{
- bt_bool is_static = BT_FALSE;
-
- if (!trace) {
- BT_LOGW_STR("Invalid parameter: trace is NULL.");
- goto end;
- }
-
- is_static = trace->is_static;
-
-end:
- return is_static;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ return trace->is_static;
}
int bt_trace_set_is_static(struct bt_trace *trace)
end:
return ret;
}
+
+struct bt_packet_header_field *bt_trace_create_packet_header_field(
+ struct bt_trace *trace)
+{
+ struct bt_field_wrapper *field_wrapper;
+
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE(trace->packet_header_field_type,
+ "Trace has no packet header field type: %!+t",
+ trace);
+ field_wrapper = bt_field_wrapper_create(
+ &trace->packet_header_field_pool,
+ (void *) trace->packet_header_field_type);
+ if (!field_wrapper) {
+ BT_LIB_LOGE("Cannot allocate one packet header field from trace: "
+ "%![trace-]+t", trace);
+ goto error;
+ }
+
+ BT_ASSERT(field_wrapper->field);
+ bt_trace_freeze(trace);
+ goto end;
+
+error:
+ if (field_wrapper) {
+ bt_field_wrapper_destroy(field_wrapper);
+ field_wrapper = NULL;
+ }
+
+end:
+ return (void *) field_wrapper;
+}