summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--messagebus/src/tests/simpleprotocol/simpleprotocol.cpp12
-rw-r--r--storage/src/tests/visiting/visitortest.cpp1
-rw-r--r--storage/src/vespa/storage/distributor/operations/external/visitoroperation.cpp2
-rw-r--r--storage/src/vespa/storage/visiting/memory_bounded_trace.h6
-rw-r--r--storage/src/vespa/storage/visiting/visitor.cpp4
-rw-r--r--storageapi/src/tests/messageapi/storage_message_address_test.cpp4
-rw-r--r--vespalib/src/tests/trace/trace.cpp20
-rw-r--r--vespalib/src/vespa/vespalib/trace/trace.cpp32
-rw-r--r--vespalib/src/vespa/vespalib/trace/trace.h26
9 files changed, 70 insertions, 37 deletions
diff --git a/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp
index 091c7b668a1..bc4fc80abad 100644
--- a/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp
+++ b/messagebus/src/tests/simpleprotocol/simpleprotocol.cpp
@@ -32,9 +32,9 @@ Test::Main()
TEST_FLUSH();
{
// test SimpleMessage
- EXPECT_EQUAL(160u, sizeof(Routable));
- EXPECT_EQUAL(208u, sizeof(Message));
- EXPECT_EQUAL(288u, sizeof(SimpleMessage));
+ EXPECT_EQUAL(56u, sizeof(Routable));
+ EXPECT_EQUAL(104u, sizeof(Message));
+ EXPECT_EQUAL(184u, sizeof(SimpleMessage));
auto msg = std::make_unique<SimpleMessage>("test");
EXPECT_TRUE(!msg->isReply());
EXPECT_TRUE(msg->getProtocol() == SimpleProtocol::NAME);
@@ -52,9 +52,9 @@ Test::Main()
TEST_FLUSH();
{
// test SimpleReply
- EXPECT_EQUAL(160u, sizeof(Routable));
- EXPECT_EQUAL(200u, sizeof(Reply));
- EXPECT_EQUAL(264u, sizeof(SimpleReply));
+ EXPECT_EQUAL(56u, sizeof(Routable));
+ EXPECT_EQUAL(96u, sizeof(Reply));
+ EXPECT_EQUAL(160u, sizeof(SimpleReply));
auto reply = std::make_unique<SimpleReply>("reply");
EXPECT_TRUE(reply->isReply());
EXPECT_TRUE(reply->getProtocol() == SimpleProtocol::NAME);
diff --git a/storage/src/tests/visiting/visitortest.cpp b/storage/src/tests/visiting/visitortest.cpp
index 8b16f3c92b6..f727cdf8eb2 100644
--- a/storage/src/tests/visiting/visitortest.cpp
+++ b/storage/src/tests/visiting/visitortest.cpp
@@ -805,6 +805,7 @@ TEST_F(VisitorTest, no_mbus_tracing_if_trace_level_is_zero) {
TEST_F(VisitorTest, reply_contains_trace_if_trace_level_above_zero) {
std::shared_ptr<api::CreateVisitorCommand> cmd(makeCreateVisitor());
cmd->getTrace().setLevel(1);
+ cmd->getTrace().trace(1,"at least one trace.");
std::shared_ptr<api::CreateVisitorReply> reply;
ASSERT_NO_FATAL_FAILURE(doCompleteVisitingSession(cmd, reply));
EXPECT_FALSE(reply->getTrace().isEmpty());
diff --git a/storage/src/vespa/storage/distributor/operations/external/visitoroperation.cpp b/storage/src/vespa/storage/distributor/operations/external/visitoroperation.cpp
index bbed631951c..85bf397ebbc 100644
--- a/storage/src/vespa/storage/distributor/operations/external/visitoroperation.cpp
+++ b/storage/src/vespa/storage/distributor/operations/external/visitoroperation.cpp
@@ -171,7 +171,7 @@ VisitorOperation::onReceive(
{
api::CreateVisitorReply& reply = static_cast<api::CreateVisitorReply&>(*r);
- _trace.add(reply.getTrace().getRoot());
+ _trace.add(reply.getTrace());
SentMessagesMap::iterator iter = _sentMessages.find(reply.getMsgId());
assert(iter != _sentMessages.end());
diff --git a/storage/src/vespa/storage/visiting/memory_bounded_trace.h b/storage/src/vespa/storage/visiting/memory_bounded_trace.h
index 1c20e56cae0..a7f8a00d6a9 100644
--- a/storage/src/vespa/storage/visiting/memory_bounded_trace.h
+++ b/storage/src/vespa/storage/visiting/memory_bounded_trace.h
@@ -23,6 +23,12 @@ public:
* otherwise.
*/
bool add(const mbus::TraceNode& node);
+ bool add(const mbus::Trace& trace) {
+ if (!trace.isEmpty()) {
+ return add(trace.getRoot());
+ }
+ return false;
+ }
/**
* Append current trace tree to the output trace node and clear internal
diff --git a/storage/src/vespa/storage/visiting/visitor.cpp b/storage/src/vespa/storage/visiting/visitor.cpp
index 540020e978b..26efaf323e0 100644
--- a/storage/src/vespa/storage/visiting/visitor.cpp
+++ b/storage/src/vespa/storage/visiting/visitor.cpp
@@ -609,7 +609,7 @@ Visitor::handleDocumentApiReply(mbus::Reply::UP reply,
VisitorThreadMetrics& metrics)
{
if (shouldAddMbusTrace()) {
- _trace.add(reply->getTrace().getRoot());
+ _trace.add(reply->getTrace()); //TODO Can it be moved ?
}
mbus::Message::UP message = reply->getMessage();
@@ -830,7 +830,7 @@ Visitor::onGetIterReply(const std::shared_ptr<GetIterReply>& reply,
}
if (shouldAddMbusTrace()) {
- _trace.add(reply->getTrace().getRoot());
+ _trace.add(reply->getTrace()); //TODO Can it be moved ?
}
LOG(debug, "Continuing visitor %s.", _id.c_str());
diff --git a/storageapi/src/tests/messageapi/storage_message_address_test.cpp b/storageapi/src/tests/messageapi/storage_message_address_test.cpp
index 6cf87b348a9..9db282c98eb 100644
--- a/storageapi/src/tests/messageapi/storage_message_address_test.cpp
+++ b/storageapi/src/tests/messageapi/storage_message_address_test.cpp
@@ -33,9 +33,9 @@ TEST(StorageMessageAddressTest, storage_hash_covers_all_expected_fields) {
hash_of("foo", lib::NodeType::STORAGE, 1));
EXPECT_EQ(112u, sizeof(StorageMessageAddress));
- EXPECT_EQ(248u, sizeof(StorageMessage));
+ EXPECT_EQ(144u, sizeof(StorageMessage));
EXPECT_EQ(80u, sizeof(documentapi::LoadType));
- EXPECT_EQ(120u, sizeof(mbus::Trace));
+ EXPECT_EQ(16u, sizeof(mbus::Trace));
}
} // storage::api
diff --git a/vespalib/src/tests/trace/trace.cpp b/vespalib/src/tests/trace/trace.cpp
index 9c8660fe395..46ebaf95114 100644
--- a/vespalib/src/tests/trace/trace.cpp
+++ b/vespalib/src/tests/trace/trace.cpp
@@ -146,25 +146,25 @@ TEST("testTraceLevel")
t.setLevel(4);
EXPECT_EQUAL(4u, t.getLevel());
t.trace(9, "no");
- EXPECT_EQUAL(0u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(0u, t.getNumChildren());
t.trace(8, "no");
- EXPECT_EQUAL(0u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(0u, t.getNumChildren());
t.trace(7, "no");
- EXPECT_EQUAL(0u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(0u, t.getNumChildren());
t.trace(6, "no");
- EXPECT_EQUAL(0u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(0u, t.getNumChildren());
t.trace(5, "no");
- EXPECT_EQUAL(0u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(0u, t.getNumChildren());
t.trace(4, "yes");
- EXPECT_EQUAL(1u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(1u, t.getNumChildren());
t.trace(3, "yes");
- EXPECT_EQUAL(2u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(2u, t.getNumChildren());
t.trace(2, "yes");
- EXPECT_EQUAL(3u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(3u, t.getNumChildren());
t.trace(1, "yes");
- EXPECT_EQUAL(4u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(4u, t.getNumChildren());
t.trace(0, "yes");
- EXPECT_EQUAL(5u, t.getRoot().getNumChildren());
+ EXPECT_EQUAL(5u, t.getNumChildren());
}
TEST("testCompact")
diff --git a/vespalib/src/vespa/vespalib/trace/trace.cpp b/vespalib/src/vespa/vespalib/trace/trace.cpp
index 2a9afc9b36b..ea93f574ed0 100644
--- a/vespalib/src/vespa/vespalib/trace/trace.cpp
+++ b/vespalib/src/vespa/vespalib/trace/trace.cpp
@@ -6,6 +6,15 @@
namespace vespalib {
+Trace::Trace(const Trace &rhs)
+ : _root(),
+ _level(rhs._level)
+{
+ if (!rhs.isEmpty()) {
+ _root = std::make_unique<TraceNode>(rhs.getRoot());
+ }
+}
+
bool
Trace::trace(uint32_t level, const string &note, bool addTime)
{
@@ -15,11 +24,30 @@ Trace::trace(uint32_t level, const string &note, bool addTime)
if (addTime) {
struct timeval tv;
gettimeofday(&tv, nullptr);
- _root.addChild(make_string("[%ld.%06ld] %s", tv.tv_sec, static_cast<long>(tv.tv_usec), note.c_str()));
+ ensureRoot().addChild(make_string("[%ld.%06ld] %s", tv.tv_sec, static_cast<long>(tv.tv_usec), note.c_str()));
} else {
- _root.addChild(note);
+ ensureRoot().addChild(note);
}
return true;
}
+string
+Trace::toString() const {
+ return _root ? _root->toString(31337) : "";
+}
+
+void
+Trace::clear() {
+ _level = 0;
+ _root.reset();
+}
+
+TraceNode &
+Trace::ensureRoot() {
+ if (!_root) {
+ _root = std::make_unique<TraceNode>();
+ }
+ return *_root;
+}
+
} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/trace/trace.h b/vespalib/src/vespa/vespalib/trace/trace.h
index 5be9b662c89..1300f121404 100644
--- a/vespalib/src/vespa/vespalib/trace/trace.h
+++ b/vespalib/src/vespa/vespalib/trace/trace.h
@@ -27,7 +27,7 @@ public:
explicit Trace(uint32_t level) : _root(), _level(level) { }
Trace & operator = (Trace &&) = default;
Trace(Trace &&) = default;
- Trace(const Trace &) = default;
+ Trace(const Trace &);
Trace & operator = (const Trace &) = delete;
~Trace() = default;
@@ -36,11 +36,7 @@ public:
*
* @return This, to allow chaining.
*/
- Trace &clear() {
- _level = 0;
- _root.clear();
- return *this;
- }
+ void clear();
/**
* Swap the internals of this with another.
@@ -97,7 +93,9 @@ public:
bool trace(uint32_t level, const string &note, bool addTime = true);
void normalize() {
- _root.normalize();
+ if (_root) {
+ _root->normalize();
+ }
}
/**
@@ -115,7 +113,7 @@ public:
}
void addChild(Trace && child) {
if (!child.isEmpty()) {
- addChild(std::move(child._root));
+ addChild(std::move(*child._root));
}
}
@@ -124,11 +122,11 @@ public:
*
* @return The root.
*/
- const TraceNode &getRoot() const { return _root; }
+ const TraceNode &getRoot() const { return *_root; }
- bool isEmpty() const { return _root.isEmpty(); }
+ bool isEmpty() const { return !_root || _root->isEmpty(); }
- uint32_t getNumChildren() const { return _root.getNumChildren(); }
+ uint32_t getNumChildren() const { return _root ? _root->getNumChildren() : 0; }
const TraceNode & getChild(uint32_t child) const { return getRoot().getChild(child); }
/**
@@ -137,11 +135,11 @@ public:
*
* @return Readable trace string.
*/
- string toString() const { return _root.toString(31337); }
+ string toString() const;
private:
- TraceNode &ensureRoot() { return _root; }
+ TraceNode &ensureRoot();
- TraceNode _root;
+ std::unique_ptr<TraceNode> _root;
uint32_t _level;
};