author | Nicholas Nethercote <nnethercote@mozilla.com> |
Sun, 01 Dec 2013 16:29:37 -0800 | |
changeset 159633 | 1965b63bb333959041bcf4a383392996193fb14a |
parent 159632 | b9a394d1c11e63e456be047b659097577f38e873 |
child 159634 | e0803c4ddc9020cc46128326b8a2b82c96d1e790 |
push id | 25808 |
push user | cbook@mozilla.com |
push date | Tue, 10 Dec 2013 12:03:31 +0000 |
treeherder | mozilla-central@7fb91a422c5e [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | mccr8 |
bugs | 947802 |
milestone | 29.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/addon-sdk/source/lib/sdk/test/harness.js +++ b/addon-sdk/source/lib/sdk/test/harness.js @@ -372,21 +372,17 @@ function getPotentialLeaks() { windows[matches[1]] = item; } } 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 }; } function nextIteration(tests) { if (tests) { results.passed += tests.passed; results.failed += tests.failed;
--- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1682,17 +1682,17 @@ ReportAndDump(JSContext *cx, unsigned ar if (!fp) { JS_ReportError(cx, "DMD can't open %s: %s", pathname.ptr(), strerror(errno)); return false; } dmd::ClearReports(); fprintf(stderr, "DMD: running reporters...\n"); - dmd::RunReporters(); + dmd::RunReportersForThisProcess(); dmd::Writer writer(FpWrite, fp); dmd::Dump(writer); fclose(fp); args.rval().setUndefined(); return true; }
--- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -492,29 +492,22 @@ ContentChild::RecvPMemoryReportRequestCo nsCOMPtr<nsIMemoryReporterManager> mgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); InfallibleTArray<MemoryReport> reports; nsCString process; 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; } bool ContentChild::RecvAudioChannelNotify() {
--- a/image/test/mochitest/test_bug601470.html +++ b/image/test/mochitest/test_bug601470.html @@ -25,21 +25,17 @@ window.onload = function() { var mgr = SpecialPowers.Cc["@mozilla.org/memory-reporter-manager;1"] .getService(SpecialPowers.Ci.nsIMemoryReporterManager); var amount = 0; var handleReport = function(aProcess, aPath, aKind, aUnits, aAmount, aDesc) { 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!"); SimpleTest.finish(); } </script>
--- a/toolkit/components/aboutmemory/tests/test_memoryReporters.xul +++ b/toolkit/components/aboutmemory/tests/test_memoryReporters.xul @@ -166,21 +166,17 @@ let otherSize = {}; let totalSize = {}; let jsMilliseconds = {}; let nonJSMilliseconds = {}; mgr.sizeOfTab(window, jsObjectsSize, jsStringsSize, jsOtherSize, 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) { ok(aAmounts.length == 1, aName + " has " + aAmounts.length + " report"); let n = aAmounts[0]; // Check the size is reasonable -- i.e. not ridiculously large or small. ok((100 * 1000 <= n && n <= 10 * 1000 * 1000 * 1000) || aCanBeUnreasonable, aName + "'s size is reasonable");
--- a/toolkit/components/aboutmemory/tests/test_sqliteMultiReporter.xul +++ b/toolkit/components/aboutmemory/tests/test_sqliteMultiReporter.xul @@ -35,21 +35,17 @@ getService(Ci.mozIStorageService); let db = storage.openDatabase(file); db.close(); // Invoke all the reporters. The SQLite multi-reporter is among // 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. ok(true, "didn't crash"); ]]> </script> </window>
--- a/xpcom/base/nsIMemoryReporter.idl +++ b/xpcom/base/nsIMemoryReporter.idl @@ -173,29 +173,28 @@ interface nsIMemoryReporter : nsISupport }; [scriptable, function, uuid(548b3909-c04d-4ca6-8466-b8bee3837457)] 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 { /* * Initialize. */ 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); /* * Like registerReporter, but the Manager service will hold a weak reference * to the given reporter. The reporter should be unregistered before * shutdown. */ @@ -210,24 +209,16 @@ interface nsIMemoryReporterManager : nsI /* * These functions should only be used for testing purposes. */ void blockRegistrationAndHideExistingReporters(); 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 * once all reports have been handled. * * |finishReporting| is called even if, for example, some child processes * fail to report back. However, calls to this method will silently and * immediately abort -- and |finishReporting| will not be called -- if a * previous getReports() call is still in flight, i.e. if it has not yet @@ -236,25 +227,33 @@ interface nsIMemoryReporterManager : nsI * catch and ignore any error anyway. */ void getReports(in nsIMemoryReporterCallback handleReport, in nsISupports handleReportData, 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 * "distinguished" amounts (as could be reported by a memory reporter) that * the manager provides as attributes, because they are sufficiently * 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. * * If you add a new distinguished amount, please update * toolkit/components/aboutmemory/tests/test_memoryReporters.xul. * * |explicit| (UNITS_BYTES) The total size of explicit memory allocations, @@ -436,17 +435,17 @@ nsresult RegisterNonJSSizeOfTab(NonJSSiz } #if defined(MOZ_DMD) namespace mozilla { 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(); } } #if !defined(MOZ_MEMORY) #error "MOZ_DMD requires MOZ_MEMORY" #endif #include "DMD.h"
--- a/xpcom/base/nsMemoryInfoDumper.cpp +++ b/xpcom/base/nsMemoryInfoDumper.cpp @@ -826,27 +826,20 @@ DumpFooter(nsIGZFileWriter* aWriter) static nsresult DumpProcessMemoryReportsToGZFileWriter(nsGZFileWriter* aWriter) { nsresult rv = DumpHeader(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); } nsresult DumpProcessMemoryInfoToTempDir(const nsAString& aIdentifier) { MOZ_ASSERT(!aIdentifier.IsEmpty()); @@ -873,17 +866,18 @@ DumpProcessMemoryInfoToTempDir(const nsA nsCString mrFilename; MakeFilename("memory-report", aIdentifier, "json.gz", mrFilename); nsCOMPtr<nsIFile> mrTmpFile; nsresult rv; 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); if (NS_WARN_IF(NS_FAILED(rv))) return rv; // Dump the memory reports to the file. DumpProcessMemoryReportsToGZFileWriter(mrWriter);
--- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -1000,33 +1000,16 @@ nsMemoryReporterManager::nsMemoryReporte nsMemoryReporterManager::~nsMemoryReporterManager() { delete mStrongReporters; delete mWeakReporters; NS_ASSERTION(!mSavedStrongReporters, "failed to restore strong reporters"); 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 #define MEMORY_REPORTING_LOG(format, ...) \ fprintf(stderr, "++++ MEMORY REPORTING: " format, ##__VA_ARGS__); #else #define MEMORY_REPORTING_LOG(...) #endif @@ -1105,29 +1088,48 @@ nsMemoryReporterManager::GetReports( mNumChildProcesses, aHandleReport, aHandleReportData, aFinishReporting, aFinishReportingData); } // 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 // clear place to report the problem to, but that's ok -- we will end up // hitting the timeout and executing TimeoutCallback(). void nsMemoryReporterManager::HandleChildReports( const uint32_t& aGeneration, @@ -1367,16 +1369,17 @@ nsMemoryReporterManager::UnblockRegistra // This is just a wrapper for int64_t that implements nsISupports, so it can be // passed to nsIMemoryReporter::CollectReports. class Int64Wrapper MOZ_FINAL : public nsISupports { public: NS_DECL_ISUPPORTS Int64Wrapper() : mValue(0) { } int64_t mValue; }; + NS_IMPL_ISUPPORTS0(Int64Wrapper) class ExplicitCallback MOZ_FINAL : public nsIHandleReportCallback { public: NS_DECL_ISUPPORTS NS_IMETHOD Callback(const nsACString& aProcess, const nsACString& aPath, @@ -1396,16 +1399,17 @@ public: { Int64Wrapper* wrappedInt64 = static_cast<Int64Wrapper*>(aWrappedExplicit); wrappedInt64->mValue += aAmount; } return NS_OK; } }; + NS_IMPL_ISUPPORTS1(ExplicitCallback, nsIHandleReportCallback) NS_IMETHODIMP nsMemoryReporterManager::GetExplicit(int64_t* aAmount) { if (NS_WARN_IF(!aAmount)) return NS_ERROR_INVALID_ARG; *aAmount = 0; @@ -1418,23 +1422,17 @@ nsMemoryReporterManager::GetExplicit(int // non-explicit, non-NONHEAP measurements (except for "heap-allocated"). // That's lots of wasted work, and we used to have a GetExplicitNonHeap() // method which did this more efficiently, but it ended up being more // trouble than it was worth. 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; return NS_OK; #endif // HAVE_JEMALLOC_STATS } NS_IMETHODIMP @@ -1849,36 +1847,27 @@ public: int32_t aKind, int32_t aUnits, int64_t aAmount, const nsACString& aDescription, nsISupports* aData) { // Do nothing; the reporter has already reported to DMD. 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 } // namespace mozilla #endif // defined(MOZ_DMD)