From 7fcdb0a96f75d66f5ff4f32d3ca78d7ca6067e4c 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 544288cd..ced017f3 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 7f87e57b..3c64ccd7 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 9a598622..d307094e 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 846aee9d..9e835158 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 ac1d2e9d..a34cbf26 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 914ae063..d8afa858 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