Bug 761723 - Add memory reporting for script sources. r=njn

--HG--
extra : rebase_source : 5f2cdb960f29829e9da19bbe137a810f456cc7fc
This commit is contained in:
Benjamin Peterson 2012-07-20 20:18:08 +02:00
parent 78a5439268
commit dfea65352c
5 changed files with 21 additions and 0 deletions

View File

@ -56,6 +56,7 @@ struct RuntimeSizes
, gcMarker(0)
, mathCache(0)
, scriptFilenames(0)
, scriptSources(0)
, compartmentObjects(0)
{}
@ -71,6 +72,7 @@ struct RuntimeSizes
size_t gcMarker;
size_t mathCache;
size_t scriptFilenames;
size_t scriptSources;
// This is the exception to the "RuntimeSizes doesn't measure things within
// compartments" rule. We combine the sizes of all the JSCompartment

View File

@ -105,6 +105,10 @@ JSRuntime::sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf, RuntimeSizes *run
for (ScriptFilenameTable::Range r = scriptFilenameTable.all(); !r.empty(); r.popFront())
runtime->scriptFilenames += mallocSizeOf(r.front());
runtime->scriptSources = 0;
for (ScriptSource *n = scriptSources; n; n = n->next)
runtime->scriptSources += n->sizeOfIncludingThis(mallocSizeOf);
runtime->compartmentObjects = 0;
CallbackData data(mallocSizeOf);
JS_IterateCompartments(this, &data, CompartmentCallback);

View File

@ -1237,6 +1237,16 @@ ScriptSource::destroy(JSRuntime *rt)
rt->free_(this);
}
size_t
ScriptSource::sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf)
{
JS_ASSERT(onRuntime());
JS_ASSERT(ready());
// data is a union, but both members are pointers to allocated memory, so
// just using compressed will work.
return mallocSizeOf(this) + mallocSizeOf(data.compressed);
}
void
ScriptSource::sweep(JSRuntime *rt)
{

View File

@ -989,6 +989,7 @@ struct ScriptSource
bool ready() const { return ready_; }
#endif
JSFixedString *substring(JSContext *cx, uint32_t start, uint32_t stop);
size_t sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf);
// For the GC.
static void sweep(JSRuntime *rt);

View File

@ -1544,6 +1544,10 @@ ReportJSRuntimeExplicitTreeStats(const JS::RuntimeStats &rtStats,
nsIMemoryReporter::KIND_HEAP, rtStats.runtime.scriptFilenames,
"Memory used for the table holding script filenames.");
RREPORT_BYTES(rtPath + NS_LITERAL_CSTRING("runtime/script-sources"),
nsIMemoryReporter::KIND_HEAP, rtStats.runtime.scriptSources,
"Memory use for storing JavaScript source code.");
RREPORT_BYTES(rtPath + NS_LITERAL_CSTRING("runtime/compartment-objects"),
nsIMemoryReporter::KIND_HEAP, rtStats.runtime.compartmentObjects,
"Memory used for JSCompartment objects. These are fairly "