Bug 672694 - Add memory reporters to count compartments. r=gal.

This commit is contained in:
Nicholas Nethercote 2011-07-21 00:20:47 -07:00
parent ea48669ae1
commit a29b258004

View File

@ -276,7 +276,7 @@ CompartmentCallback(JSContext *cx, JSCompartment *compartment, uintN op)
XPCCompartmentMap &map = self->GetCompartmentMap(); XPCCompartmentMap &map = self->GetCompartmentMap();
#ifdef DEBUG #ifdef DEBUG
{ {
JSCompartment *current; JSCompartment *current = NULL; // init to shut GCC up
NS_ASSERTION(map.Get(key, &current), "no compartment?"); NS_ASSERTION(map.Get(key, &current), "no compartment?");
NS_ASSERTION(current == compartment, "compartment mismatch"); NS_ASSERTION(current == compartment, "compartment mismatch");
} }
@ -1300,6 +1300,59 @@ NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSStack,
"of the stack; any uncommitted portion is not measured because it " "of the stack; any uncommitted portion is not measured because it "
"hardly costs anything.") "hardly costs anything.")
static PRInt64
GetJSSystemCompartmentCount()
{
JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->GetJSRuntime();
size_t n = 0;
for (size_t i = 0; i < rt->compartments.length(); i++) {
if (rt->compartments[i]->isSystemCompartment) {
n++;
}
}
return n;
}
static PRInt64
GetJSUserCompartmentCount()
{
JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->GetJSRuntime();
size_t n = 0;
for (size_t i = 0; i < rt->compartments.length(); i++) {
if (!rt->compartments[i]->isSystemCompartment) {
n++;
}
}
return n;
}
// Nb: js-system-compartment-count + js-user-compartment-count could be
// different to the number of compartments reported by
// XPConnectJSCompartmentsMultiReporter if a garbage collection occurred
// between them being consulted. We could move these reporters into
// XPConnectJSCompartmentCount to avoid that problem, but then we couldn't
// easily report them via telemetry, so we live with the small risk of
// inconsistencies.
NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSSystemCompartmentCount,
"js-compartments-system",
KIND_OTHER,
nsIMemoryReporter::UNITS_COUNT,
GetJSSystemCompartmentCount,
"The number of JavaScript compartments for system code. The sum of this "
"and 'js-compartments-user' might not match the number of "
"compartments listed under 'js' if a garbage collection occurs at an "
"inopportune time, but such cases should be rare.")
NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSUserCompartmentCount,
"js-compartments-user",
KIND_OTHER,
nsIMemoryReporter::UNITS_COUNT,
GetJSUserCompartmentCount,
"The number of JavaScript compartments for user code. The sum of this "
"and 'js-compartments-system' might not match the number of "
"compartments listed under 'js' if a garbage collection occurs at an "
"inopportune time, but such cases should be rare.")
class XPConnectJSCompartmentsMultiReporter : public nsIMemoryMultiReporter class XPConnectJSCompartmentsMultiReporter : public nsIMemoryMultiReporter
{ {
private: private:
@ -1798,6 +1851,8 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSGCHeap)); NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSGCHeap));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSStack)); NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSStack));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSSystemCompartmentCount));
NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSUserCompartmentCount));
NS_RegisterMemoryMultiReporter(new XPConnectJSCompartmentsMultiReporter); NS_RegisterMemoryMultiReporter(new XPConnectJSCompartmentsMultiReporter);
} }