diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index 4b1f5633ab9..806c8f721d1 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -64,7 +64,7 @@ extern void jemalloc_stats(jemalloc_stats_t* stats) # endif // XP_LINUX #endif // MOZ_MEMORY -#if defined(XP_LINUX) || defined(XP_MACOSX) +#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(SOLARIS) #include #include @@ -122,6 +122,52 @@ static PRInt64 GetResident() return GetProcSelfStatmField(1); } +#elif defined(SOLARIS) + +#include +#include +#include + +static void XMappingIter(PRInt64& Vsize, PRInt64& Resident) +{ + int mapfd = open("/proc/self/xmap", O_RDONLY); + struct stat st; + prxmap_t *prmapp; + if (mapfd >= 0) { + if (!fstat(mapfd, &st)) { + int nmap = st.st_size / sizeof(prxmap_t); + prmapp = (prxmap_t*)malloc((nmap + 1) * sizeof(prxmap_t)); + int n = read(mapfd, prmapp, (nmap + 1) * sizeof(prxmap_t)); + if (n > 0) { + Vsize = 0; + Resident = 0; + for (int i = 0; i < n / sizeof(prxmap_t); i++) { + Vsize += prmapp[i].pr_size; + Resident += prmapp[i].pr_rss * prmapp[i].pr_pagesize; + } + } + free(prmapp); + } + close(mapfd); + } +} + +static PRInt64 GetVsize() +{ + PRInt64 Vsize = -1; + PRInt64 Resident = -1; + XMappingIter(Vsize, Resident); + return Vsize; +} + +static PRInt64 GetResident() +{ + PRInt64 Vsize = -1; + PRInt64 Resident = -1; + XMappingIter(Vsize, Resident); + return Resident; +} + #elif defined(XP_MACOSX) #include @@ -224,7 +270,7 @@ static PRInt64 GetResident() #endif -#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN) +#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN) || defined(SOLARIS) NS_MEMORY_REPORTER_IMPLEMENT(Vsize, "vsize", KIND_OTHER, @@ -239,7 +285,7 @@ NS_MEMORY_REPORTER_IMPLEMENT(Vsize, "measure of the memory resources used by the process.") #endif -#if defined(XP_LINUX) || defined(XP_MACOSX) +#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(SOLARIS) NS_MEMORY_REPORTER_IMPLEMENT(PageFaultsSoft, "page-faults-soft", KIND_OTHER, @@ -457,11 +503,11 @@ nsMemoryReporterManager::Init() REGISTER(HeapUnallocated); REGISTER(Resident); -#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN) +#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN) || defined(SOLARIS) REGISTER(Vsize); #endif -#if defined(XP_LINUX) || defined(XP_MACOSX) +#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(SOLARIS) REGISTER(PageFaultsSoft); REGISTER(PageFaultsHard); #endif