Add public showMemory symbol (when SHOW_MEMORY=1)

This commit is contained in:
2024-02-26 13:48:20 -08:00
parent be7f643f14
commit 2b0dbabb5c
2 changed files with 22 additions and 15 deletions

View File

@@ -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)) {}