X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fctf%2Fcommon%2Fmetadata%2Fvisitor-generate-ir.c;h=27345fd287a63ff33d85987d0531f4d96ab7e656;hb=0f2d58c93fe05b0f40c1c9589aa59d4f9cad877b;hp=69149a509592cebc8889b44b7709613161ee8f27;hpb=398454ed067b95215c7affbe265fd36edab931ee;p=babeltrace.git diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index 69149a50..27345fd2 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -193,8 +193,8 @@ struct ctx_decl_scope { * Visitor context (private). */ struct ctx { - /* Trace IR trace being filled (owned by this) */ - struct bt_private_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; @@ -208,9 +208,6 @@ struct ctx { /* 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; }; @@ -554,16 +551,12 @@ void ctx_destroy(struct ctx *ctx) scope = parent_scope; } - bt_object_put_ref(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: @@ -577,8 +570,8 @@ 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(bt_self_component_source *self_comp, + const struct ctf_metadata_decoder_config *decoder_config) { struct ctx *ctx = NULL; @@ -590,10 +583,13 @@ struct ctx *ctx_create(const struct ctf_metadata_decoder_config *decoder_config, goto error; } - ctx->trace = bt_private_trace_create(); - if (!ctx->trace) { - BT_LOGE_STR("Cannot create empty trace."); - goto error; + if (self_comp) { + ctx->trace_class = bt_trace_class_create( + bt_self_component_source_as_self_component(self_comp)); + if (!ctx->trace_class) { + BT_LOGE_STR("Cannot create empty trace class."); + goto error; + } } ctx->ctf_tc = ctf_trace_class_create(); @@ -609,14 +605,6 @@ struct ctx *ctx_create(const struct ctf_metadata_decoder_config *decoder_config, 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; @@ -2365,9 +2353,9 @@ int visit_integer_decl(struct ctx *ctx, int signedness = 0; struct ctf_node *expression; uint64_t alignment = 0, size = 0; - struct bt_private_clock_class *mapped_clock_class = NULL; + struct ctf_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; @@ -2720,7 +2708,6 @@ int visit_integer_decl(struct ctx *ctx, (*integer_decl)->disp_base = base; (*integer_decl)->encoding = encoding; (*integer_decl)->mapped_clock_class = mapped_clock_class; - bt_object_get_ref((*integer_decl)->mapped_clock_class); return 0; error: @@ -3267,7 +3254,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, _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", @@ -3577,7 +3564,7 @@ static int auto_map_field_to_trace_clock_class(struct ctx *ctx, struct ctf_field_class *fc) { - struct bt_private_clock_class *clock_class_to_map_to = NULL; + struct ctf_clock_class *clock_class_to_map_to = NULL; struct ctf_field_class_int *int_fc = (void *) fc; int ret = 0; uint64_t clock_class_count; @@ -3605,16 +3592,13 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, * implicit one at 1 GHz, named `default`, and use this clock * class. */ - clock_class_to_map_to = bt_private_clock_class_create(); + clock_class_to_map_to = ctf_clock_class_create(); BT_ASSERT(clock_class_to_map_to); - bt_private_clock_class_set_frequency(clock_class_to_map_to, - UINT64_C(1000000000)); - ret = bt_private_clock_class_set_name(clock_class_to_map_to, - "default"); + clock_class_to_map_to->frequency = UINT64_C(1000000000); + g_string_assign(clock_class_to_map_to->name, "default"); BT_ASSERT(ret == 0); g_ptr_array_add(ctx->ctf_tc->clock_classes, clock_class_to_map_to); - bt_object_get_ref(clock_class_to_map_to); break; case 1: /* @@ -3622,7 +3606,6 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, * this one. */ clock_class_to_map_to = ctx->ctf_tc->clock_classes->pdata[0]; - bt_object_get_ref(clock_class_to_map_to); break; default: /* @@ -3637,10 +3620,8 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx, BT_ASSERT(clock_class_to_map_to); int_fc->mapped_clock_class = clock_class_to_map_to; - bt_object_get_ref(int_fc->mapped_clock_class); end: - bt_object_put_ref(clock_class_to_map_to); return ret; } @@ -4370,7 +4351,7 @@ error: static int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, - struct bt_private_clock_class *clock, int *set, int64_t *offset_seconds, + struct ctf_clock_class *clock, int *set, int64_t *offset_seconds, uint64_t *offset_cycles) { int ret = 0; @@ -4409,14 +4390,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_private_clock_class_set_name(clock, right); - if (ret) { - _BT_LOGE_NODE(entry_node, - "cannot set clock class's name"); - g_free(right); - goto error; - } - + g_string_assign(clock->name, right); g_free(right); _SET(set, _CLOCK_NAME_SET); } else if (!strcmp(left, "uuid")) { @@ -4435,7 +4409,8 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - bt_private_clock_class_set_uuid(clock, uuid); + clock->has_uuid = true; + memcpy(&clock->uuid[0], uuid, 16); _SET(set, _CLOCK_UUID_SET); } else if (!strcmp(left, "description")) { char *right; @@ -4456,14 +4431,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = bt_private_clock_class_set_description(clock, right); - if (ret) { - _BT_LOGE_NODE(entry_node, - "Cannot set clock class's description."); - g_free(right); - goto error; - } - + g_string_assign(clock->description, right); g_free(right); _SET(set, _CLOCK_DESCRIPTION_SET); } else if (!strcmp(left, "freq")) { @@ -4492,7 +4460,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - bt_private_clock_class_set_frequency(clock, freq); + clock->frequency = freq; _SET(set, _CLOCK_FREQ_SET); } else if (!strcmp(left, "precision")) { uint64_t precision; @@ -4513,7 +4481,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - bt_private_clock_class_set_precision(clock, precision); + clock->precision = precision; _SET(set, _CLOCK_PRECISION_SET); } else if (!strcmp(left, "offset_s")) { if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) { @@ -4571,7 +4539,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - bt_private_clock_class_set_is_absolute(clock, ret); + clock->is_absolute = ret; _SET(set, _CLOCK_ABSOLUTE_SET); } else { _BT_LOGW_NODE(entry_node, @@ -4617,7 +4585,7 @@ void calibrate_clock_class_offsets(int64_t *offset_seconds, static void apply_clock_class_offset(struct ctx *ctx, - struct bt_private_clock_class *clock) + struct ctf_clock_class *clock) { uint64_t freq; int64_t offset_s_to_apply = ctx->decoder_config.clock_class_offset_s; @@ -4652,10 +4620,9 @@ void apply_clock_class_offset(struct ctx *ctx, offset_s_to_apply += extra_s; } - freq = bt_clock_class_get_frequency( - bt_private_clock_class_as_clock_class(clock)); - bt_clock_class_get_offset(bt_private_clock_class_as_clock_class(clock), - &cur_offset_s, &cur_offset_cycles); + freq = clock->frequency; + cur_offset_s = clock->offset_seconds; + cur_offset_cycles = clock->offset_cycles; /* Apply offsets */ cur_offset_s += offset_s_to_apply; @@ -4668,7 +4635,8 @@ void apply_clock_class_offset(struct ctx *ctx, calibrate_clock_class_offsets(&cur_offset_s, &cur_offset_cycles, freq); /* Set final offsets */ - bt_private_clock_class_set_offset(clock, cur_offset_s, cur_offset_cycles); + clock->offset_seconds = cur_offset_s; + clock->offset_cycles = cur_offset_cycles; end: return; @@ -4679,7 +4647,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) { int ret = 0; int set = 0; - struct bt_private_clock_class *clock; + struct ctf_clock_class *clock; struct ctf_node *entry_node; struct bt_list_head *decl_list = &clock_node->u.clock.declaration_list; const char *clock_class_name; @@ -4694,7 +4662,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) clock_node->visited = TRUE; /* CTF 1.8's default frequency for a clock class is 1 GHz */ - clock = bt_private_clock_class_create(); + clock = ctf_clock_class_create(); if (!clock) { _BT_LOGE_NODE(clock_node, "Cannot create default clock class."); @@ -4702,9 +4670,6 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) goto end; } - /* CTF: not absolute by default */ - bt_private_clock_class_set_is_absolute(clock, BT_FALSE); - bt_list_for_each_entry(entry_node, decl_list, siblings) { ret = visit_clock_decl_entry(ctx, entry_node, clock, &set, &offset_seconds, &offset_cycles); @@ -4723,35 +4688,36 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) goto end; } - clock_class_name = bt_clock_class_get_name( - bt_private_clock_class_as_clock_class(clock)); + clock_class_name = clock->name->str; BT_ASSERT(clock_class_name); if (ctx->is_lttng && strcmp(clock_class_name, "monotonic") == 0) { /* * 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. */ - bt_private_clock_class_set_is_absolute(clock, BT_TRUE); + clock->is_absolute = true; } /* * Adjust offsets so that the part in cycles is less than the * frequency (move to the part in seconds). */ - freq = bt_clock_class_get_frequency( - bt_private_clock_class_as_clock_class(clock)); + freq = clock->frequency; calibrate_clock_class_offsets(&offset_seconds, &offset_cycles, freq); - BT_ASSERT(offset_cycles < bt_clock_class_get_frequency( - bt_private_clock_class_as_clock_class(clock))); - bt_private_clock_class_set_offset(clock, offset_seconds, offset_cycles); + BT_ASSERT(offset_cycles < clock->frequency); + clock->offset_seconds = offset_seconds; + clock->offset_cycles = offset_cycles; apply_clock_class_offset(ctx, clock); g_ptr_array_add(ctx->ctf_tc->clock_classes, clock); - bt_object_get_ref(clock); + clock = NULL; end: - BT_OBJECT_PUT_REF_AND_RESET(clock); + if (clock) { + ctf_clock_class_destroy(clock); + } + return ret; } @@ -4819,64 +4785,15 @@ end: 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) + bt_self_component_source *self_comp, + 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(self_comp, decoder_config); if (!ctx) { BT_LOGE_STR("Cannot create visitor's context."); goto error; @@ -4899,15 +4816,18 @@ void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor) } BT_HIDDEN -struct bt_private_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); - bt_object_get_ref(ctx->trace); - return ctx->trace; + + if (ctx->trace_class) { + bt_trace_class_get_ref(ctx->trace_class); + } + + return ctx->trace_class; } BT_HIDDEN @@ -5090,13 +5010,6 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, 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) { @@ -5118,11 +5031,19 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, goto end; } - /* Update "in IR" for field classes */ - ret = ctf_trace_class_update_in_ir(ctx->ctf_tc); - if (ret) { - ret = -EINVAL; - goto end; + if (ctx->trace_class) { + /* + * Update "in IR" for field classes. + * + * If we have no IR trace class, then we'll have no way + * to create IR fields anyway, so we leave all the + * `in_ir` members false. + */ + ret = ctf_trace_class_update_in_ir(ctx->ctf_tc); + if (ret) { + ret = -EINVAL; + goto end; + } } /* Update saved value indexes */ @@ -5139,11 +5060,13 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, goto end; } - /* Copy new CTF metadata -> new IR metadata */ - ret = ctf_trace_class_translate(ctx->trace, ctx->ctf_tc); - if (ret) { - ret = -EINVAL; - goto end; + if (ctx->trace_class) { + /* Copy new CTF metadata -> new IR metadata */ + ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc); + if (ret) { + ret = -EINVAL; + goto end; + } } end: