src.ctf.fs: Add `readPktProps()`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 22 May 2024 15:57:36 +0000 (11:57 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I0e98db658cc50e44bc8d77c8dea53c1984af28aa
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8190
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12712

src/Makefile.am
src/plugins/ctf/common/src/pkt-props.cpp [new file with mode: 0644]
src/plugins/ctf/common/src/pkt-props.hpp [new file with mode: 0644]

index 16f14eb8494f2a9656fcd65bc7961acfb64d0af2..eeb50a9561bc758eda0c1a60c06cde909e9b5093 100644 (file)
@@ -704,6 +704,8 @@ plugins_ctf_babeltrace_plugin_ctf_la_SOURCES = \
        plugins/ctf/common/src/msg-iter/msg-iter.cpp \
        plugins/ctf/common/src/msg-iter/msg-iter.hpp \
        plugins/ctf/common/src/null-cp-finder.hpp \
+       plugins/ctf/common/src/pkt-props.cpp \
+       plugins/ctf/common/src/pkt-props.hpp \
        plugins/ctf/fs-sink/fs-sink.cpp \
        plugins/ctf/fs-sink/fs-sink-ctf-meta.hpp \
        plugins/ctf/fs-sink/fs-sink.hpp \
diff --git a/src/plugins/ctf/common/src/pkt-props.cpp b/src/plugins/ctf/common/src/pkt-props.cpp
new file mode 100644 (file)
index 0000000..ec5a3a0
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2022 EfficiOS Inc. and Linux Foundation
+ */
+
+#include "../../common/src/item-seq/item-seq-iter.hpp"
+#include "../../common/src/item-seq/logging-item-visitor.hpp"
+#include "pkt-props.hpp"
+
+namespace ctf {
+namespace src {
+namespace {
+
+struct ReadPacketPropertiesItemVisitor final : public ItemVisitor
+{
+    void visit(const DataStreamInfoItem& item) override
+    {
+        props.dataStreamCls = item.cls();
+        props.dataStreamId = item.id();
+    }
+
+    void visit(const PktInfoItem& item) override
+    {
+        props.expectedTotalLen = item.expectedTotalLen();
+        props.expectedContentLen = item.expectedContentLen();
+        props.snapshots.discEventRecordCounter = item.discEventRecordCounterSnap();
+        props.snapshots.beginDefClk = item.beginDefClkVal();
+        props.snapshots.endDefClk = item.endDefClkVal();
+        _mDone = true;
+    }
+
+    bool done() const noexcept
+    {
+        return _mDone;
+    }
+
+    PktProps props;
+
+private:
+    bool _mDone = false;
+};
+} /* namespace */
+
+PktProps readPktProps(const TraceCls& traceCls, Medium::UP medium, const bt2c::DataLen pktOffset,
+                      const bt2c::Logger& parentLogger)
+{
+    bt2c::Logger logger {parentLogger, "PLUGIN/CTF/PKT-PROPS"};
+    BT_CPPLOGD_SPEC(logger, "Reading packet properties: pkt-offset-bytes={}", pktOffset.bytes());
+
+    ItemSeqIter itemSeqIter {std::move(medium), traceCls, pktOffset, logger};
+    ReadPacketPropertiesItemVisitor visitor;
+    LoggingItemVisitor loggingVisitor {logger};
+
+    while (!visitor.done()) {
+        const Item *item = itemSeqIter.next();
+        BT_ASSERT(item);
+
+        if (parentLogger.wouldLogT()) {
+            item->accept(loggingVisitor);
+        }
+
+        item->accept(visitor);
+    }
+
+    return visitor.props;
+}
+
+} /* namespace src */
+} /* namespace ctf */
diff --git a/src/plugins/ctf/common/src/pkt-props.hpp b/src/plugins/ctf/common/src/pkt-props.hpp
new file mode 100644 (file)
index 0000000..8100926
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2022 EfficiOS Inc. and Linux Foundation
+ */
+
+#ifndef BABELTRACE_PLUGINS_CTF_COMMON_SRC_PKT_PROPS_HPP
+#define BABELTRACE_PLUGINS_CTF_COMMON_SRC_PKT_PROPS_HPP
+
+#include "cpp-common/bt2c/data-len.hpp"
+#include "cpp-common/bt2c/logging.hpp"
+#include "cpp-common/bt2s/optional.hpp"
+
+#include "item-seq/medium.hpp"
+#include "metadata/ctf-ir.hpp"
+
+namespace ctf {
+namespace src {
+
+struct PktProps final
+{
+    bt2s::optional<bt2c::DataLen> expectedTotalLen;
+    bt2s::optional<bt2c::DataLen> expectedContentLen;
+    const DataStreamCls *dataStreamCls;
+    bt2s::optional<unsigned long long> dataStreamId;
+
+    struct
+    {
+        bt2s::optional<unsigned long long> discEventRecordCounter;
+        bt2s::optional<unsigned long long> beginDefClk;
+        bt2s::optional<unsigned long long> endDefClk;
+    } snapshots;
+};
+
+/*
+ * Extract packet properties at offset.
+ */
+PktProps readPktProps(const TraceCls& traceCls, Medium::UP medium, bt2c::DataLen pktOffset,
+                      const bt2c::Logger& parentLogger);
+
+} /* namespace src */
+} /* namespace ctf */
+
+#endif /* BABELTRACE_PLUGINS_CTF_COMMON_SRC_PKT_PROPS_HPP */
This page took 0.02616 seconds and 4 git commands to generate.