diff options
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/trace/trace.cpp | 2 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/trace.cpp | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/trace.h | 15 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/tracenode.cpp | 13 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/trace/tracenode.h | 2 |
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 ¬e, 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 |