mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 1007534 - Part 1: Add a saveMemoryReport method to nsICrashReporter. r=froydnj
This commit is contained in:
parent
67df248e76
commit
9cb7f94c04
@ -161,6 +161,7 @@ static google_breakpad::ExceptionHandler* gExceptionHandler = nullptr;
|
||||
|
||||
static XP_CHAR* pendingDirectory;
|
||||
static XP_CHAR* crashReporterPath;
|
||||
static XP_CHAR* memoryReportPath;
|
||||
|
||||
// Where crash events should go.
|
||||
static XP_CHAR* eventsDirectory;
|
||||
@ -1532,6 +1533,11 @@ nsresult UnsetExceptionHandler()
|
||||
eventsDirectory = nullptr;
|
||||
}
|
||||
|
||||
if (memoryReportPath) {
|
||||
NS_Free(memoryReportPath);
|
||||
memoryReportPath = nullptr;
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
posix_spawnattr_destroy(&spawnattr);
|
||||
#endif
|
||||
@ -2199,6 +2205,23 @@ bool GetCrashEventsDir(nsAString& aPath)
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
SetMemoryReportFile(nsIFile* aFile)
|
||||
{
|
||||
if (!gExceptionHandler) {
|
||||
return;
|
||||
}
|
||||
#ifdef XP_WIN
|
||||
nsString path;
|
||||
aFile->GetPath(path);
|
||||
memoryReportPath = ToNewUnicode(path);
|
||||
#else
|
||||
nsCString path;
|
||||
aFile->GetNativePath(path);
|
||||
memoryReportPath = ToNewCString(path);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
FindPendingDir()
|
||||
{
|
||||
|
@ -50,6 +50,7 @@ nsresult UnsetExceptionHandler();
|
||||
void SetUserAppDataDirectory(nsIFile* aDir);
|
||||
void SetProfileDirectory(nsIFile* aDir);
|
||||
void UpdateCrashEventsDir();
|
||||
void SetMemoryReportFile(nsIFile* aFile);
|
||||
|
||||
/**
|
||||
* Get the path where crash event files should be written.
|
||||
|
@ -178,6 +178,7 @@
|
||||
#include "nsICrashReporter.h"
|
||||
#define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIMemoryInfoDumper.h"
|
||||
#endif
|
||||
|
||||
#include "base/command_line.h"
|
||||
@ -590,6 +591,7 @@ class nsXULAppInfo : public nsIXULAppInfo,
|
||||
#endif
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
public nsICrashReporter,
|
||||
public nsIFinishDumpingCallback,
|
||||
#endif
|
||||
public nsIXULRuntime
|
||||
|
||||
@ -601,6 +603,7 @@ public:
|
||||
NS_DECL_NSIXULRUNTIME
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
NS_DECL_NSICRASHREPORTER
|
||||
NS_DECL_NSIFINISHDUMPINGCALLBACK
|
||||
#endif
|
||||
#ifdef XP_WIN
|
||||
NS_DECL_NSIWINAPPHELPER
|
||||
@ -615,6 +618,7 @@ NS_INTERFACE_MAP_BEGIN(nsXULAppInfo)
|
||||
#endif
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
NS_INTERFACE_MAP_ENTRY(nsICrashReporter)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIFinishDumpingCallback)
|
||||
#endif
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData ||
|
||||
XRE_GetProcessType() == GeckoProcessType_Content)
|
||||
@ -1133,6 +1137,45 @@ nsXULAppInfo::UpdateCrashEventsDir()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULAppInfo::SaveMemoryReport()
|
||||
{
|
||||
if (!CrashReporter::GetEnabled()) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DIR_STARTUP,
|
||||
getter_AddRefs(file));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
file->AppendNative(NS_LITERAL_CSTRING("memory-report.json.gz"));
|
||||
|
||||
nsString path;
|
||||
file->GetPath(path);
|
||||
|
||||
nsCOMPtr<nsIMemoryInfoDumper> dumper =
|
||||
do_GetService("@mozilla.org/memory-info-dumper;1");
|
||||
if (NS_WARN_IF(!dumper)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
rv = dumper->DumpMemoryReportsToNamedFile(path, this, file, true /* anonymize */);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXULAppInfo::Callback(nsISupports* aData)
|
||||
{
|
||||
nsCOMPtr<nsIFile> file = do_QueryInterface(aData);
|
||||
MOZ_ASSERT(file);
|
||||
|
||||
CrashReporter::SetMemoryReportFile(file);
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const nsXULAppInfo kAppInfo;
|
||||
|
@ -14,7 +14,7 @@ interface nsIURL;
|
||||
* future releases.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(a2080795-e54c-4ecb-b001-bdc08a2021dd)]
|
||||
[scriptable, uuid(ee431adc-21dd-42d9-968b-e19b4c62960a)]
|
||||
interface nsICrashReporter : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -117,4 +117,12 @@ interface nsICrashReporter : nsISupports
|
||||
* change.
|
||||
*/
|
||||
void UpdateCrashEventsDir();
|
||||
|
||||
/**
|
||||
* Save an anonymized memory report file for inclusion in a future crash
|
||||
* report in this session.
|
||||
*
|
||||
* @throws NS_ERROR_NOT_INITIALIZED if crash reporting is disabled.
|
||||
*/
|
||||
void saveMemoryReport();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user