summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-11-23 13:30:45 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-11-23 13:30:45 +0000
commitc3c152485a4e2d246d4dd50909a3481cdce71347 (patch)
tree2964c046f8f38abf4f40a509cef91f4a7be5c417 /vespalib
parentca29131b659c51935fe6a6cdf3ae93207c79e714 (diff)
Steal the traces explicit and force moving of traces. Also hide access to the root.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/trace/trace.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/trace/trace.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/trace/trace.h15
-rw-r--r--vespalib/src/vespa/vespalib/trace/tracenode.cpp13
-rw-r--r--vespalib/src/vespa/vespalib/trace/tracenode.h2
5 files changed, 23 insertions, 13 deletions
diff --git a/vespalib/src/tests/trace/trace.cpp b/vespalib/src/tests/trace/trace.cpp
index 46ebaf95114..992317b0289 100644
--- a/vespalib/src/tests/trace/trace.cpp
+++ b/vespalib/src/tests/trace/trace.cpp
@@ -264,7 +264,7 @@ TEST("testTraceDump")
big.addChild(TraceNode(b1));
}
string normal = big.toString();
- string full = big.getRoot().toString();
+ string full = big.toString(100000);
EXPECT_GREATER(normal.size(), 30000u);
EXPECT_LESS(normal.size(), 32000u);
EXPECT_GREATER(full.size(), 50000u);
diff --git a/vespalib/src/vespa/vespalib/trace/trace.cpp b/vespalib/src/vespa/vespalib/trace/trace.cpp
index df9b5111d70..be370aebbd2 100644
--- a/vespalib/src/vespa/vespalib/trace/trace.cpp
+++ b/vespalib/src/vespa/vespalib/trace/trace.cpp
@@ -32,8 +32,8 @@ Trace::trace(uint32_t level, const string &note, bool addTime)
}
string
-Trace::toString() const {
- return _root ? _root->toString(31337) : "";
+Trace::toString(size_t limit) const {
+ return _root ? _root->toString(limit) : "";
}
string
diff --git a/vespalib/src/vespa/vespalib/trace/trace.h b/vespalib/src/vespa/vespalib/trace/trace.h
index 2931cd16829..2f70785d77d 100644
--- a/vespalib/src/vespa/vespalib/trace/trace.h
+++ b/vespalib/src/vespa/vespalib/trace/trace.h
@@ -95,15 +95,6 @@ public:
addChild(std::move(*child._root));
}
}
- //TODO This one should go away as we should prefer moving
- void addChild(const Trace & child) {
- if (!child.isEmpty()) {
- addChild(TraceNode(*child._root));
- }
- }
-
- //TODO This one should go away
- const TraceNode &getRoot() const { return *_root; }
bool isEmpty() const { return !_root || _root->isEmpty(); }
@@ -117,8 +108,12 @@ public:
*
* @return Readable trace string.
*/
- string toString() const;
+ string toString(size_t limit=31337) const;
+ size_t computeMemoryUsage() const {
+ return _root ? _root->computeMemoryUsage() : 0;
+ }
private:
+ const TraceNode &getRoot() const { return *_root; }
TraceNode &ensureRoot();
std::unique_ptr<TraceNode> _root;
diff --git a/vespalib/src/vespa/vespalib/trace/tracenode.cpp b/vespalib/src/vespa/vespalib/trace/tracenode.cpp
index 0f845ca646a..12dd51ac677 100644
--- a/vespalib/src/vespa/vespalib/trace/tracenode.cpp
+++ b/vespalib/src/vespa/vespalib/trace/tracenode.cpp
@@ -342,4 +342,17 @@ TraceNode::accept(TraceVisitor & visitor) const
return visitor;
}
+size_t
+TraceNode::computeMemoryUsage() const
+{
+ if (isLeaf()) {
+ return getNote().size();
+ }
+ size_t childSum = 0;
+ for (const TraceNode & child : _children) {
+ childSum += child.computeMemoryUsage();
+ }
+ return childSum;
+}
+
} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/trace/tracenode.h b/vespalib/src/vespa/vespalib/trace/tracenode.h
index 405c7d994da..7a7cdb89c69 100644
--- a/vespalib/src/vespa/vespalib/trace/tracenode.h
+++ b/vespalib/src/vespa/vespalib/trace/tracenode.h
@@ -253,6 +253,8 @@ public:
*/
TraceVisitor & accept(TraceVisitor & visitor) const;
+ size_t computeMemoryUsage() const;
+
};
} // namespace vespalib