From: Francis Deslauriers Date: Wed, 22 May 2024 15:57:36 +0000 (-0400) Subject: src.ctf.fs: Add `readPktProps()` X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=116721c566f349e92884f990bc640bbf67033168;p=babeltrace.git src.ctf.fs: Add `readPktProps()` Signed-off-by: Francis Deslauriers Change-Id: I0e98db658cc50e44bc8d77c8dea53c1984af28aa Reviewed-on: https://review.lttng.org/c/babeltrace/+/8190 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12712 --- diff --git a/src/Makefile.am b/src/Makefile.am index 16f14eb8..eeb50a95 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 00000000..ec5a3a06 --- /dev/null +++ b/src/plugins/ctf/common/src/pkt-props.cpp @@ -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 index 00000000..8100926d --- /dev/null +++ b/src/plugins/ctf/common/src/pkt-props.hpp @@ -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 expectedTotalLen; + bt2s::optional expectedContentLen; + const DataStreamCls *dataStreamCls; + bt2s::optional dataStreamId; + + struct + { + bt2s::optional discEventRecordCounter; + bt2s::optional beginDefClk; + bt2s::optional 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 */