about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--autoconf/configure.ac6
-rw-r--r--lib/Support/MemoryUsage.cpp10
2 files changed, 14 insertions, 2 deletions
diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index f1b2dfc3..c6e59d97 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -498,9 +498,11 @@ AC_CHECK_HEADERS([selinux/selinux.h],
 dnl **************************************************************************
 dnl Test for features
 dnl **************************************************************************
+
+AC_CHECK_HEADERS([malloc/malloc.h])
+AC_CHECK_FUNCS([malloc_zone_statistics])
 AC_SEARCH_LIBS(mallinfo,malloc,
-               AC_DEFINE([HAVE_MALLINFO],[1],[Define if mallinfo() is available on this platform.]),
-               AC_MSG_WARN([mallinfo() was not found - disabling memory usage checking]))
+               AC_DEFINE([HAVE_MALLINFO],[1],[Define if mallinfo() is available on this platform.]))
 
 dnl **************************************************************************
 dnl Find an install of STP
diff --git a/lib/Support/MemoryUsage.cpp b/lib/Support/MemoryUsage.cpp
index 6143b127..32a7eb3b 100644
--- a/lib/Support/MemoryUsage.cpp
+++ b/lib/Support/MemoryUsage.cpp
@@ -14,6 +14,9 @@
 #ifdef HAVE_MALLINFO
 #include <malloc.h>
 #endif
+#ifdef HAVE_MALLOC_MALLOC_H
+#include <malloc/malloc.h>
+#endif
 
 using namespace klee;
 
@@ -29,6 +32,13 @@ size_t util::GetTotalMallocUsage() {
   return mi.uordblks;
 #endif
 
+#elif defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H)
+
+  // Support memory usage on Darwin.
+  malloc_statistics_t Stats;
+  malloc_zone_statistics(malloc_default_zone(), &Stats);
+  return Stats.size_in_use;
+
 #else // HAVE_MALLINFO
 
 #warning Cannot get malloc info on this platform