Bug 806473 - Expose MemoryInfoDumper methods via a nsIMemoryInfoDumper service. r=jlebar

--HG--
rename : xpcom/base/MemoryInfoDumper.h => xpcom/base/nsIMemoryInfoDumper.idl
rename : xpcom/base/MemoryInfoDumper.cpp => xpcom/base/nsMemoryInfoDumper.cpp
This commit is contained in:
Kartikaya Gupta 2012-10-29 20:41:14 -04:00
Родитель fa7b3aa811
Коммит 3f8b30e6af
9 изменённых файлов: 107 добавлений и 60 удалений

Просмотреть файл

@ -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<nsIMemoryInfoDumper> 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<nsIMemoryInfoDumper> dumper = do_GetService("@mozilla.org/memory-info-dumper;1");
dumper->DumpGCAndCCLogsToFile(
aIdentifier, aDumpChildProcesses);
return true;
}

Просмотреть файл

@ -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 \

Просмотреть файл

@ -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-<identifier>-<pid>-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

Просмотреть файл

@ -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<nsIMemoryInfoDumper> 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<nsIMemoryInfoDumper> 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<int64_t>(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<nsIMemoryReporterManager> 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

Просмотреть файл

@ -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

Просмотреть файл

@ -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 <unistd.h>
@ -605,7 +605,7 @@ nsMemoryReporterManager::Init()
REGISTER(AtomTable);
#if defined(XP_LINUX)
MemoryInfoDumper::Initialize();
nsMemoryInfoDumper::Initialize();
#endif
return NS_OK;

Просмотреть файл

@ -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)

Просмотреть файл

@ -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
*/

Просмотреть файл

@ -96,6 +96,7 @@ extern nsresult nsStringInputStreamConstructor(nsISupports *, REFNSIID, void **)
#include "nsSystemInfo.h"
#include "nsMemoryReporterManager.h"
#include "nsMemoryInfoDumper.h"
#include "nsMessageLoop.h"
#include <locale.h>
@ -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