From 04cf902791e339f9449d7d26a399cafebba84ac5 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Thu, 25 Jul 2024 18:04:56 +0000 Subject: [PATCH] Mallinfo and ASAN hooks --- Grid/allocator/MemoryManager.cc | 40 ++++++++++++++++++++++++++++++++- Grid/allocator/MemoryManager.h | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Grid/allocator/MemoryManager.cc b/Grid/allocator/MemoryManager.cc index a9e5c9b4..30a24c9c 100644 --- a/Grid/allocator/MemoryManager.cc +++ b/Grid/allocator/MemoryManager.cc @@ -16,6 +16,44 @@ NAMESPACE_BEGIN(Grid); uint64_t total_shared; uint64_t total_device; uint64_t total_host;; + +#if defined(__has_feature) +#if __has_feature(leak_sanitizer) +#define ASAN_LEAK_CHECK +#endif +#endif + +#ifdef ASAN_LEAK_CHECK +#include +#include +#include +#define LEAK_CHECK(A) { __lsan_do_recoverable_leak_check(); } +#else +#define LEAK_CHECK(A) { } +#endif + +void MemoryManager::DisplayMallinfo(void) +{ +#ifdef __linux__ + struct mallinfo mi; // really want mallinfo2, but glibc version isn't uniform + + mi = mallinfo(); + + std::cout << "MemoryManager: Total non-mmapped bytes (arena): "<< (size_t)mi.arena<