Bug 741378 - Rejigger the js memory reporters to match jemalloc's. r=njn

This commit is contained in:
Justin Lebar 2012-04-16 12:20:54 +10:00
parent 3224a73351
commit fcfe8663d1
3 changed files with 52 additions and 42 deletions

View File

@ -114,13 +114,15 @@ struct RuntimeStats
, runtimeStackCommitted(0)
, runtimeGCMarker(0)
, gcHeapChunkTotal(0)
, gcHeapCommitted(0)
, gcHeapUnused(0)
, gcHeapChunkCleanUnused(0)
, gcHeapChunkDirtyUnused(0)
, gcHeapChunkCleanDecommitted(0)
, gcHeapChunkDirtyDecommitted(0)
, gcHeapArenaUnused(0)
, gcHeapChunkAdmin(0)
, gcHeapUnusedPercentage(0)
, gcHeapFragmentationPercentage(0)
, totalObjects(0)
, totalShapes(0)
, totalScripts(0)
@ -144,13 +146,15 @@ struct RuntimeStats
size_t runtimeStackCommitted;
size_t runtimeGCMarker;
size_t gcHeapChunkTotal;
size_t gcHeapCommitted;
size_t gcHeapUnused;
size_t gcHeapChunkCleanUnused;
size_t gcHeapChunkDirtyUnused;
size_t gcHeapChunkCleanDecommitted;
size_t gcHeapChunkDirtyDecommitted;
size_t gcHeapArenaUnused;
size_t gcHeapChunkAdmin;
size_t gcHeapUnusedPercentage;
size_t gcHeapFragmentationPercentage;
size_t totalObjects;
size_t totalShapes;
size_t totalScripts;

View File

@ -274,15 +274,21 @@ CollectRuntimeStats(JSRuntime *rt, RuntimeStats *rtStats)
rtStats->gcHeapChunkAdmin = numDirtyChunks * perChunkAdmin;
rtStats->gcHeapChunkDirtyUnused -= rtStats->gcHeapChunkAdmin;
rtStats->gcHeapUnused = rtStats->gcHeapChunkDirtyUnused +
rtStats->gcHeapChunkCleanUnused +
rtStats->gcHeapArenaUnused;
rtStats->gcHeapCommitted = rtStats->gcHeapChunkTotal -
rtStats->gcHeapChunkCleanDecommitted -
rtStats->gcHeapChunkDirtyDecommitted;
// Why 10000x? 100x because it's a percentage, and another 100x
// because nsIMemoryReporter requires that for percentage amounts so
// they can be fractional.
rtStats->gcHeapUnusedPercentage = (rtStats->gcHeapChunkCleanUnused +
rtStats->gcHeapChunkDirtyUnused +
rtStats->gcHeapChunkCleanDecommitted +
rtStats->gcHeapChunkDirtyDecommitted +
rtStats->gcHeapArenaUnused) * 10000 /
rtStats->gcHeapChunkTotal;
rtStats->gcHeapFragmentationPercentage = (rtStats->gcHeapChunkCleanUnused +
rtStats->gcHeapChunkDirtyUnused +
rtStats->gcHeapArenaUnused) * 10000 /
rtStats->gcHeapCommitted;
return true;
}

View File

