ctf: add ClkClsConfig and use it
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 11 Dec 2023 17:22:44 +0000 (12:22 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8228
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12276

src/Makefile.am
src/plugins/ctf/common/src/clk-cls-cfg.hpp [new file with mode: 0644]
src/plugins/ctf/common/src/metadata/tsdl/decoder.cpp
src/plugins/ctf/common/src/metadata/tsdl/decoder.hpp
src/plugins/ctf/common/src/metadata/tsdl/visitor-generate-ir.cpp
src/plugins/ctf/fs-src/fs.cpp
src/plugins/ctf/fs-src/fs.hpp
src/plugins/ctf/fs-src/metadata.cpp
src/plugins/ctf/fs-src/metadata.hpp
src/plugins/ctf/lttng-live/metadata.cpp

index 204bb6f17db8303a91ebbbbe32de5e58207ca34c..6b98e341782c1e51fb080cdcb05b137d0e6f84a4 100644 (file)
@@ -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 (file)
index 0000000..0c3b52d
--- /dev/null
@@ -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 <cstdint>
+
+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 */
index b6fe517487f3a297ff87987a4a2052d265735da0..4dea9b76be07a89fb6a60d671a0c4ba8f51ece44 100644 (file)
@@ -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:
index 0aee6173c845374cf6f10a390c5759bba2f42431..a6142cb3ab05ce295053f4ddd7779c9e193991df 100644 (file)
@@ -7,7 +7,6 @@
 #ifndef _METADATA_DECODER_H
 #define _METADATA_DECODER_H
 
-#include <stdint.h>
 #include <stdio.h>
 
 #include <babeltrace2/babeltrace.h>
 #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;
index 6416b3378af71711cc1395add05d8735c7cd191f..458177a6d6b9e20eccce56f09a80976f21943670 100644 (file)
@@ -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;
index f2bd9618e1f9e95ad5483f328cec798d87646f82..c4bfd972d6116a63dab5ac2749c6e8f52b4c7aaa 100644 (file)
@@ -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 */
index 1cb9e8b058fef34c9bcf286300055506e26cdb30..7aa4568e0a5a9f8fdaa21462e8f9e09ae9ffd6bd 100644 (file)
@@ -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
index cbe4172b21a6fab4ebb4f34c73e3f3781b9e5a31..86826179c9b08ecb881fae5b4d143c40dc79041c 100644 (file)
@@ -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);
index cf24aa47e0f11984a71a20c103f1c4e2694050e9..202980bd09af6931180525cff458503063ff3c07 100644 (file)
@@ -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);
 
index e90b352ee46c1f56e81fb01d8b730586fa5f935c..e78b675933c99106cad7a880c87fe7bf958b5afd 100644 (file)
@@ -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};
This page took 0.03157 seconds and 4 git commands to generate.