diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index e3e35e606f32..cca9c2af5411 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -20,7 +20,6 @@ #endif #include "mozilla/Attributes.h" -#include "mozilla/MemoryInfoDumper.h" #include "mozilla/dom/ExternalHelperAppChild.h" #include "mozilla/dom/PCrashReporterChild.h" #include "mozilla/dom/StorageChild.h" @@ -39,6 +38,7 @@ #include "nsAudioStream.h" #endif #include "nsIMemoryReporter.h" +#include "nsIMemoryInfoDumper.h" #include "nsIObserverService.h" #include "nsTObserverArray.h" #include "nsIObserver.h" @@ -448,7 +448,9 @@ ContentChild::RecvDumpMemoryReportsToFile(const nsString& aIdentifier, const bool& aMinimizeMemoryUsage, const bool& aDumpChildProcesses) { - MemoryInfoDumper::DumpMemoryReportsToFile( + nsCOMPtr dumper = do_GetService("@mozilla.org/memory-info-dumper;1"); + + dumper->DumpMemoryReportsToFile( aIdentifier, aMinimizeMemoryUsage, aDumpChildProcesses); return true; } @@ -457,7 +459,9 @@ bool ContentChild::RecvDumpGCAndCCLogsToFile(const nsString& aIdentifier, const bool& aDumpChildProcesses) { - MemoryInfoDumper::DumpGCAndCCLogsToFile( + nsCOMPtr dumper = do_GetService("@mozilla.org/memory-info-dumper;1"); + + dumper->DumpGCAndCCLogsToFile( aIdentifier, aDumpChildProcesses); return true; } diff --git a/xpcom/base/Makefile.in b/xpcom/base/Makefile.in index bc849efcc581..99e0841f15c9 100644 --- a/xpcom/base/Makefile.in +++ b/xpcom/base/Makefile.in @@ -41,7 +41,7 @@ CPPSRCS = \ VisualEventTracer.cpp \ nsErrorAsserts.cpp \ nsGZFileWriter.cpp \ - MemoryInfoDumper.cpp \ + nsMemoryInfoDumper.cpp \ nsMessageLoop.cpp \ $(NULL) @@ -74,7 +74,7 @@ EXPORTS_NAMESPACES = mozilla EXPORTS_mozilla = \ MapsMemoryReporter.h \ - MemoryInfoDumper.h \ + nsMemoryInfoDumper.h \ ClearOnShutdown.h \ StaticPtr.h \ AvailableMemoryTracker.h \ @@ -136,6 +136,7 @@ XPIDLSRCS = \ nsIVersionComparator.idl \ nsIUUIDGenerator.idl \ nsIMutable.idl \ + nsIMemoryInfoDumper.idl \ nsIMemoryReporter.idl \ nsIGZFileWriter.idl \ nsIMessageLoop.idl \ diff --git a/xpcom/base/MemoryInfoDumper.h b/xpcom/base/nsIMemoryInfoDumper.idl similarity index 75% rename from xpcom/base/MemoryInfoDumper.h rename to xpcom/base/nsIMemoryInfoDumper.idl index 08b81659e3da..c0a6e9112f74 100644 --- a/xpcom/base/MemoryInfoDumper.h +++ b/xpcom/base/nsIMemoryInfoDumper.idl @@ -1,30 +1,13 @@ /* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set sw=2 ts=50 et cin tw=80 : */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef mozilla_MemoryInfoDumper_h -#define mozilla_MemoryInfoDumper_h +#include "nsISupports.idl" -#include "nsString.h" -#include "mozilla/StandardInteger.h" -class nsIGZFileWriter; - -namespace mozilla { - -/** - * This class facilitates dumping information about our memory usage to disk. - * - * Its cpp file also has Linux-only code which watches various OS signals and - * dumps memory info upon receiving a signal. You can activate these listeners - * by calling Initialize(). - */ -class MemoryInfoDumper +[scriptable, builtinclass, uuid(ede09623-d793-4355-9682-b3adfe307126)] +interface nsIMemoryInfoDumper : nsISupports { -public: - static void Initialize(); - /** * DumpMemoryReportsToFile dumps the memory reports for this process and * possibly our child processes (and their children, recursively) to a file in @@ -32,21 +15,21 @@ public: * something similar, such as memory-reports---1.json.gz; no * existing file will be overwritten). * - * @param identifier this identifier will appear in the filename of our - * about:memory dump and those of our children (if dumpChildProcesses is + * @param aIdentifier this identifier will appear in the filename of our + * about:memory dump and those of our children (if aDumpChildProcesses is * true). * * If the identifier is empty, the dumpMemoryReportsToFile implementation * may set it arbitrarily and use that new value for its own dump and the * dumps of its child processes. For example, the dumpMemoryReportsToFile - * implementation may set |identifier| to the number of seconds since the + * implementation may set |aIdentifier| to the number of seconds since the * epoch. * - * @param minimizeMemoryUsage indicates whether we should run a series of + * @param aMinimizeMemoryUsage indicates whether we should run a series of * gc/cc's in an attempt to reduce our memory usage before collecting our * memory report. * - * @param dumpChildProcesses indicates whether we should call + * @param aDumpChildProcesses indicates whether we should call * dumpMemoryReportsToFile in our child processes. If so, the child * processes will also dump their children, and so on. * @@ -119,10 +102,9 @@ public: * } * } */ - static void - DumpMemoryReportsToFile(const nsAString& aIdentifier, - bool aMinimizeMemoryUsage, - bool aDumpChildProcesses); + void dumpMemoryReportsToFile(in AString aIdentifier, + in bool aMinimizeMemoryUsage, + in bool aDumpChildProcesses); /** * Dump GC and CC logs to files in the OS's temp directory (or in @@ -140,14 +122,6 @@ public: * DumpGCAndCCLogsToFile in our child processes. If so, the child processes * will dump their children, and so on. */ - static void - DumpGCAndCCLogsToFile(const nsAString& aIdentifier, - bool aDumpChildProcesses); - -private: - static nsresult - DumpMemoryReportsToFileImpl(const nsAString& aIdentifier); + void dumpGCAndCCLogsToFile(in AString aIdentifier, + in bool aDumpChildProcesses); }; - -} // namespace mozilla -#endif diff --git a/xpcom/base/MemoryInfoDumper.cpp b/xpcom/base/nsMemoryInfoDumper.cpp similarity index 95% rename from xpcom/base/MemoryInfoDumper.cpp rename to xpcom/base/nsMemoryInfoDumper.cpp index f054ddfeb649..198a66dae7bc 100644 --- a/xpcom/base/MemoryInfoDumper.cpp +++ b/xpcom/base/nsMemoryInfoDumper.cpp @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "mozilla/MemoryInfoDumper.h" +#include "mozilla/nsMemoryInfoDumper.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/FileUtils.h" @@ -55,7 +55,8 @@ public: NS_IMETHOD Run() { - MemoryInfoDumper::DumpMemoryReportsToFile( + nsCOMPtr dumper = do_GetService("@mozilla.org/memory-info-dumper;1"); + dumper->DumpMemoryReportsToFile( mIdentifier, mMinimizeMemoryUsage, mDumpChildProcesses); return NS_OK; } @@ -77,7 +78,8 @@ public: NS_IMETHOD Run() { - MemoryInfoDumper::DumpGCAndCCLogsToFile( + nsCOMPtr dumper = do_GetService("@mozilla.org/memory-info-dumper;1"); + dumper->DumpGCAndCCLogsToFile( mIdentifier, mDumpChildProcesses); return NS_OK; } @@ -270,8 +272,20 @@ InitializeSignalWatcher() } // anonymous namespace #endif // } XP_LINUX +} // namespace mozilla + +NS_IMPL_ISUPPORTS1(nsMemoryInfoDumper, nsIMemoryInfoDumper) + +nsMemoryInfoDumper::nsMemoryInfoDumper() +{ +} + +nsMemoryInfoDumper::~nsMemoryInfoDumper() +{ +} + /* static */ void -MemoryInfoDumper::Initialize() +nsMemoryInfoDumper::Initialize() { #ifdef XP_LINUX InitializeSignalWatcher(); @@ -292,8 +306,8 @@ EnsureNonEmptyIdentifier(nsAString& aIdentifier) aIdentifier.AppendInt(static_cast(PR_Now()) / 1000000); } -/* static */ void -MemoryInfoDumper::DumpMemoryReportsToFile( +NS_IMETHODIMP +nsMemoryInfoDumper::DumpMemoryReportsToFile( const nsAString& aIdentifier, bool aMinimizeMemoryUsage, bool aDumpChildProcesses) @@ -322,16 +336,16 @@ MemoryInfoDumper::DumpMemoryReportsToFile( /* dumpChildProcesses = */ false); nsCOMPtr mgr = do_GetService("@mozilla.org/memory-reporter-manager;1"); - NS_ENSURE_TRUE(mgr,); + NS_ENSURE_TRUE(mgr, NS_ERROR_FAILURE); mgr->MinimizeMemoryUsage(callback); - return; + return NS_OK; } - DumpMemoryReportsToFileImpl(identifier); + return DumpMemoryReportsToFileImpl(identifier); } -/* static */ void -MemoryInfoDumper::DumpGCAndCCLogsToFile( +NS_IMETHODIMP +nsMemoryInfoDumper::DumpGCAndCCLogsToFile( const nsAString& aIdentifier, bool aDumpChildProcesses) { @@ -352,8 +366,11 @@ MemoryInfoDumper::DumpGCAndCCLogsToFile( logger->SetFilenameIdentifier(identifier); nsJSContext::CycleCollectNow(logger); + return NS_OK; } +namespace mozilla { + #define DUMP(o, s) \ do { \ nsresult rv = (o)->Write(s); \ @@ -451,8 +468,10 @@ NS_IMPL_ISUPPORTS1( , nsIMemoryMultiReporterCallback ) +} // namespace mozilla + /* static */ nsresult -MemoryInfoDumper::DumpMemoryReportsToFileImpl( +nsMemoryInfoDumper::DumpMemoryReportsToFileImpl( const nsAString& aIdentifier) { // Open a new file named something like @@ -602,10 +621,9 @@ MemoryInfoDumper::DumpMemoryReportsToFileImpl( NS_ENSURE_SUCCESS(rv, rv); nsString msg = NS_LITERAL_STRING( - "nsIMemoryReporterManager::dumpReports() dumped reports to "); + "nsIMemoryInfoDumper dumped reports to "); msg.Append(path); return cs->LogStringMessage(msg.get()); } #undef DUMP -} // namespace mozilla diff --git a/xpcom/base/nsMemoryInfoDumper.h b/xpcom/base/nsMemoryInfoDumper.h new file mode 100644 index 000000000000..c3e02614aec8 --- /dev/null +++ b/xpcom/base/nsMemoryInfoDumper.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set sw=2 ts=50 et cin tw=80 : */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_nsMemoryInfoDumper_h +#define mozilla_nsMemoryInfoDumper_h + +#include "nsIMemoryInfoDumper.h" +#include "nsString.h" + +/** + * This class facilitates dumping information about our memory usage to disk. + * + * Its cpp file also has Linux-only code which watches various OS signals and + * dumps memory info upon receiving a signal. You can activate these listeners + * by calling Initialize(). + */ +class nsMemoryInfoDumper : public nsIMemoryInfoDumper +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIMEMORYINFODUMPER + + nsMemoryInfoDumper(); + virtual ~nsMemoryInfoDumper(); + +public: + static void Initialize(); + +private: + static nsresult + DumpMemoryReportsToFileImpl(const nsAString& aIdentifier); +}; + +#define NS_MEMORY_INFO_DUMPER_CID \ +{ 0x00bd71fb, 0x7f09, 0x4ec3, \ +{ 0x96, 0xaf, 0xa0, 0xb5, 0x22, 0xb7, 0x79, 0x69 } } + +#endif diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index 84119a5f6e48..a3ba2d18a0f9 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -17,10 +17,10 @@ #include "nsThreadUtils.h" #include "nsIObserverService.h" #include "nsThread.h" +#include "nsMemoryInfoDumper.h" #include "mozilla/Telemetry.h" #include "mozilla/Attributes.h" #include "mozilla/Services.h" -#include "mozilla/MemoryInfoDumper.h" #ifndef XP_WIN #include @@ -605,7 +605,7 @@ nsMemoryReporterManager::Init() REGISTER(AtomTable); #if defined(XP_LINUX) - MemoryInfoDumper::Initialize(); + nsMemoryInfoDumper::Initialize(); #endif return NS_OK; diff --git a/xpcom/build/XPCOMModule.inc b/xpcom/build/XPCOMModule.inc index 00180300ea05..dcee301a7a81 100644 --- a/xpcom/build/XPCOMModule.inc +++ b/xpcom/build/XPCOMModule.inc @@ -76,6 +76,7 @@ COMPONENT(SYSTEMINFO, nsSystemInfoConstructor) COMPONENT(MEMORY_REPORTER_MANAGER, nsMemoryReporterManagerConstructor) + COMPONENT(MEMORY_INFO_DUMPER, nsMemoryInfoDumperConstructor) COMPONENT(IOUTIL, nsIOUtilConstructor) COMPONENT(CYCLE_COLLECTOR_LOGGER, nsCycleCollectorLoggerConstructor) COMPONENT(MESSAGE_LOOP, nsMessageLoopConstructor) diff --git a/xpcom/build/nsXPCOMCID.h b/xpcom/build/nsXPCOMCID.h index 2dc040da8090..c6f0976687b4 100644 --- a/xpcom/build/nsXPCOMCID.h +++ b/xpcom/build/nsXPCOMCID.h @@ -70,6 +70,11 @@ */ #define NS_MEMORY_REPORTER_MANAGER_CONTRACTID "@mozilla.org/memory-reporter-manager;1" +/** + * Memory info dumper service CID + */ +#define NS_MEMORY_INFO_DUMPER_CONTRACTID "@mozilla.org/memory-info-dumper;1" + /** * Cycle collector logger contract id */ diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index 4343ace6d7e7..eec58219fbb9 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -96,6 +96,7 @@ extern nsresult nsStringInputStreamConstructor(nsISupports *, REFNSIID, void **) #include "nsSystemInfo.h" #include "nsMemoryReporterManager.h" +#include "nsMemoryInfoDumper.h" #include "nsMessageLoop.h" #include @@ -193,6 +194,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemInfo, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMemoryReporterManager, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsMemoryInfoDumper) + NS_GENERIC_FACTORY_CONSTRUCTOR(nsIOUtil) static nsresult