Bug 947802 (part 2) - Replace enumerateReporters() with getReportsForThisProcess(). r=mccr8.

--HG--
extra : rebase_source : 1c70e838e3600745f69c5772a084398f78d4c477
This commit is contained in:
Nicholas Nethercote 2013-12-01 16:29:37 -08:00
parent 7b9f6814c3
commit 1e79a74289
9 changed files with 57 additions and 98 deletions

View File

@ -377,11 +377,7 @@ function getPotentialLeaks() {
let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
getService(Ci.nsIMemoryReporterManager);
let enm = mgr.enumerateReporters();
while (enm.hasMoreElements()) {
let mr = enm.getNext().QueryInterface(Ci.nsIMemoryReporter);
mr.collectReports(logReporter, null);
}
mgr.getReportsForThisProcess(logReporter, null);
return { compartments: compartments, windows: windows };
}

View File

@ -1687,7 +1687,7 @@ ReportAndDump(JSContext *cx, unsigned argc, JS::Value *vp)
dmd::ClearReports();
fprintf(stderr, "DMD: running reporters...\n");
dmd::RunReporters();
dmd::RunReportersForThisProcess();
dmd::Writer writer(FpWrite, fp);
dmd::Dump(writer);

View File

@ -497,19 +497,12 @@ ContentChild::RecvPMemoryReportRequestConstructor(
GetProcessName(process);
AppendProcessId(process);
// Run each reporter. The callback will turn each measurement into a
// Run the reporters. The callback will turn each measurement into a
// MemoryReport.
nsCOMPtr<nsISimpleEnumerator> e;
mgr->EnumerateReporters(getter_AddRefs(e));
nsRefPtr<MemoryReportsWrapper> wrappedReports =
new MemoryReportsWrapper(&reports);
nsRefPtr<MemoryReportCallback> cb = new MemoryReportCallback(process);
bool more;
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
nsCOMPtr<nsIMemoryReporter> r;
e->GetNext(getter_AddRefs(r));
r->CollectReports(cb, wrappedReports);
}
mgr->GetReportsForThisProcess(cb, wrappedReports);
child->Send__delete__(child, generation, reports);
return true;

View File

@ -30,11 +30,7 @@ window.onload = function() {
amount += aAmount;
}
var e = mgr.enumerateReporters();
while (e.hasMoreElements()) {
var mr = e.getNext().QueryInterface(SpecialPowers.Ci.nsIMemoryReporter);
mr.collectReports(handleReport, null);
}
mgr.getReportsForThisProcess(handleReport, null);
ok(amount > 0, "we should be using a nonzero amount of memory");
ok(true, "yay, didn't crash!");

View File

