* Visitor context (private).
*/
struct ctx {
- /* Trace IR trace being filled (owned by this) */
- struct bt_trace *trace;
+ /* Trace IR trace class being filled (owned by this) */
+ bt_trace_class *trace_class;
/* CTF meta trace being filled (owned by this) */
struct ctf_trace_class *ctf_tc;
/* True if this is an LTTng trace */
bool is_lttng;
- /* Eventual name suffix of the trace to set (owned by this) */
- char *trace_class_name_suffix;
-
/* Config passed by the user */
struct ctf_metadata_decoder_config decoder_config;
};
scope = parent_scope;
}
- bt_put(ctx->trace);
+ bt_trace_class_put_ref(ctx->trace_class);
if (ctx->ctf_tc) {
ctf_trace_class_destroy(ctx->ctf_tc);
}
- if (ctx->trace_class_name_suffix) {
- free(ctx->trace_class_name_suffix);
- }
-
g_free(ctx);
end:
* @returns New visitor context, or NULL on error
*/
static
-struct ctx *ctx_create(const struct ctf_metadata_decoder_config *decoder_config,
- const char *trace_class_name_suffix)
+struct ctx *ctx_create(
+ const struct ctf_metadata_decoder_config *decoder_config)
{
struct ctx *ctx = NULL;
goto error;
}
- ctx->trace = bt_trace_create();
- if (!ctx->trace) {
- BT_LOGE_STR("Cannot create empty trace.");
+ ctx->trace_class = bt_trace_class_create();
+ if (!ctx->trace_class) {
+ BT_LOGE_STR("Cannot create empty trace class.");
goto error;
}
goto error;
}
- if (trace_class_name_suffix) {
- ctx->trace_class_name_suffix = strdup(trace_class_name_suffix);
- if (!ctx->trace_class_name_suffix) {
- BT_LOGE_STR("Failed to copy string.");
- goto error;
- }
- }
-
ctx->decoder_config = *decoder_config;
goto end;
goto error;
}
- if (nested_decl->id == CTF_FIELD_CLASS_ID_INT) {
+ if (nested_decl->type == CTF_FIELD_CLASS_TYPE_INT) {
/* Pointer: force integer's base to 16 */
struct ctf_field_class_int *int_fc =
(void *) nested_decl;
}
/* Do not allow field class def and alias of untagged variants */
- if (class_decl->id == CTF_FIELD_CLASS_ID_VARIANT) {
+ if (class_decl->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
struct ctf_field_class_variant *var_fc =
(void *) class_decl;
}
/* Do not allow field class def and alias of untagged variants */
- if (class_decl->id == CTF_FIELD_CLASS_ID_VARIANT) {
+ if (class_decl->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
struct ctf_field_class_variant *var_fc = (void *) class_decl;
if (var_fc->tag_path.path->len == 0) {
BT_ASSERT(integer_decl);
- if (integer_decl->base.base.id != CTF_FIELD_CLASS_ID_INT) {
+ if (integer_decl->base.base.type != CTF_FIELD_CLASS_TYPE_INT) {
BT_LOGE("Container field class for enumeration field class is not an integer field class: "
- "fc-id=%d", integer_decl->base.base.id);
+ "fc-type=%d", integer_decl->base.base.type);
ret = -EINVAL;
goto error;
}
int signedness = 0;
struct ctf_node *expression;
uint64_t alignment = 0, size = 0;
- struct bt_clock_class *mapped_clock_class = NULL;
+ bt_clock_class *mapped_clock_class = NULL;
enum ctf_encoding encoding = CTF_ENCODING_NONE;
- enum bt_field_class_integer_preferred_display_base base =
+ bt_field_class_integer_preferred_display_base base =
BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
enum ctf_byte_order byte_order = ctx->ctf_tc->default_byte_order;
(*integer_decl)->is_signed = (signedness > 0);
(*integer_decl)->disp_base = base;
(*integer_decl)->encoding = encoding;
- (*integer_decl)->mapped_clock_class = bt_get(mapped_clock_class);
+ (*integer_decl)->mapped_clock_class = mapped_clock_class;
+ bt_clock_class_get_ref((*integer_decl)->mapped_clock_class);
return 0;
error:
_SET(set, _EVENT_FIELDS_SET);
} else if (!strcmp(left, "loglevel")) {
uint64_t loglevel_value;
- enum bt_event_class_log_level log_level = -1;
+ bt_event_class_log_level log_level = -1;
if (_IS_SET(set, _EVENT_LOG_LEVEL_SET)) {
_BT_LOGE_DUP_ATTR(node, "loglevel",
int auto_map_field_to_trace_clock_class(struct ctx *ctx,
struct ctf_field_class *fc)
{
- struct bt_clock_class *clock_class_to_map_to = NULL;
+ bt_clock_class *clock_class_to_map_to = NULL;
struct ctf_field_class_int *int_fc = (void *) fc;
int ret = 0;
uint64_t clock_class_count;
goto end;
}
- if (fc->id != CTF_FIELD_CLASS_ID_INT &&
- fc->id != CTF_FIELD_CLASS_ID_ENUM) {
+ if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
+ fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
goto end;
}
*/
clock_class_to_map_to = bt_clock_class_create();
BT_ASSERT(clock_class_to_map_to);
- ret = bt_clock_class_set_frequency(clock_class_to_map_to,
+ bt_clock_class_set_frequency(clock_class_to_map_to,
UINT64_C(1000000000));
- BT_ASSERT(ret == 0);
ret = bt_clock_class_set_name(clock_class_to_map_to,
"default");
BT_ASSERT(ret == 0);
g_ptr_array_add(ctx->ctf_tc->clock_classes,
- bt_get(clock_class_to_map_to));
+ clock_class_to_map_to);
+ bt_clock_class_get_ref(clock_class_to_map_to);
break;
case 1:
/*
* Only one clock class exists in the trace at this point: use
* this one.
*/
- clock_class_to_map_to =
- bt_get(ctx->ctf_tc->clock_classes->pdata[0]);
+ clock_class_to_map_to = ctx->ctf_tc->clock_classes->pdata[0];
+ bt_clock_class_get_ref(clock_class_to_map_to);
break;
default:
/*
}
BT_ASSERT(clock_class_to_map_to);
- int_fc->mapped_clock_class = bt_get(clock_class_to_map_to);
+ int_fc->mapped_clock_class = clock_class_to_map_to;
+ bt_clock_class_get_ref(int_fc->mapped_clock_class);
end:
- bt_put(clock_class_to_map_to);
+ bt_clock_class_put_ref(clock_class_to_map_to);
return ret;
}
goto end;
}
- if (root_fc->id != CTF_FIELD_CLASS_ID_STRUCT &&
- root_fc->id != CTF_FIELD_CLASS_ID_VARIANT) {
+ if (root_fc->type != CTF_FIELD_CLASS_TYPE_STRUCT &&
+ root_fc->type != CTF_FIELD_CLASS_TYPE_VARIANT) {
goto end;
}
- if (root_fc->id == CTF_FIELD_CLASS_ID_STRUCT) {
+ if (root_fc->type == CTF_FIELD_CLASS_TYPE_STRUCT) {
count = struct_fc->members->len;
} else {
count = var_fc->options->len;
for (i = 0; i < count; i++) {
struct ctf_named_field_class *named_fc = NULL;
- if (root_fc->id == CTF_FIELD_CLASS_ID_STRUCT) {
+ if (root_fc->type == CTF_FIELD_CLASS_TYPE_STRUCT) {
named_fc = ctf_field_class_struct_borrow_member_by_index(
struct_fc, i);
- } else if (root_fc->id == CTF_FIELD_CLASS_ID_VARIANT) {
+ } else if (root_fc->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
named_fc = ctf_field_class_variant_borrow_option_by_index(
var_fc, i);
}
goto error;
}
- if (named_fc->fc->id != CTF_FIELD_CLASS_ID_INT &&
- named_fc->fc->id != CTF_FIELD_CLASS_ID_ENUM) {
+ if (named_fc->fc->type != CTF_FIELD_CLASS_TYPE_INT &&
+ named_fc->fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
_BT_LOGE_NODE(node,
"Stream class has a `id` attribute, "
"but trace's packet header field class's `stream_id` field is not an integer field class.");
static
int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
- struct bt_clock_class *clock, int *set, int64_t *offset_seconds,
+ bt_clock_class *clock, int *set, int64_t *offset_seconds,
uint64_t *offset_cycles)
{
int ret = 0;
goto error;
}
- ret = bt_clock_class_set_uuid(clock, uuid);
- if (ret) {
- _BT_LOGE_NODE(entry_node,
- "Cannot set clock class's UUID.");
- goto error;
- }
-
+ bt_clock_class_set_uuid(clock, uuid);
_SET(set, _CLOCK_UUID_SET);
} else if (!strcmp(left, "description")) {
char *right;
goto error;
}
- ret = bt_clock_class_set_frequency(clock, freq);
- if (ret) {
- _BT_LOGE_NODE(entry_node,
- "Cannot set clock class's frequency.");
- goto error;
- }
-
+ bt_clock_class_set_frequency(clock, freq);
_SET(set, _CLOCK_FREQ_SET);
} else if (!strcmp(left, "precision")) {
uint64_t precision;
goto error;
}
- ret = bt_clock_class_set_precision(clock, precision);
- if (ret) {
- _BT_LOGE_NODE(entry_node,
- "Cannot set clock class's precision.");
- goto error;
- }
-
+ bt_clock_class_set_precision(clock, precision);
_SET(set, _CLOCK_PRECISION_SET);
} else if (!strcmp(left, "offset_s")) {
if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) {
goto error;
}
- ret = bt_clock_class_set_is_absolute(clock, ret);
- if (ret) {
- _BT_LOGE_NODE(entry_node,
- "Cannot set clock class's absolute flag.");
- goto error;
- }
-
+ bt_clock_class_set_is_absolute(clock, ret);
_SET(set, _CLOCK_ABSOLUTE_SET);
} else {
_BT_LOGW_NODE(entry_node,
}
static
-void apply_clock_class_offset(struct ctx *ctx, struct bt_clock_class *clock)
+void apply_clock_class_offset(struct ctx *ctx,
+ bt_clock_class *clock)
{
- int ret;
uint64_t freq;
int64_t offset_s_to_apply = ctx->decoder_config.clock_class_offset_s;
uint64_t offset_ns_to_apply;
}
freq = bt_clock_class_get_frequency(clock);
- bt_clock_class_get_offset(clock, &cur_offset_s, &cur_offset_cycles);
+ bt_clock_class_get_offset(clock,
+ &cur_offset_s, &cur_offset_cycles);
/* Apply offsets */
cur_offset_s += offset_s_to_apply;
calibrate_clock_class_offsets(&cur_offset_s, &cur_offset_cycles, freq);
/* Set final offsets */
- ret = bt_clock_class_set_offset(clock, cur_offset_s, cur_offset_cycles);
- BT_ASSERT(ret == 0);
+ bt_clock_class_set_offset(clock, cur_offset_s, cur_offset_cycles);
end:
return;
{
int ret = 0;
int set = 0;
- struct bt_clock_class *clock;
+ bt_clock_class *clock;
struct ctf_node *entry_node;
struct bt_list_head *decl_list = &clock_node->u.clock.declaration_list;
const char *clock_class_name;
}
/* CTF: not absolute by default */
- ret = bt_clock_class_set_is_absolute(clock, BT_FALSE);
- if (ret) {
- _BT_LOGE_NODE(clock_node,
- "Cannot set clock class's absolute flag.");
- goto end;
- }
+ bt_clock_class_set_is_absolute(clock, BT_FALSE);
bt_list_for_each_entry(entry_node, decl_list, siblings) {
ret = visit_clock_decl_entry(ctx, entry_node, clock, &set,
/*
* Old versions of LTTng forgot to set its clock class
* as absolute, even if it is. This is important because
- * it's a condition to be able to sort notifications
+ * it's a condition to be able to sort messages
* from different sources.
*/
- ret = bt_clock_class_set_is_absolute(clock, BT_TRUE);
- if (ret) {
- _BT_LOGE_NODE(clock_node,
- "Cannot set clock class's absolute flag.");
- goto end;
- }
+ bt_clock_class_set_is_absolute(clock, BT_TRUE);
}
/*
freq = bt_clock_class_get_frequency(clock);
calibrate_clock_class_offsets(&offset_seconds, &offset_cycles, freq);
BT_ASSERT(offset_cycles < bt_clock_class_get_frequency(clock));
- ret = bt_clock_class_set_offset(clock, offset_seconds, offset_cycles);
- BT_ASSERT(ret == 0);
+ bt_clock_class_set_offset(clock, offset_seconds, offset_cycles);
apply_clock_class_offset(ctx, clock);
- g_ptr_array_add(ctx->ctf_tc->clock_classes, bt_get(clock));
+ g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);
+ bt_clock_class_get_ref(clock);
end:
- BT_PUT(clock);
+ BT_CLOCK_CLASS_PUT_REF_AND_RESET(clock);
return ret;
}
return ret;
}
-static
-int try_set_trace_class_name(struct ctx *ctx)
-{
- GString *name = NULL;
- int ret = 0;
- struct ctf_trace_class_env_entry *env_entry;
-
- if (ctx->ctf_tc->name->len > 0) {
- /* Already set */
- goto end;
- }
-
- name = g_string_new(NULL);
- if (!name) {
- BT_LOGE_STR("Failed to allocate a GString.");
- ret = -1;
- goto end;
- }
-
- /*
- * Check if we have a trace environment string value named `hostname`.
- * If so, use it as the trace name's prefix.
- */
- env_entry = ctf_trace_class_borrow_env_entry_by_name(ctx->ctf_tc,
- "hostname");
- if (env_entry &&
- env_entry->type == CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR) {
- g_string_append(name, env_entry->value.str->str);
-
- if (ctx->trace_class_name_suffix) {
- g_string_append_c(name, G_DIR_SEPARATOR);
- }
- }
-
- if (ctx->trace_class_name_suffix) {
- g_string_append(name, ctx->trace_class_name_suffix);
- }
-
- g_string_assign(ctx->ctf_tc->name, name->str);
- goto end;
-
-end:
- if (name) {
- g_string_free(name, TRUE);
- }
-
- return ret;
-}
-
BT_HIDDEN
struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
- const struct ctf_metadata_decoder_config *decoder_config,
- const char *name)
+ const struct ctf_metadata_decoder_config *decoder_config)
{
struct ctx *ctx = NULL;
/* Create visitor's context */
- ctx = ctx_create(decoder_config, name);
+ ctx = ctx_create(decoder_config);
if (!ctx) {
BT_LOGE_STR("Cannot create visitor's context.");
goto error;
}
BT_HIDDEN
-struct bt_trace *ctf_visitor_generate_ir_get_ir_trace(
+bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(
struct ctf_visitor_generate_ir *visitor)
{
struct ctx *ctx = (void *) visitor;
BT_ASSERT(ctx);
- BT_ASSERT(ctx->trace);
- return bt_get(ctx->trace);
+ BT_ASSERT(ctx->trace_class);
+ bt_trace_class_get_ref(ctx->trace_class);
+ return ctx->trace_class;
}
BT_HIDDEN
goto end;
}
- /* Set trace's name, if not already done */
- ret = try_set_trace_class_name(ctx);
- if (ret) {
- ret = -EINVAL;
- goto end;
- }
-
/* Update trace class meanings */
ret = ctf_trace_class_update_meanings(ctx->ctf_tc);
if (ret) {
}
/* Copy new CTF metadata -> new IR metadata */
- ret = ctf_trace_class_translate(ctx->trace, ctx->ctf_tc);
+ ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc);
if (ret) {
ret = -EINVAL;
goto end;