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 \
--- /dev/null
+/*
+ * 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 */
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);
"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:
#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
{
/* 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;
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;
}
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;
}
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)
{
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;
}
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);
/* 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 */
/* Owned by this */
struct ctf_fs_trace *trace = nullptr;
- struct ctf_fs_metadata_config metadata_config;
+ ctf::src::ClkClsCfg clkClsCfg;
};
struct ctf_fs_trace
}
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);
} /* 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);
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};