From 2b0dbabb5c0fd498d0e42d082f6f5d6bd87f753f Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Mon, 26 Feb 2024 13:48:20 -0800 Subject: [PATCH] Add public showMemory symbol (when SHOW_MEMORY=1) --- Bench.cpp | 4 ++++ ConflictSet.cpp | 33 ++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Bench.cpp b/Bench.cpp index 8a502b0..043dcb8 100644 --- a/Bench.cpp +++ b/Bench.cpp @@ -4,6 +4,10 @@ #include #include +#if SHOW_MEMORY +void showMemory(const ConflictSet &cs); +#endif + #define ANKERL_NANOBENCH_IMPLEMENT #include "third_party/nanobench.h" diff --git a/ConflictSet.cpp b/ConflictSet.cpp index ead210e..4edae24 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -1905,21 +1905,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl { root->entry.rangeVersion = oldestVersion; root->entryPresent = true; } - ~Impl() { - destroyTree(root); -#if SHOW_MEMORY - fprintf(stderr, "Max Node1 memory usage: %" PRId64 "\n", - allocators.node1.highWaterMarkBytes()); - fprintf(stderr, "Max Node4 memory usage: %" PRId64 "\n", - allocators.node4.highWaterMarkBytes()); - fprintf(stderr, "Max Node16 memory usage: %" PRId64 "\n", - allocators.node16.highWaterMarkBytes()); - fprintf(stderr, "Max Node48 memory usage: %" PRId64 "\n", - allocators.node48.highWaterMarkBytes()); - fprintf(stderr, "Max Node256 memory usage: %" PRId64 "\n", - allocators.node256.highWaterMarkBytes()); -#endif - } + ~Impl() { destroyTree(root); } NodeAllocators allocators; @@ -1981,6 +1967,23 @@ ConflictSet::~ConflictSet() { } } +#if SHOW_MEMORY +__attribute__((visibility("default"))) void showMemory(const ConflictSet &cs) { + ConflictSet::Impl *impl; + memcpy(&impl, &cs, sizeof(impl)); // NOLINT + fprintf(stderr, "Max Node1 memory usage: %" PRId64 "\n", + impl->allocators.node1.highWaterMarkBytes()); + fprintf(stderr, "Max Node4 memory usage: %" PRId64 "\n", + impl->allocators.node4.highWaterMarkBytes()); + fprintf(stderr, "Max Node16 memory usage: %" PRId64 "\n", + impl->allocators.node16.highWaterMarkBytes()); + fprintf(stderr, "Max Node48 memory usage: %" PRId64 "\n", + impl->allocators.node48.highWaterMarkBytes()); + fprintf(stderr, "Max Node256 memory usage: %" PRId64 "\n", + impl->allocators.node256.highWaterMarkBytes()); +} +#endif + ConflictSet::ConflictSet(ConflictSet &&other) noexcept : impl(std::exchange(other.impl, nullptr)) {}