summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-02-25 16:32:58 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-02-25 16:32:58 +0000
commite05d188754f74a97bdaac4edbfb7b99f7684ed82 (patch)
tree660cd81690479dd76e15b0efe476450ab1cee475 /vespalib
parenta3871bdb217657971d24998772618e39b4386340 (diff)
Add methods to print memory usage.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/util/memoryusage.cpp24
-rw-r--r--vespalib/src/vespa/vespalib/util/memoryusage.h13
3 files changed, 34 insertions, 4 deletions
diff --git a/vespalib/src/vespa/vespalib/util/CMakeLists.txt b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
index d934a7b38ca..9d250d31563 100644
--- a/vespalib/src/vespa/vespalib/util/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
@@ -31,6 +31,7 @@ vespa_add_library(vespalib_vespalib_util OBJECT
left_right_heap.cpp
lz4compressor.cpp
md5.c
+ memoryusage.cpp
mmap_file_allocator.cpp
mmap_file_allocator_factory.cpp
printable.cpp
diff --git a/vespalib/src/vespa/vespalib/util/memoryusage.cpp b/vespalib/src/vespa/vespalib/util/memoryusage.cpp
new file mode 100644
index 00000000000..6d6f93c3be0
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/memoryusage.cpp
@@ -0,0 +1,24 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "memoryusage.h"
+#include <vespa/vespalib/stllike/asciistream.h>
+
+namespace vespalib {
+
+string
+MemoryUsage::toString() const {
+ vespalib::asciistream os;
+ os << *this;
+ return os.str();
+}
+
+asciistream &
+operator << (asciistream & os, const MemoryUsage & usage) {
+ os << "allocated: " << usage.allocatedBytes();
+ os << ", used: " << usage.usedBytes();
+ os << ", dead: " << usage.deadBytes();
+ os << ", onhold: " << usage.allocatedBytesOnHold();
+ return os;
+}
+
+} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/util/memoryusage.h b/vespalib/src/vespa/vespalib/util/memoryusage.h
index 0ab339d1262..cc245ee69e9 100644
--- a/vespalib/src/vespa/vespalib/util/memoryusage.h
+++ b/vespalib/src/vespa/vespalib/util/memoryusage.h
@@ -1,8 +1,8 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include <cstddef>
+#include <vespa/vespalib/stllike/string.h>
namespace vespalib {
@@ -14,14 +14,14 @@ private:
size_t _allocatedBytesOnHold;
public:
- MemoryUsage()
+ MemoryUsage() noexcept
: _allocatedBytes(0),
_usedBytes(0),
_deadBytes(0),
_allocatedBytesOnHold(0)
{ }
- MemoryUsage(size_t allocated, size_t used, size_t dead, size_t onHold)
+ MemoryUsage(size_t allocated, size_t used, size_t dead, size_t onHold) noexcept
: _allocatedBytes(allocated),
_usedBytes(used),
_deadBytes(dead),
@@ -56,6 +56,11 @@ public:
_deadBytes += rhs._deadBytes;
_allocatedBytesOnHold += rhs._allocatedBytesOnHold;
}
+ string toString() const;
};
+class asciistream;
+
+asciistream & operator << (asciistream & os, const MemoryUsage & usage);
+
} // namespace vespalib