@ -1250,24 +1250,6 @@ GetCompartmentName(JSCompartment *c, bool getAddress, nsCString &name)
}
}
// We have per-compartment GC heap totals, so we can't put the total GC heap
// size in the explicit allocations tree. But it's a useful figure, so put it
// in the "others" list.
static PRInt64
GetGCChunkTotalBytes()
{
JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->GetJSRuntime();
return PRInt64(JS_GetGCParameter(rt, JSGC_TOTAL_CHUNKS)) * js::gc::ChunkSize;
}
NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSGCHeap,
"js-gc-heap",
KIND_OTHER,
nsIMemoryReporter::UNITS_BYTES,
GetGCChunkTotalBytes,
"Memory used by the garbage-collected JavaScript heap.")
static PRInt64
GetJSSystemCompartmentCount()
{
@ -1390,7 +1372,7 @@ ReportCompartmentStats(const JS::CompartmentStats &cStats,
cStats.gcHeapArenaHeaders,
"Memory on the compartment's garbage-collected JavaScript "
"heap, within arenas, that is used to hold internal "
"book-keeping information.");
"bookkeeping information.");
REPORT_GC_BYTES0(MakePath(pathPrefix, cStats, "gc-heap/arena/padding"),
cStats.gcHeapArenaPadding,
@ -1628,7 +1610,7 @@ ReportJSRuntimeExplicitTreeStats(const JS::RuntimeStats &rtStats,
REPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("gc-heap-chunk-admin"),
rtStats.gcHeapChunkAdmin,
"Memory on the garbage-collected JavaScript heap, within "
"chunks, that is used to hold internal book-keeping "
"chunks, that is used to hold internal bookkeeping "
"information.");
// gcTotal is the sum of everything we've reported for the GC heap. It
@ -1779,12 +1761,6 @@ public:
"Shown here for easy comparison with other 'js-gc' "
"reporters.");
REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-decommitted"),
nsIMemoryReporter::KIND_OTHER,
rtStats.gcHeapChunkCleanDecommitted + rtStats.gcHeapChunkDirtyDecommitted,
"The same as 'explicit/js/gc-heap-decommitted'. Shown "
"here for easy comparison with other 'js-gc' reporters.");
REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-arena-unused"),
nsIMemoryReporter::KIND_OTHER,
rtStats.gcHeapArenaUnused,
@ -1793,15 +1769,40 @@ public:
"useful data but currently isn't. This is the sum of all "
"compartments' 'gc-heap/arena-unused' numbers.");
REPORT(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-unused-fraction"),
REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-unused"),
nsIMemoryReporter::KIND_OTHER,
rtStats.gcHeapUnused,
"Amount of the GC heap that's committed, but that is "
"neither part of an active allocation nor being used for "
"bookkeeping. Equal to 'gc-heap-chunk-dirty-unused' + "
"'gc-heap-chunk-clean-unused' + 'gc-heap-arena-unused'.");
REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed"),
nsIMemoryReporter::KIND_OTHER,
rtStats.gcHeapCommitted,
"Committed memory (i.e., in physical memory or swap) "
"used by the garbage-collected JavaScript heap.");
REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-allocated"),
nsIMemoryReporter::KIND_OTHER,
(rtStats.gcHeapCommitted - rtStats.gcHeapUnused),
"Amount of the GC heap used for active allocations and "
"bookkeeping. This is calculated as 'gc-heap-committed' "
"- 'gc-heap-unused'.");
REPORT(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-fragmentation"),
nsIMemoryReporter::KIND_OTHER,
nsIMemoryReporter::UNITS_PERCENTAGE,
rtStats.gcHeapUnusedPercentage,
"Fraction of the main JSRuntime's garbage-collected JavaScript "
"heap that is unused. Computed as "
"('js-gc-heap-chunk-clean-unused' + "
"'js-gc-heap-chunk-dirty-unused' + 'js-gc-heap-decommitted' + "
"'js-gc-heap-arena-unused') / 'js-gc-heap'.");
rtStats.gcHeapFragmentationPercentage,
"Fraction of the committed part of the main JSRuntime's "
"garbage-collected heap that is unused. Computed as "
"'gc-heap-unused' / 'gc-heap-committed'.");
REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-decommitted"),
nsIMemoryReporter::KIND_OTHER,
rtStats.gcHeapChunkCleanDecommitted + rtStats.gcHeapChunkDirtyDecommitted,
"The same as 'explicit/js/gc-heap-decommitted'. Shown "
"here for easy comparison with other 'js-gc' reporters.");
REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-objects"),
nsIMemoryReporter::KIND_OTHER, rtStats.totalObjects,
@ -2008,7 +2009,6 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
JS_SetAccumulateTelemetryCallback(mJSRuntime, AccumulateTelemetryCallback);
js::SetActivityCallback(mJSRuntime, ActivityCallback, this);
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSGCHeap));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSSystemCompartmentCount));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSUserCompartmentCount));
NS_RegisterMemoryMultiReporter(new JSMemoryMultiReporter);