From f0fd4f84e60dae72c122421c40999617de175f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Thu, 12 May 2022 18:25:52 +0200 Subject: [PATCH] #1513: use `mallinfo2` when available --- cmake/check_system_functions.cmake | 1 + cmake_config.h.in | 1 + src/vt/utils/memory/memory_usage.cc | 16 ++++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmake/check_system_functions.cmake b/cmake/check_system_functions.cmake index b29083333b..14aa261bed 100644 --- a/cmake/check_system_functions.cmake +++ b/cmake/check_system_functions.cmake @@ -22,6 +22,7 @@ check_function_exists(sysconf vt_has_sysconf) set(CMAKE_REQUIRED_INCLUDES "malloc.h") check_function_exists(mallinfo vt_has_mallinfo) +check_function_exists(mallinfo2 vt_has_mallinfo2) set(CMAKE_REQUIRED_INCLUDES "sys/resource.h") check_function_exists(getrusage vt_has_getrusage) diff --git a/cmake_config.h.in b/cmake_config.h.in index a71513913a..686c98e95e 100644 --- a/cmake_config.h.in +++ b/cmake_config.h.in @@ -82,6 +82,7 @@ #cmakedefine vt_has_pclose #cmakedefine vt_has_sbrk #cmakedefine vt_has_mallinfo +#cmakedefine vt_has_mallinfo2 #cmakedefine vt_has_getrusage #cmakedefine vt_has_sysinfo #cmakedefine vt_has_mach_task_self diff --git a/src/vt/utils/memory/memory_usage.cc b/src/vt/utils/memory/memory_usage.cc index 92bf78e672..4d9344325d 100644 --- a/src/vt/utils/memory/memory_usage.cc +++ b/src/vt/utils/memory/memory_usage.cc @@ -145,13 +145,17 @@ std::string PS::getName() { } std::size_t Mallinfo::getUsage() { -# if defined(vt_has_mallinfo) && defined(vt_has_malloc_h) && !vt_check_enabled(mimalloc) - struct mallinfo mi = mallinfo(); - unsigned int blocks = mi.uordblks; - return static_cast(blocks); -# else - return 0; +#if vt_check_enabled(mimalloc) || \ + !defined(vt_has_mallinfo) && !defined(vt_has_mallinfo2) + return 0; # endif + +#if defined(vt_has_mallinfo2) + auto mi = mallinfo2(); +#elif defined(vt_has_mallinfo) + auto mi = mallinfo(); +#endif + return static_cast(mi.uordblks); } std::string Mallinfo::getName() {