From c942e7a26ff9579f3135ff181f54d1bc691c954c Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 11 Dec 2023 12:22:44 -0500 Subject: [PATCH] ctf: add ClkClsConfig and use it Different parts of the code in the ctf plugin (in fs-src, lttng-live and common) use these three values: - clock offset (seconds) - clock offset (nanoseconds) - force origin to be Unix epoch Gather these three values in a new structure, `ClkClsConfig`, so that these they can easily be passed around. This replaces the existing ctf_fs_metadata_config structure, which contained the exact same thing, but was specific to the fs component class. Change-Id: If9b4d88c9fd5eb3352c5de4007dc4343fac485c1 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8228 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12276 --- src/Makefile.am | 1 + src/plugins/ctf/common/src/clk-cls-cfg.hpp | 25 +++++++++++++++++++ .../ctf/common/src/metadata/tsdl/decoder.cpp | 5 ++-- .../ctf/common/src/metadata/tsdl/decoder.hpp | 11 ++++---- .../src/metadata/tsdl/visitor-generate-ir.cpp | 18 ++++++------- src/plugins/ctf/fs-src/fs.cpp | 14 +++++------ src/plugins/ctf/fs-src/fs.hpp | 2 +- src/plugins/ctf/fs-src/metadata.cpp | 7 ++---- src/plugins/ctf/fs-src/metadata.hpp | 11 +++----- src/plugins/ctf/lttng-live/metadata.cpp | 2 -- 10 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 src/plugins/ctf/common/src/clk-cls-cfg.hpp diff --git a/src/Makefile.am b/src/Makefile.am index 204bb6f1..6b98e341 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -659,6 +659,7 @@ endif plugins_ctf_babeltrace_plugin_ctf_la_SOURCES = \ plugins/ctf/common/src/bfcr/bfcr.cpp \ plugins/ctf/common/src/bfcr/bfcr.hpp \ + plugins/ctf/common/src/clk-cls-cfg.hpp \ plugins/ctf/common/src/msg-iter/msg-iter.cpp \ plugins/ctf/common/src/msg-iter/msg-iter.hpp \ plugins/ctf/fs-sink/fs-sink.cpp \ diff --git a/src/plugins/ctf/common/src/clk-cls-cfg.hpp b/src/plugins/ctf/common/src/clk-cls-cfg.hpp new file mode 100644 index 00000000..0c3b52d7 --- /dev/null +++ b/src/plugins/ctf/common/src/clk-cls-cfg.hpp @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (c) 2022 EfficiOS Inc. and Linux Foundation + */ + +#ifndef CTF_COMMON_SRC_CLK_CLS_CFG_HPP +#define CTF_COMMON_SRC_CLK_CLS_CFG_HPP + +#include + +namespace ctf { +namespace src { + +struct ClkClsCfg +{ + std::int64_t offsetSec = 0; + std::int64_t offsetNanoSec = 0; + bool forceOriginIsUnixEpoch = false; +}; + +} /* namespace src */ +} /* namespace ctf */ + +#endif /* CTF_COMMON_SRC_CLK_CLS_CFG_HPP */ diff --git a/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp b/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp index b6fe5174..4dea9b76 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp @@ -90,12 +90,11 @@ ctf_metadata_decoder_up ctf_metadata_decoder_create(const struct ctf_metadata_decoder_config *config) { BT_ASSERT(config); - BT_CPPLOGD_SPEC(config->logger, "Creating CTF metadata decoder: " "clock-class-offset-s={}, " "clock-class-offset-ns={}", - config->clock_class_offset_s, config->clock_class_offset_ns); + config->clkClsCfg.offsetSec, config->clkClsCfg.offsetNanoSec); ctf_metadata_decoder *mdec = new ctf_metadata_decoder {config->logger}; mdec->scanner = ctf_scanner_alloc(mdec->logger); @@ -131,7 +130,7 @@ ctf_metadata_decoder_create(const struct ctf_metadata_decoder_config *config) "Creating CTF metadata decoder: " "clock-class-offset-s={}, " "clock-class-offset-ns={}, addr={}", - config->clock_class_offset_s, config->clock_class_offset_ns, fmt::ptr(mdec)); + config->clkClsCfg.offsetSec, config->clkClsCfg.offsetNanoSec, fmt::ptr(mdec)); goto end; error: diff --git a/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp b/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp index 0aee6173..a6142cb3 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp @@ -7,7 +7,6 @@ #ifndef _METADATA_DECODER_H #define _METADATA_DECODER_H -#include #include #include @@ -16,6 +15,11 @@ #include "cpp-common/bt2c/logging.hpp" #include "cpp-common/vendor/fmt/format.h" /* IWYU pragma: keep */ +#include "../../../src/clk-cls-cfg.hpp" + +/* A CTF metadata decoder object */ +struct ctf_metadata_decoder; + /* CTF metadata decoder status */ enum ctf_metadata_decoder_status { @@ -65,10 +69,7 @@ struct ctf_metadata_decoder_config /* Weak, used to create a bt_trace_class, if not nullptr. */ bt_self_component *self_comp = nullptr; - /* Additional clock class offset to apply */ - int64_t clock_class_offset_s = 0; - int64_t clock_class_offset_ns = 0; - bool force_clock_class_origin_unix_epoch = false; + ctf::src::ClkClsCfg clkClsCfg; /* True to create trace class objects */ bool create_trace_class = false; diff --git a/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp b/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp index 6416b337..458177a6 100644 --- a/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp +++ b/src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp @@ -4208,7 +4208,7 @@ static void calibrate_clock_class_offsets(int64_t *offset_seconds, uint64_t *off static void apply_clock_class_is_absolute(struct ctf_visitor_generate_ir *ctx, struct ctf_clock_class *clock) { - if (ctx->decoder_config.force_clock_class_origin_unix_epoch) { + if (ctx->decoder_config.clkClsCfg.forceOriginIsUnixEpoch) { clock->is_absolute = true; } @@ -4219,31 +4219,31 @@ static void apply_clock_class_offset(struct ctf_visitor_generate_ir *ctx, struct ctf_clock_class *clock) { uint64_t freq; - int64_t offset_s_to_apply = ctx->decoder_config.clock_class_offset_s; + int64_t offset_s_to_apply = ctx->decoder_config.clkClsCfg.offsetSec; uint64_t offset_ns_to_apply; int64_t cur_offset_s; uint64_t cur_offset_cycles; - if (ctx->decoder_config.clock_class_offset_s == 0 && - ctx->decoder_config.clock_class_offset_ns == 0) { + if (ctx->decoder_config.clkClsCfg.offsetSec == 0 && + ctx->decoder_config.clkClsCfg.offsetNanoSec == 0) { goto end; } /* Transfer nanoseconds to seconds as much as possible */ - if (ctx->decoder_config.clock_class_offset_ns < 0) { - const int64_t abs_ns = -ctx->decoder_config.clock_class_offset_ns; + if (ctx->decoder_config.clkClsCfg.offsetNanoSec < 0) { + const int64_t abs_ns = -ctx->decoder_config.clkClsCfg.offsetNanoSec; const int64_t abs_extra_s = abs_ns / INT64_C(1000000000) + 1; const int64_t extra_s = -abs_extra_s; const int64_t offset_ns = - ctx->decoder_config.clock_class_offset_ns - (extra_s * INT64_C(1000000000)); + ctx->decoder_config.clkClsCfg.offsetNanoSec - (extra_s * INT64_C(1000000000)); BT_ASSERT(offset_ns > 0); offset_ns_to_apply = (uint64_t) offset_ns; offset_s_to_apply += extra_s; } else { - const int64_t extra_s = ctx->decoder_config.clock_class_offset_ns / INT64_C(1000000000); + const int64_t extra_s = ctx->decoder_config.clkClsCfg.offsetNanoSec / INT64_C(1000000000); const int64_t offset_ns = - ctx->decoder_config.clock_class_offset_ns - (extra_s * INT64_C(1000000000)); + ctx->decoder_config.clkClsCfg.offsetNanoSec - (extra_s * INT64_C(1000000000)); BT_ASSERT(offset_ns >= 0); offset_ns_to_apply = (uint64_t) offset_ns; diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index f2bd9618..c4bfd972 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -959,7 +959,7 @@ end: } static struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, - struct ctf_fs_metadata_config *metadata_config, + const ctf::src::ClkClsCfg& clkClsCfg, bt_self_component *selfComp, const bt2c::Logger& parentLogger) { @@ -979,7 +979,7 @@ static struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *na goto error; } - ret = ctf_fs_metadata_set_trace_class(selfComp, ctf_fs_trace, metadata_config); + ret = ctf_fs_metadata_set_trace_class(selfComp, ctf_fs_trace, clkClsCfg); if (ret) { goto error; } @@ -1076,8 +1076,8 @@ static int ctf_fs_component_create_ctf_fs_trace_one_path(struct ctf_fs_component goto end; } - ctf_fs_trace = ctf_fs_trace_create(norm_path->str, trace_name, &ctf_fs->metadata_config, - selfComp, ctf_fs->logger); + ctf_fs_trace = ctf_fs_trace_create(norm_path->str, trace_name, ctf_fs->clkClsCfg, selfComp, + ctf_fs->logger); if (!ctf_fs_trace) { BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Cannot create trace for `{}`.", norm_path->str); @@ -2163,19 +2163,19 @@ bool read_src_fs_parameters(const bt_value *params, const bt_value **inputs, /* clock-class-offset-s parameter */ value = bt_value_map_borrow_entry_value_const(params, "clock-class-offset-s"); if (value) { - ctf_fs->metadata_config.clock_class_offset_s = bt_value_integer_signed_get(value); + ctf_fs->clkClsCfg.offsetSec = bt_value_integer_signed_get(value); } /* clock-class-offset-ns parameter */ value = bt_value_map_borrow_entry_value_const(params, "clock-class-offset-ns"); if (value) { - ctf_fs->metadata_config.clock_class_offset_ns = bt_value_integer_signed_get(value); + ctf_fs->clkClsCfg.offsetNanoSec = bt_value_integer_signed_get(value); } /* force-clock-class-origin-unix-epoch parameter */ value = bt_value_map_borrow_entry_value_const(params, "force-clock-class-origin-unix-epoch"); if (value) { - ctf_fs->metadata_config.force_clock_class_origin_unix_epoch = bt_value_bool_get(value); + ctf_fs->clkClsCfg.forceOriginIsUnixEpoch = bt_value_bool_get(value); } /* trace-name parameter */ diff --git a/src/plugins/ctf/fs-src/fs.hpp b/src/plugins/ctf/fs-src/fs.hpp index 1cb9e8b0..7aa4568e 100644 --- a/src/plugins/ctf/fs-src/fs.hpp +++ b/src/plugins/ctf/fs-src/fs.hpp @@ -79,7 +79,7 @@ struct ctf_fs_component /* Owned by this */ struct ctf_fs_trace *trace = nullptr; - struct ctf_fs_metadata_config metadata_config; + ctf::src::ClkClsCfg clkClsCfg; }; struct ctf_fs_trace diff --git a/src/plugins/ctf/fs-src/metadata.cpp b/src/plugins/ctf/fs-src/metadata.cpp index cbe4172b..86826179 100644 --- a/src/plugins/ctf/fs-src/metadata.cpp +++ b/src/plugins/ctf/fs-src/metadata.cpp @@ -63,17 +63,14 @@ end: } int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_trace *ctf_fs_trace, - struct ctf_fs_metadata_config *config) + const ctf::src::ClkClsCfg& clkClsCfg) { int ret = 0; struct ctf_fs_file *file = NULL; ctf_metadata_decoder_config decoder_config {ctf_fs_trace->logger}; decoder_config.self_comp = self_comp; - decoder_config.clock_class_offset_s = config ? config->clock_class_offset_s : 0; - decoder_config.clock_class_offset_ns = config ? config->clock_class_offset_ns : 0; - decoder_config.force_clock_class_origin_unix_epoch = - config ? config->force_clock_class_origin_unix_epoch : false; + decoder_config.clkClsCfg = clkClsCfg; decoder_config.create_trace_class = true; file = get_file(ctf_fs_trace->path->str, ctf_fs_trace->logger); diff --git a/src/plugins/ctf/fs-src/metadata.hpp b/src/plugins/ctf/fs-src/metadata.hpp index cf24aa47..202980bd 100644 --- a/src/plugins/ctf/fs-src/metadata.hpp +++ b/src/plugins/ctf/fs-src/metadata.hpp @@ -17,21 +17,16 @@ class Logger; } /* namespace bt2c */ -#define CTF_FS_METADATA_FILENAME "metadata" +#include "../common/src/clk-cls-cfg.hpp" -struct ctf_fs_metadata_config -{ - bool force_clock_class_origin_unix_epoch = false; - int64_t clock_class_offset_s = 0; - int64_t clock_class_offset_ns = 0; -}; +#define CTF_FS_METADATA_FILENAME "metadata" int ctf_fs_metadata_init(struct ctf_fs_metadata *metadata); void ctf_fs_metadata_fini(struct ctf_fs_metadata *metadata); int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_trace *ctf_fs_trace, - struct ctf_fs_metadata_config *config); + const ctf::src::ClkClsCfg& clkClsCfg); FILE *ctf_fs_metadata_open_file(const char *trace_path, const bt2c::Logger& logger); diff --git a/src/plugins/ctf/lttng-live/metadata.cpp b/src/plugins/ctf/lttng-live/metadata.cpp index e90b352e..e78b6759 100644 --- a/src/plugins/ctf/lttng-live/metadata.cpp +++ b/src/plugins/ctf/lttng-live/metadata.cpp @@ -284,8 +284,6 @@ int lttng_live_metadata_create_stream(struct lttng_live_session *session, uint64 ctf_metadata_decoder_config cfg {session->logger}; cfg.self_comp = session->self_comp; - cfg.clock_class_offset_s = 0; - cfg.clock_class_offset_ns = 0; cfg.create_trace_class = true; lttng_live_metadata *metadata = new lttng_live_metadata {session->logger}; -- 2.34.1