[llvm-commits] [vector_llvm] CVS: llvm/lib/System/Unix/Process.inc

Robert Bocchino bocchino at cs.uiuc.edu
Wed Nov 16 10:32:40 PST 2005



Changes in directory llvm/lib/System/Unix:

Process.inc updated: 1.11 -> 1.11.4.1
---
Log message:

Merged mainline into Vector LLVM branch


---
Diffs of the changes:  (+16 -10)

 Process.inc |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)


Index: llvm/lib/System/Unix/Process.inc
diff -u llvm/lib/System/Unix/Process.inc:1.11 llvm/lib/System/Unix/Process.inc:1.11.4.1
--- llvm/lib/System/Unix/Process.inc:1.11	Thu May  5 17:33:06 2005
+++ llvm/lib/System/Unix/Process.inc	Wed Nov 16 12:32:28 2005
@@ -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,22 @@
   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_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H)
+  malloc_statistics_t Stats;
+  malloc_zone_statistics(malloc_default_zone(), &Stats);
+  return Stats.size_in_use;   // 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 +76,10 @@
 #if defined(HAVE_MALLINFO)
   struct mallinfo mi = ::mallinfo();
   return mi.uordblks + mi.hblkhd;
+#elif defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H)
+  malloc_statistics_t Stats;
+  malloc_zone_statistics(malloc_default_zone(), &Stats);
+  return Stats.size_allocated;   // darwin
 #elif defined(HAVE_GETRUSAGE)
   struct rusage usage;
   ::getrusage(RUSAGE_SELF, &usage);






More information about the llvm-commits mailing list