about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2014-09-12 14:05:12 -0700
committerDaniel Dunbar <daniel@zuster.org>2014-09-12 17:39:17 -0700
commit13ae5fef303a54da6d9e2a30b23c3209c0a20d45 (patch)
tree2e3e35e94be98a4a0777abd83f9c70034820d5a8
parent4444e21e7926ca079583f14a51cca0bf5e01b711 (diff)
downloadklee-13ae5fef303a54da6d9e2a30b23c3209c0a20d45.tar.gz
Add support for getting memory usage on Darwin.
-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