Bug 800486 - Part 3: Minor fixups to MemoryInfoDumper.cpp. r=njn, a=akeybl

This commit is contained in:
Justin Lebar 2012-10-15 22:12:14 -04:00
Родитель 3ebd0de262
Коммит 369c44b3dd
2 изменённых файлов: 30 добавлений и 23 удалений

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

@ -19,6 +19,13 @@
#include "nsJSEnvironment.h"
#include "nsPrintfCString.h"
#ifdef XP_WIN
#include <process.h>
#define getpid _getpid
#else
#include <unistd.h>
#endif
#ifdef XP_LINUX
#include <fcntl.h>
#endif
@ -214,10 +221,11 @@ public:
if (signum == sDumpAboutMemorySignum ||
signum == sDumpAboutMemoryAfterMMUSignum) {
// Dump our memory reports (but run this on the main thread!).
bool doMMUFirst = signum == sDumpAboutMemoryAfterMMUSignum;
nsRefPtr<DumpMemoryReportsRunnable> runnable =
new DumpMemoryReportsRunnable(
/* identifier = */ EmptyString(),
signum == sDumpAboutMemoryAfterMMUSignum,
doMMUFirst,
/* dumpChildProcesses = */ true);
NS_DispatchToMainThread(runnable);
}
@ -270,20 +278,28 @@ MemoryInfoDumper::Initialize()
#endif
}
/* static */ void
static void
EnsureNonEmptyIdentifier(nsAString& aIdentifier)
{
if (!aIdentifier.IsEmpty()) {
return;
}
// If the identifier is empty, set it to the number of whole seconds since the
// epoch. This identifier will appear in the files that this process
// generates and also the files generated by this process's children, allowing
// us to identify which files are from the same memory report request.
aIdentifier.AppendInt(static_cast<int64_t>(PR_Now()) / 1000000);
}
/* static */ void
MemoryInfoDumper::DumpMemoryReportsToFile(
const nsAString& aIdentifier,
bool aMinimizeMemoryUsage,
bool aDumpChildProcesses)
{
// If the identifier is empty, set it to the number of whole seconds since
// the epoch. This identifier will appear in our memory report as well as
// our children's, allowing us to identify which files are from the same
// memory report request.
nsString identifier(aIdentifier);
if (identifier.IsEmpty()) {
identifier.AppendInt(static_cast<int64_t>(PR_Now()) / 1000000);
}
EnsureNonEmptyIdentifier(identifier);
// Kick off memory report dumps in our child processes, if applicable. We
// do this before doing our own report because writing a report may be I/O
@ -318,14 +334,8 @@ MemoryInfoDumper::DumpGCAndCCLogsToFile(
const nsAString& aIdentifier,
bool aDumpChildProcesses)
{
// If the identifier is empty, set it to the number of whole seconds since
// the epoch. This identifier will appear in our logs as well as our
// children's, allowing us to identify which files are from the same
// request.
nsString identifier(aIdentifier);
if (identifier.IsEmpty()) {
identifier.AppendInt(static_cast<int64_t>(PR_Now()) / 1000000);
}
EnsureNonEmptyIdentifier(identifier);
if (aDumpChildProcesses) {
nsTArray<ContentParent*> children;
@ -582,15 +592,15 @@ MemoryInfoDumper::DumpMemoryReportsToFileImpl(
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIConsoleService> cs =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsString path;
tmpFile->GetPath(path);
NS_ENSURE_SUCCESS(rv, rv);
nsString msg = NS_LITERAL_STRING("nsIMemoryReporterManager::dumpReports() "
"dumped reports to ");
nsString msg = NS_LITERAL_STRING(
"nsIMemoryReporterManager::dumpReports() dumped reports to ");
msg.Append(path);
return cs->LogStringMessage(msg.get());
}

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

@ -24,10 +24,7 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/MemoryInfoDumper.h"
#ifdef XP_WIN
#include <process.h>
#define getpid _getpid
#else
#ifndef XP_WIN
#include <unistd.h>
#endif