diff options
author | Chris Lattner <sabre@nondot.org> | 2005-11-14 07:00:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-11-14 07:00:29 +0000 |
commit | 513a9547f50bda29d4795fc8869ce80c120d8387 (patch) | |
tree | 7c0255ada91b882167a03c29f3b58b77da0a1f55 /lib/System | |
parent | 0b14259eb2b2663ca9ee02ad8919b27e2723d330 (diff) | |
download | external_llvm-513a9547f50bda29d4795fc8869ce80c120d8387.zip external_llvm-513a9547f50bda29d4795fc8869ce80c120d8387.tar.gz external_llvm-513a9547f50bda29d4795fc8869ce80c120d8387.tar.bz2 |
Teach -track-memory to work on darwin. Looking at sbrk doesn't work because
the default allocator uses mmap.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24349 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r-- | lib/System/Unix/Process.inc | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/System/Unix/Process.inc b/lib/System/Unix/Process.inc index e5a9378..f73444f 100644 --- a/lib/System/Unix/Process.inc +++ b/lib/System/Unix/Process.inc @@ -21,6 +21,9 @@ #ifdef HAVE_MALLOC_H #include <malloc.h> #endif +#ifdef HAVE_MALLOC_MALLOC_H +#include <malloc/malloc.h> +#endif //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only generic UNIX code that @@ -43,23 +46,20 @@ Process::GetPageSize() return static_cast<unsigned>(page_size); } -#if defined(HAVE_SBRK) -static char* som = reinterpret_cast<char*>(::sbrk(0)); -#endif - -size_t -Process::GetMallocUsage() -{ +size_t Process::GetMallocUsage() { #if defined(HAVE_MALLINFO) struct mallinfo mi; mi = ::mallinfo(); return mi.uordblks; +#elif defined(HAVE_MSTATS) && defined(HAVE_MALLOC_MALLOC_H) + return mstats().bytes_used; // darwin #elif defined(HAVE_SBRK) // Note this is only an approximation and more closely resembles // the value returned by mallinfo in the arena field. - char * eom = (char*) sbrk(0); - if (eom != ((char*)-1) && som != ((char*)-1)) - return eom - som; + static char *StartOfMemory = reinterpret_cast<char*>(::sbrk(0)); + char *EndOfMemory = (char*)sbrk(0); + if (EndOfMemory != ((char*)-1) && StartOfMemory != ((char*)-1)) + return EndOfMemory - StartOfMemory; else return 0; #else @@ -74,6 +74,8 @@ Process::GetTotalMemoryUsage() #if defined(HAVE_MALLINFO) struct mallinfo mi = ::mallinfo(); return mi.uordblks + mi.hblkhd; +#elif defined(HAVE_MSTATS) && defined(HAVE_MALLOC_MALLOC_H) + return mstats().bytes_total; // darwin #elif defined(HAVE_GETRUSAGE) struct rusage usage; ::getrusage(RUSAGE_SELF, &usage); |