@ -171,11 +171,7 @@
domSize, styleSize, otherSize, totalSize,
jsMilliseconds, nonJSMilliseconds);
let e = mgr.enumerateReporters();
while (e.hasMoreElements()) {
let r = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
r.collectReports(handleReport, null);
}
mgr.getReportsForThisProcess(handleReport, null);
function checkSpecialReport(aName, aAmounts, aCanBeUnreasonable)
{

View File

@ -40,11 +40,7 @@
// them. It shouldn't crash.
let mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
getService(Ci.nsIMemoryReporterManager);
e = mgr.enumerateReporters();
while (e.hasMoreElements()) {
let r = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
r.collectReports(function(){}, null);
}
mgr.getReportsForThisProcess(function(){}, null);
// If we haven't crashed, we've passed, but the test harness requires that
// we explicitly check something.

View File

@ -178,7 +178,7 @@ interface nsIFinishReportingCallback : nsISupports
void callback(in nsISupports data);
};
[scriptable, builtinclass, uuid(9245d89e-6523-45f9-bc15-a69789e33cbb)]
[scriptable, builtinclass, uuid(2b61d644-1520-420a-8f52-d06e615c1ff6)]
interface nsIMemoryReporterManager : nsISupports
{
/*
@ -187,10 +187,9 @@ interface nsIMemoryReporterManager : nsISupports
void init();
/*
* Register the given nsIMemoryReporter. After a reporter is registered,
* it will be available via enumerateReporters(). The Manager service
* will hold a strong reference to the given reporter, and will be
* responsible for freeing the reporter at shutdown.
* Register the given nsIMemoryReporter. The Manager service will hold a
* strong reference to the given reporter, and will be responsible for freeing
* the reporter at shutdown.
*/
void registerStrongReporter(in nsIMemoryReporter reporter);
@ -214,14 +213,6 @@ interface nsIMemoryReporterManager : nsISupports
void unblockRegistrationAndRestoreOriginalReporters();
void registerStrongReporterEvenIfBlocked(in nsIMemoryReporter aReporter);
/*
* Return an enumerator of nsIMemoryReporters that are currently registered
* in the current process. WARNING: this does not do anything with child
* processes. Use getReports() if you want measurements from child
* processes.
*/
nsISimpleEnumerator enumerateReporters();
/*
* Get memory reports for the current process and all child processes.
* |handleReport| is called for each report, and |finishReporting| is called
@ -240,6 +231,13 @@ interface nsIMemoryReporterManager : nsISupports
in nsIFinishReportingCallback finishReporting,
in nsISupports finishReportingData);
/*
* Get memory reports in the current process only. |handleReport| is called
* for each report.
*/
void getReportsForThisProcess(in nsIMemoryReporterCallback handleReport,
in nsISupports handleReportData);
/*
* The memory reporter manager, for the most part, treats reporters
* registered with it as a black box. However, there are some
@ -248,8 +246,9 @@ interface nsIMemoryReporterManager : nsISupports
* interesting that we want external code (e.g. telemetry) to be able to rely
* on them.
*
* Note that these are not reporters and so enumerateReporters() does not
* look at them. However, they can be embedded in a reporter.
* Note that these are not reporters and so getReports() and
* getReportsForThisProcess() do not look at them. However, distinguished
* amounts can be embedded in a reporter.
*
* Access to these attributes can fail. In particular, some of them are not
* available on all platforms.
@ -441,7 +440,7 @@ namespace dmd {
// This runs all the memory reporters in the current process but does nothing
// with the results; i.e. it does the minimal amount of work possible for DMD
// to do its thing. It does nothing with child processes.
void RunReporters();
void RunReportersForThisProcess();
}
}

View File

@ -831,17 +831,10 @@ DumpProcessMemoryReportsToGZFileWriter(nsGZFileWriter* aWriter)
NS_ENSURE_SUCCESS(rv, rv);
// Process reporters.
bool more;
nsCOMPtr<nsISimpleEnumerator> e;
nsCOMPtr<nsIMemoryReporterManager> mgr =
do_GetService("@mozilla.org/memory-reporter-manager;1");
mgr->EnumerateReporters(getter_AddRefs(e));
nsRefPtr<DumpReportCallback> dumpReport = new DumpReportCallback(aWriter);
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
nsCOMPtr<nsIMemoryReporter> r;
e->GetNext(getter_AddRefs(r));
r->CollectReports(dumpReport, nullptr);
}
mgr->GetReportsForThisProcess(dumpReport, nullptr);
return DumpFooter(aWriter);
}
@ -878,7 +871,8 @@ DumpProcessMemoryInfoToTempDir(const nsAString& aIdentifier)
rv = nsMemoryInfoDumper::OpenTempFile(NS_LITERAL_CSTRING("incomplete-") +
mrFilename,
getter_AddRefs(mrTmpFile));
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
if (NS_WARN_IF(NS_FAILED(rv)))
return rv;
nsRefPtr<nsGZFileWriter> mrWriter = new nsGZFileWriter();
rv = mrWriter->Init(mrTmpFile);

View File

@ -1005,23 +1005,6 @@ nsMemoryReporterManager::~nsMemoryReporterManager()
NS_ASSERTION(!mSavedWeakReporters, "failed to restore weak reporters");
}
NS_IMETHODIMP
nsMemoryReporterManager::EnumerateReporters(nsISimpleEnumerator** aResult)
{
// Memory reporters are not necessarily threadsafe, so this function must
// be called from the main thread.
if (!NS_IsMainThread()) {
MOZ_CRASH();
}
mozilla::MutexAutoLock autoLock(mMutex);
nsRefPtr<ReporterEnumerator> enumerator =
new ReporterEnumerator(mStrongReporters, mWeakReporters);
enumerator.forget(aResult);
return NS_OK;
}
//#define DEBUG_CHILD_PROCESS_MEMORY_REPORTING 1
#ifdef DEBUG_CHILD_PROCESS_MEMORY_REPORTING
@ -1110,19 +1093,38 @@ nsMemoryReporterManager::GetReports(
}
// Get reports for this process.
GetReportsForThisProcess(aHandleReport, aHandleReportData);
// If there are no child processes, we can finish up immediately.
return (mNumChildProcesses == 0)
? aFinishReporting->Callback(aFinishReportingData)
: NS_OK;
}
NS_IMETHODIMP
nsMemoryReporterManager::GetReportsForThisProcess(
nsIHandleReportCallback* aHandleReport,
nsISupports* aHandleReportData)
{
// Memory reporters are not necessarily threadsafe, so this function must
// be called from the main thread.
if (!NS_IsMainThread()) {
MOZ_CRASH();
}
nsRefPtr<ReporterEnumerator> e;
{
mozilla::MutexAutoLock autoLock(mMutex);
e = new ReporterEnumerator(mStrongReporters, mWeakReporters);
}
bool more;
nsCOMPtr<nsISimpleEnumerator> e;
EnumerateReporters(getter_AddRefs(e));
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
nsCOMPtr<nsIMemoryReporter> r;
e->GetNext(getter_AddRefs(r));
r->CollectReports(aHandleReport, aHandleReportData);
}
// If there are no child processes, we can finish up immediately.
return (mNumChildProcesses == 0)
? aFinishReporting->Callback(aFinishReportingData)
: NS_OK;
return NS_OK;
}
// This function has no return value. If something goes wrong, there's no
@ -1372,6 +1374,7 @@ public:
Int64Wrapper() : mValue(0) { }
int64_t mValue;
};
NS_IMPL_ISUPPORTS0(Int64Wrapper)
class ExplicitCallback MOZ_FINAL : public nsIHandleReportCallback
@ -1401,6 +1404,7 @@ public:
return NS_OK;
}
};
NS_IMPL_ISUPPORTS1(ExplicitCallback, nsIHandleReportCallback)
NS_IMETHODIMP
@ -1423,13 +1427,7 @@ nsMemoryReporterManager::GetExplicit(int64_t* aAmount)
nsRefPtr<ExplicitCallback> handleReport = new ExplicitCallback();
nsRefPtr<Int64Wrapper> wrappedExplicitSize = new Int64Wrapper();
nsCOMPtr<nsISimpleEnumerator> e;
EnumerateReporters(getter_AddRefs(e));
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
nsCOMPtr<nsIMemoryReporter> r;
e->GetNext(getter_AddRefs(r));
r->CollectReports(handleReport, wrappedExplicitSize);
}
GetReportsForThisProcess(handleReport, wrappedExplicitSize);
*aAmount = wrappedExplicitSize->mValue;
@ -1854,27 +1852,18 @@ public:
return NS_OK;
}
};
NS_IMPL_ISUPPORTS1(
DoNothingCallback
, nsIHandleReportCallback
)
NS_IMPL_ISUPPORTS1(DoNothingCallback, nsIHandleReportCallback)
void
RunReporters()
RunReportersForThisProcess()
{
nsCOMPtr<nsIMemoryReporterManager> mgr =
do_GetService("@mozilla.org/memory-reporter-manager;1");
nsRefPtr<DoNothingCallback> doNothing = new DoNothingCallback();
bool more;
nsCOMPtr<nsISimpleEnumerator> e;
mgr->EnumerateReporters(getter_AddRefs(e));
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
nsCOMPtr<nsIMemoryReporter> r;
e->GetNext(getter_AddRefs(r));
r->CollectReports(doNothing, nullptr);
}
mgr->GetReportsForThisProcess(doNothing, nullptr);
}
} // namespace dmd