mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
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
This commit is contained in:
parent
0b14259eb2
commit
513a9547f5
@ -21,6 +21,9 @@
|
|||||||
#ifdef HAVE_MALLOC_H
|
#ifdef HAVE_MALLOC_H
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_MALLOC_MALLOC_H
|
||||||
|
#include <malloc/malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//=== WARNING: Implementation here must contain only generic UNIX code that
|
//=== WARNING: Implementation here must contain only generic UNIX code that
|
||||||
@ -43,23 +46,20 @@ Process::GetPageSize()
|
|||||||
return static_cast<unsigned>(page_size);
|
return static_cast<unsigned>(page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_SBRK)
|
size_t Process::GetMallocUsage() {
|
||||||
static char* som = reinterpret_cast<char*>(::sbrk(0));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t
|
|
||||||
Process::GetMallocUsage()
|
|
||||||
{
|
|
||||||
#if defined(HAVE_MALLINFO)
|
#if defined(HAVE_MALLINFO)
|
||||||
struct mallinfo mi;
|
struct mallinfo mi;
|
||||||
mi = ::mallinfo();
|
mi = ::mallinfo();
|
||||||
return mi.uordblks;
|
return mi.uordblks;
|
||||||
|
#elif defined(HAVE_MSTATS) && defined(HAVE_MALLOC_MALLOC_H)
|
||||||
|
return mstats().bytes_used; // darwin
|
||||||
#elif defined(HAVE_SBRK)
|
#elif defined(HAVE_SBRK)
|
||||||
// Note this is only an approximation and more closely resembles
|
// Note this is only an approximation and more closely resembles
|
||||||
// the value returned by mallinfo in the arena field.
|
// the value returned by mallinfo in the arena field.
|
||||||
char * eom = (char*) sbrk(0);
|
static char *StartOfMemory = reinterpret_cast<char*>(::sbrk(0));
|
||||||
if (eom != ((char*)-1) && som != ((char*)-1))
|
char *EndOfMemory = (char*)sbrk(0);
|
||||||
return eom - som;
|
if (EndOfMemory != ((char*)-1) && StartOfMemory != ((char*)-1))
|
||||||
|
return EndOfMemory - StartOfMemory;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
@ -74,6 +74,8 @@ Process::GetTotalMemoryUsage()
|
|||||||
#if defined(HAVE_MALLINFO)
|
#if defined(HAVE_MALLINFO)
|
||||||
struct mallinfo mi = ::mallinfo();
|
struct mallinfo mi = ::mallinfo();
|
||||||
return mi.uordblks + mi.hblkhd;
|
return mi.uordblks + mi.hblkhd;
|
||||||
|
#elif defined(HAVE_MSTATS) && defined(HAVE_MALLOC_MALLOC_H)
|
||||||
|
return mstats().bytes_total; // darwin
|
||||||
#elif defined(HAVE_GETRUSAGE)
|
#elif defined(HAVE_GETRUSAGE)
|
||||||
struct rusage usage;
|
struct rusage usage;
|
||||||
::getrusage(RUSAGE_SELF, &usage);
|
::getrusage(RUSAGE_SELF, &usage);
|
||||||
|
Loading…
Reference in New Issue
Block a user