Bug 762445 - Add jemalloc3 glue for heap-committed, heap-dirty in about:memory. r=glandium,jlebar
authorJan Beich <jbeich@tormail.org>
Thu, 18 Oct 2012 16:09:07 +0200
changeset 110800 199e231bfa7f663382ab171cee9620ad5021ada8
parent 110799 38784da3792d7c078be6102b8ba684884e5153ff
child 110801 83d4508b92d318a2d0c7cc919983d3750580105e
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersglandium, jlebar
bugs762445
milestone19.0a1
Bug 762445 - Add jemalloc3 glue for heap-committed, heap-dirty in about:memory. r=glandium,jlebar
memory/build/mozjemalloc_compat.c
--- a/memory/build/mozjemalloc_compat.c
+++ b/memory/build/mozjemalloc_compat.c
@@ -6,20 +6,55 @@
 #include "jemalloc_types.h"
 
 #if defined(MOZ_NATIVE_JEMALLOC)
 #define wrap(a) a
 #else
 #define wrap(a) je_ ## a
 #endif
 
-extern MOZ_IMPORT_API(int)
+/*
+ *  CTL_* macros are from memory/jemalloc/src/src/stats.c with changes:
+ *  - drop `t' argument to avoid redundancy in calculating type size
+ *  - require `i' argument for arena number explicitly
+ */
+
+#define	CTL_GET(n, v) do {						\
+	size_t sz = sizeof(v);						\
+	wrap(mallctl)(n, &v, &sz, NULL, 0);				\
+} while (0)
+
+#define	CTL_I_GET(n, v, i) do {						\
+	size_t mib[6];							\
+	size_t miblen = sizeof(mib) / sizeof(mib[0]);			\
+	size_t sz = sizeof(v);						\
+	wrap(mallctlnametomib)(n, mib, &miblen);			\
+	mib[2] = i;							\
+	wrap(mallctlbymib)(mib, miblen, &v, &sz, NULL, 0);		\
+} while (0)
+
+MOZ_IMPORT_API(int)
 wrap(mallctl)(const char*, void*, size_t*, void*, size_t);
+MOZ_IMPORT_API(int)
+wrap(mallctlnametomib)(const char *name, size_t *mibp, size_t *miblenp);
+MOZ_IMPORT_API(int)
+wrap(mallctlbymib)(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
 
 MOZ_EXPORT_API(void)
 jemalloc_stats(jemalloc_stats_t *stats)
 {
-  size_t size = sizeof(stats->mapped);
-  wrap(mallctl)("stats.mapped", &stats->mapped, &size, NULL, 0);
-  wrap(mallctl)("stats.allocated", &stats->allocated, &size, NULL, 0);
-  stats->committed = -1;
-  stats->dirty = -1;
+  unsigned narenas;
+  size_t active, allocated, mapped, page, pdirty;
+
+  CTL_GET("arenas.narenas", narenas);
+  CTL_GET("arenas.page", page);
+  CTL_GET("stats.active", active);
+  CTL_GET("stats.allocated", allocated);
+  CTL_GET("stats.mapped", mapped);
+
+  /* get the summation for all arenas, i == narenas */
+  CTL_I_GET("stats.arenas.0.pdirty", pdirty, narenas);
+
+  stats->allocated = allocated;
+  stats->mapped = mapped;
+  stats->dirty = pdirty * page;
+  stats->committed = active + stats->dirty;
 }