Bug 1257486 - Annotate global memory status in the crash reporter for child process; r?bsmedberg
MozReview-Commit-ID: ExVZS3aAp41
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -763,16 +763,49 @@ OpenAPIData(PlatformWriter& aWriter,
p -= 4;
size += 4;
}
}
Concat(p, extraFileExtension, &size);
aWriter.Open(extraDataPath);
}
+#ifdef XP_WIN
+void
+WriteGlobalMemoryStatus(PlatformWriter* apiData, PlatformWriter* eventFile)
+{
+ char buffer[128];
+
+ // Try to get some information about memory.
+ MEMORYSTATUSEX statex;
+ statex.dwLength = sizeof(statex);
+ if (GlobalMemoryStatusEx(&statex)) {
+
+#define WRITE_STATEX_FIELD(field, name, conversionFunc) \
+ conversionFunc(statex.field, buffer, 10); \
+ if (apiData) { \
+ WriteAnnotation(*apiData, name, buffer); \
+ } \
+ if (eventFile) { \
+ WriteAnnotation(*eventFile, name, buffer); \
+ }
+
+ WRITE_STATEX_FIELD(dwMemoryLoad, "SystemMemoryUsePercentage", ltoa);
+ WRITE_STATEX_FIELD(ullTotalVirtual, "TotalVirtualMemory", _ui64toa);
+ WRITE_STATEX_FIELD(ullAvailVirtual, "AvailableVirtualMemory", _ui64toa);
+ WRITE_STATEX_FIELD(ullTotalPageFile, "TotalPageFile", _ui64toa);
+ WRITE_STATEX_FIELD(ullAvailPageFile, "AvailablePageFile", _ui64toa);
+ WRITE_STATEX_FIELD(ullTotalPhys, "TotalPhysicalMemory", _ui64toa);
+ WRITE_STATEX_FIELD(ullAvailPhys, "AvailablePhysicalMemory", _ui64toa);
+
+#undef WRITE_STATEX_FIELD
+ }
+}
+#endif
+
bool MinidumpCallback(
#ifdef XP_LINUX
const MinidumpDescriptor& descriptor,
#else
const XP_CHAR* dump_path,
const XP_CHAR* minidump_id,
#endif
void* context,
@@ -963,37 +996,17 @@ bool MinidumpCallback(
}
#ifdef HAS_DLL_BLOCKLIST
if (apiData.Valid()) {
DllBlocklist_WriteNotes(apiData.Handle());
DllBlocklist_WriteNotes(eventFile.Handle());
}
#endif
-
- // Try to get some information about memory.
- MEMORYSTATUSEX statex;
- statex.dwLength = sizeof(statex);
- if (GlobalMemoryStatusEx(&statex)) {
-
-#define WRITE_STATEX_FIELD(field, name, conversionFunc) \
- conversionFunc(statex.field, buffer, 10); \
- WriteAnnotation(apiData, name, buffer); \
- WriteAnnotation(eventFile, name, buffer);
-
- WRITE_STATEX_FIELD(dwMemoryLoad, "SystemMemoryUsePercentage", ltoa);
- WRITE_STATEX_FIELD(ullTotalVirtual, "TotalVirtualMemory", _ui64toa);
- WRITE_STATEX_FIELD(ullAvailVirtual, "AvailableVirtualMemory", _ui64toa);
- WRITE_STATEX_FIELD(ullTotalPageFile, "TotalPageFile", _ui64toa);
- WRITE_STATEX_FIELD(ullAvailPageFile, "AvailablePageFile", _ui64toa);
- WRITE_STATEX_FIELD(ullTotalPhys, "TotalPhysicalMemory", _ui64toa);
- WRITE_STATEX_FIELD(ullAvailPhys, "AvailablePhysicalMemory", _ui64toa);
-
-#undef WRITE_STATEX_FIELD
- }
+ WriteGlobalMemoryStatus(&apiData, &eventFile);
#endif // XP_WIN
if (gMozCrashReason) {
WriteAnnotation(apiData, "MozCrashReason", gMozCrashReason);
WriteAnnotation(eventFile, "MozCrashReason", gMozCrashReason);
}
if (oomAllocationSizeBuffer[0]) {
@@ -1266,16 +1279,20 @@ PrepareChildExceptionTimeAnnotations()
p = Concat(p, pidBuffer, &charsAvailable);
// Now open the file...
PlatformWriter apiData;
OpenAPIData(apiData, tempPath);
// ...and write out any annotations. These must be escaped if necessary
// (but don't call EscapeAnnotation here, because it touches the heap).
+#ifdef XP_WIN
+ WriteGlobalMemoryStatus(&apiData, nullptr);
+#endif
+
char oomAllocationSizeBuffer[32] = "";
if (gOOMAllocationSize) {
XP_STOA(gOOMAllocationSize, oomAllocationSizeBuffer, 10);
}
if (oomAllocationSizeBuffer[0]) {
WriteAnnotation(apiData, "OOMAllocationSize", oomAllocationSizeBuffer);
}
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/unit/test_oom_annotation_windows.js
@@ -0,0 +1,27 @@
+function run_test()
+{
+ if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) {
+ dump("INFO | test_crash_oom.js | Can't test crashreporter in a non-libxul build.\n");
+ return;
+ }
+
+ do_crash(
+ function() {
+ crashType = CrashTestUtils.CRASH_OOM;
+ crashReporter.annotateCrashReport("TestingOOMCrash", "Yes");
+ },
+ function(mdump, extra) {
+ do_check_eq(extra.TestingOOMCrash, "Yes");
+ do_check_true("OOMAllocationSize" in extra);
+ do_check_true(Number(extra.OOMAllocationSize) > 0);
+ do_check_true("SystemMemoryUsePercentage" in extra);
+ do_check_true("TotalVirtualMemory" in extra);
+ do_check_true("AvailableVirtualMemory" in extra);
+ do_check_true("TotalPageFile" in extra);
+ do_check_true("AvailablePageFile" in extra);
+ do_check_true("TotalPhysicalMemory" in extra);
+ do_check_true("AvailablePhysicalMemory" in extra);
+
+ },
+ true);
+}
--- a/toolkit/crashreporter/test/unit/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit/xpcshell.ini
@@ -10,16 +10,19 @@ support-files =
[test_crash_purevirtual.js]
[test_crash_runtimeabort.js]
[test_crash_after_js_oom_reported.js]
[test_crash_after_js_oom_recovered.js]
[test_crash_after_js_oom_reported_2.js]
[test_crash_after_js_large_allocation_failure.js]
[test_crash_after_js_large_allocation_failure_reporting.js]
[test_crash_oom.js]
+[test_oom_annotation_windows.js]
+skip-if = os != 'win'
+
[test_crash_abort.js]
skip-if = os == 'win'
[test_crash_with_memory_report.js]
[test_crashreporter.js]
[test_crashreporter_crash.js]
[test_crashreporter_crash_profile_lock.js]
[test_override_exception_handler.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/unit_ipc/test_content_oom_annotation_windows.js
@@ -0,0 +1,23 @@
+load("../unit/head_crashreporter.js");
+
+function run_test()
+{
+ if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) {
+ dump("INFO | test_content_annotation.js | Can't test crashreporter in a non-libxul build.\n");
+ return;
+ }
+
+ // Try crashing with an OOM
+ do_content_crash(function() {
+ crashType = CrashTestUtils.CRASH_OOM;
+ },
+ function(mdump, extra) {
+ do_check_true("SystemMemoryUsePercentage" in extra);
+ do_check_true("TotalVirtualMemory" in extra);
+ do_check_true("AvailableVirtualMemory" in extra);
+ do_check_true("TotalPageFile" in extra);
+ do_check_true("AvailablePageFile" in extra);
+ do_check_true("TotalPhysicalMemory" in extra);
+ do_check_true("AvailablePhysicalMemory" in extra);
+ });
+}
--- a/toolkit/crashreporter/test/unit_ipc/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit_ipc/xpcshell.ini
@@ -1,7 +1,9 @@
[DEFAULT]
head =
tail =
skip-if = toolkit == 'android' || toolkit == 'gonk'
[test_content_annotation.js]
[test_content_exception_time_annotation.js]
+[test_content_oom_annotation_windows.js]
+skip-if = os != 'win'