Bug 1745526 - Add a crash annotation for the linux memory watcher r=gsvelto

Adds a crash annotation, `LinuxUnderMemoryPressure`, which the memory pressure monitor updates based on whether or not it is under memory pressure.

Differential Revision: https://phabricator.services.mozilla.com/D133555
This commit is contained in:
kriswright 2022-01-20 14:25:44 +00:00
parent 4f4dd2fbae
commit ad3aa241a4
2 changed files with 18 additions and 0 deletions

View file

@ -622,6 +622,12 @@ MacAvailableMemorySysctl:
Expected to be a percentage integer value. Expected to be a percentage integer value.
type: integer type: integer
LinuxUnderMemoryPressure:
description: >
Set to true if the memory pressure watcher was under memory pressure when
the crash occurred.
type: boolean
LauncherProcessState: LauncherProcessState:
description: > description: >
Launcher process enabled state. The integer value of this annotation must Launcher process enabled state. The integer value of this annotation must

View file

@ -40,6 +40,7 @@ class nsAvailableMemoryWatcher final : public nsITimerCallback,
void StartPolling(const MutexAutoLock&); void StartPolling(const MutexAutoLock&);
void StopPolling(const MutexAutoLock&); void StopPolling(const MutexAutoLock&);
void ShutDown(const MutexAutoLock&); void ShutDown(const MutexAutoLock&);
void UpdateCrashAnnotation(const MutexAutoLock&);
static bool IsMemoryLow(); static bool IsMemoryLow();
nsCOMPtr<nsITimer> mTimer; nsCOMPtr<nsITimer> mTimer;
@ -89,6 +90,9 @@ nsresult nsAvailableMemoryWatcher::Init() {
mThread = thread; mThread = thread;
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
// Set the crash annotation to its initial state.
UpdateCrashAnnotation(lock);
StartPolling(lock); StartPolling(lock);
return NS_OK; return NS_OK;
@ -182,6 +186,7 @@ void nsAvailableMemoryWatcher::HandleLowMemory() {
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
if (!mUnderMemoryPressure) { if (!mUnderMemoryPressure) {
mUnderMemoryPressure = true; mUnderMemoryPressure = true;
UpdateCrashAnnotation(lock);
// Poll more frequently under memory pressure. // Poll more frequently under memory pressure.
StartPolling(lock); StartPolling(lock);
} }
@ -194,6 +199,12 @@ void nsAvailableMemoryWatcher::HandleLowMemory() {
[self = RefPtr{this}]() { self->mTabUnloader->UnloadTabAsync(); })); [self = RefPtr{this}]() { self->mTabUnloader->UnloadTabAsync(); }));
} }
void nsAvailableMemoryWatcher::UpdateCrashAnnotation(const MutexAutoLock&) {
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::LinuxUnderMemoryPressure,
mUnderMemoryPressure);
}
// If memory is not low, we may need to dispatch an // If memory is not low, we may need to dispatch an
// event for it if we have been under memory pressure. // event for it if we have been under memory pressure.
// We can also adjust our polling interval. // We can also adjust our polling interval.
@ -203,6 +214,7 @@ void nsAvailableMemoryWatcher::MaybeHandleHighMemory() {
RecordTelemetryEventOnHighMemory(); RecordTelemetryEventOnHighMemory();
NS_NotifyOfEventualMemoryPressure(MemoryPressureState::NoPressure); NS_NotifyOfEventualMemoryPressure(MemoryPressureState::NoPressure);
mUnderMemoryPressure = false; mUnderMemoryPressure = false;
UpdateCrashAnnotation(lock);
} }
StartPolling(lock); StartPolling(lock);
} }