Bug 605362, part 3: Add MemoryReporters for shmem. r=vlad

This commit is contained in:
Chris Jones 2010-11-05 02:17:07 -05:00
Родитель 58cd28b141
Коммит d842dc7390
2 изменённых файлов: 72 добавлений и 0 удалений

Просмотреть файл

@ -40,11 +40,40 @@
#include <math.h>
#include "nsIMemoryReporter.h"
#include "mozilla/ipc/SharedMemory.h"
namespace mozilla {
namespace ipc {
static PRInt64 gShmemAllocated;
static PRInt64 gShmemMapped;
static PRInt64 GetShmemAllocated(void*) { return gShmemAllocated; }
static PRInt64 GetShmemMapped(void*) { return gShmemMapped; }
NS_MEMORY_REPORTER_IMPLEMENT(ShmemAllocated,
"shmem/allocated",
"Shmem bytes accessible (not necessarily mapped)",
GetShmemAllocated,
nsnull)
NS_MEMORY_REPORTER_IMPLEMENT(ShmemMapped,
"shmem/mapped",
"Shmem bytes mapped into address space",
GetShmemMapped,
nsnull)
SharedMemory::SharedMemory()
{
// NB: SharedMemory is main-thread-only at the moment, but that may
// change soon
static bool registered;
if (!registered) {
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(ShmemAllocated));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(ShmemMapped));
registered = true;
}
}
/*static*/ size_t
SharedMemory::PageAlignedSize(size_t aSize)
{
@ -53,5 +82,33 @@ SharedMemory::PageAlignedSize(size_t aSize)
return pageSize * nPagesNeeded;
}
/*static*/ void
SharedMemory::Created(size_t aNBytes)
{
gShmemAllocated += aNBytes;
}
/*static*/ void
SharedMemory::Mapped(size_t aNBytes)
{
gShmemMapped += aNBytes;
}
/*static*/ void
SharedMemory::Unmapped(size_t aNBytes)
{
NS_ABORT_IF_FALSE(gShmemMapped >= PRInt64(aNBytes),
"Can't unmap more than mapped");
gShmemMapped -= aNBytes;
}
/*static*/ void
SharedMemory::Destroyed(size_t aNBytes)
{
NS_ABORT_IF_FALSE(gShmemAllocated >= PRInt64(aNBytes),
"Can't destroy more than allocated");
gShmemAllocated -= aNBytes;
}
} // namespace ipc
} // namespace mozilla

Просмотреть файл

@ -104,6 +104,21 @@ public:
static void SystemProtect(char* aAddr, size_t aSize, int aRights);
static size_t SystemPageSize();
static size_t PageAlignedSize(size_t aSize);
protected:
SharedMemory();
// Implementations should call these methods on shmem usage changes,
// but *only if* the OS-specific calls are known to have succeeded.
// The methods are expected to be called in the pattern
//
// Created (Mapped Unmapped)* Destroy
//
// but this isn't checked.
static void Created(size_t aNBytes);
static void Mapped(size_t aNBytes);
static void Unmapped(size_t aNBytes);
static void Destroyed(size_t aNBytes);
};
} // namespace ipc