From 27bc3313a83d32c54cb90c290767ecb60c2db912 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Fri, 22 Feb 2019 19:53:15 -0500 Subject: [PATCH] lib: create a clock class object from component Before this commit, a trace class was needed for the creation of a clock class. Turns out that clock class may be needed before the creation any trace class. For example, Inactivity messages created before a trace has generated any data need a clock class but no trace class was created yet. This commit allows for the creation of clock classes even when no trace classes exist using a component class. Signed-off-by: Francis Deslauriers --- include/babeltrace/trace-ir/clock-class.h | 2 +- lib/trace-ir/clock-class.c | 4 ++-- plugins/ctf/common/metadata/ctf-meta-translate.c | 10 +++++++--- plugins/ctf/common/metadata/ctf-meta-visitors.h | 4 ++-- plugins/ctf/common/metadata/visitor-generate-ir.c | 5 ++++- plugins/text/dmesg/dmesg.c | 3 ++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/babeltrace/trace-ir/clock-class.h b/include/babeltrace/trace-ir/clock-class.h index 544288cd5..ced017f33 100644 --- a/include/babeltrace/trace-ir/clock-class.h +++ b/include/babeltrace/trace-ir/clock-class.h @@ -39,7 +39,7 @@ extern "C" { #endif -extern bt_clock_class *bt_clock_class_create(bt_trace_class *trace_class); +extern bt_clock_class *bt_clock_class_create(bt_self_component *self_comp); extern bt_clock_class_status bt_clock_class_set_name( bt_clock_class *clock_class, const char *name); diff --git a/lib/trace-ir/clock-class.c b/lib/trace-ir/clock-class.c index 7f87e57b4..3c64ccd7e 100644 --- a/lib/trace-ir/clock-class.c +++ b/lib/trace-ir/clock-class.c @@ -79,12 +79,12 @@ void set_base_offset(struct bt_clock_class *clock_class) clock_class->frequency, &clock_class->base_offset.value_ns); } -struct bt_clock_class *bt_clock_class_create(bt_trace_class *trace_class) +struct bt_clock_class *bt_clock_class_create(bt_self_component *self_comp) { int ret; struct bt_clock_class *clock_class = NULL; - BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); + BT_ASSERT_PRE_NON_NULL(self_comp, "Self component"); BT_LOGD_STR("Creating default clock class object"); clock_class = g_new0(struct bt_clock_class, 1); diff --git a/plugins/ctf/common/metadata/ctf-meta-translate.c b/plugins/ctf/common/metadata/ctf-meta-translate.c index 9a5986228..d307094ef 100644 --- a/plugins/ctf/common/metadata/ctf-meta-translate.c +++ b/plugins/ctf/common/metadata/ctf-meta-translate.c @@ -26,6 +26,7 @@ #include "ctf-meta-visitors.h" struct ctx { + bt_self_component_source *self_comp; bt_trace_class *ir_tc; bt_stream_class *ir_sc; struct ctf_trace_class *tc; @@ -580,7 +581,9 @@ int ctf_trace_class_to_ir(struct ctx *ctx) for (i = 0; i < ctx->tc->clock_classes->len; i++) { struct ctf_clock_class *cc = ctx->tc->clock_classes->pdata[i]; - cc->ir_cc = bt_clock_class_create(ctx->ir_tc); + cc->ir_cc = bt_clock_class_create( + bt_self_component_source_as_self_component( + ctx->self_comp)); ctf_clock_class_to_ir(cc->ir_cc, cc); } @@ -594,13 +597,14 @@ end: } BT_HIDDEN -int ctf_trace_class_translate(bt_trace_class *ir_tc, - struct ctf_trace_class *tc) +int ctf_trace_class_translate(bt_self_component_source *self_comp, + bt_trace_class *ir_tc, struct ctf_trace_class *tc) { int ret = 0; uint64_t i; struct ctx ctx = { 0 }; + ctx.self_comp = self_comp; ctx.tc = tc; ctx.ir_tc = ir_tc; ret = ctf_trace_class_to_ir(&ctx); diff --git a/plugins/ctf/common/metadata/ctf-meta-visitors.h b/plugins/ctf/common/metadata/ctf-meta-visitors.h index 846aee9d5..9e835158e 100644 --- a/plugins/ctf/common/metadata/ctf-meta-visitors.h +++ b/plugins/ctf/common/metadata/ctf-meta-visitors.h @@ -24,8 +24,8 @@ BT_HIDDEN int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc); BT_HIDDEN -int ctf_trace_class_translate(bt_trace_class *ir_tc, - struct ctf_trace_class *tc); +int ctf_trace_class_translate(bt_self_component_source *self_comp, + bt_trace_class *ir_tc, struct ctf_trace_class *tc); BT_HIDDEN int ctf_trace_class_update_default_clock_classes( diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index ac1d2e9d6..a34cbf261 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -193,6 +193,7 @@ struct ctx_decl_scope { * Visitor context (private). */ struct ctx { + bt_self_component_source *self_comp; /* Trace IR trace class being filled (owned by this) */ bt_trace_class *trace_class; @@ -590,6 +591,7 @@ struct ctx *ctx_create(bt_self_component_source *self_comp, BT_LOGE_STR("Cannot create empty trace class."); goto error; } + ctx->self_comp = self_comp; } ctx->ctf_tc = ctf_trace_class_create(); @@ -5068,7 +5070,8 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, if (ctx->trace_class) { /* Copy new CTF metadata -> new IR metadata */ - ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc); + ret = ctf_trace_class_translate(ctx->self_comp, + ctx->trace_class, ctx->ctf_tc); if (ret) { ret = -EINVAL; goto end; diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 914ae0636..d8afa858c 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -141,7 +141,8 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) if (has_ts) { dmesg_comp->clock_class = bt_clock_class_create( - dmesg_comp->trace_class); + bt_self_component_source_as_self_component( + dmesg_comp->self_comp)); if (!dmesg_comp->clock_class) { BT_LOGE_STR("Cannot create clock class."); goto error; -- 2.34.1