Bug 692963 - Report heap-committed-unallocated-fraction in about:memory. r=khuey
authorJustin Lebar <justin.lebar@gmail.com>
Mon, 10 Oct 2011 13:57:05 -0400
changeset 79000 a5aa295c2b8620e785b9a4cef7ba7f79cc9912a8
parent 78999 371619a1550941b6e2bbaabd4e9b3df5e95c5154
child 79001 a9eacbb0e411fc2c837dcb114d72eadde45d4f9e
push idunknown
push userunknown
push dateunknown
reviewerskhuey
bugs692963
milestone10.0a1
Bug 692963 - Report heap-committed-unallocated-fraction in about:memory. r=khuey
xpcom/base/nsMemoryReporterManager.cpp
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -291,16 +291,23 @@ static PRInt64 GetHeapAllocated()
 
 static PRInt64 GetHeapCommitted()
 {
     jemalloc_stats_t stats;
     jemalloc_stats(&stats);
     return (PRInt64) stats.committed;
 }
 
+static PRInt64 GetHeapCommittedUnallocatedFraction()
+{
+    jemalloc_stats_t stats;
+    jemalloc_stats(&stats);
+    return (PRInt64) 10000 * (1 - stats.allocated / (double)stats.committed);
+}
+
 static PRInt64 GetHeapDirty()
 {
     jemalloc_stats_t stats;
     jemalloc_stats(&stats);
     return (PRInt64) stats.dirty;
 }
 
 NS_MEMORY_REPORTER_IMPLEMENT(HeapCommitted,
@@ -310,16 +317,26 @@ NS_MEMORY_REPORTER_IMPLEMENT(HeapCommitt
     GetHeapCommitted,
     "Memory mapped by the heap allocator that is committed, i.e. in physical "
     "memory or paged to disk.  When heap-committed is larger than "
     "heap-allocated, the difference between the two values is likely due to "
     "external fragmentation; that is, the allocator allocated a large block of "
     "memory and is unable to decommit it because a small part of that block is "
     "currently in use.")
 
+NS_MEMORY_REPORTER_IMPLEMENT(HeapCommittedUnallocatedFraction,
+    "heap-committed-unallocated-fraction",
+    KIND_OTHER,
+    UNITS_PERCENTAGE,
+    GetHeapCommittedUnallocatedFraction,
+    "Fraction of committed bytes which do not correspond to an active "
+    "allocation; i.e., 1 - (heap-allocated / heap-committed).  Although the "
+    "allocator will waste some space under any circumstances, a large value here "
+    "may indicate that the heap is highly fragmented.")
+
 NS_MEMORY_REPORTER_IMPLEMENT(HeapDirty,
     "heap-dirty",
     KIND_OTHER,
     UNITS_BYTES,
     GetHeapDirty,
     "Memory which the allocator could return to the operating system, but "
     "hasn't.  The allocator keeps this memory around as an optimization, so it "
     "doesn't have to ask the OS the next time it needs to fulfill a request. "
@@ -433,16 +450,17 @@ nsMemoryReporterManager::Init()
 #endif
 
 #if defined(XP_WIN) && MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
     REGISTER(Private);
 #endif
 
 #if defined(HAVE_JEMALLOC_STATS)
     REGISTER(HeapCommitted);
+    REGISTER(HeapCommittedUnallocatedFraction);
     REGISTER(HeapDirty);
 #elif defined(XP_MACOSX) && !defined(MOZ_MEMORY)
     REGISTER(HeapZone0Committed);
     REGISTER(HeapZone0Used);
 #endif
 
     return NS_OK;
 }