2012-07-11 03:12:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2014-06-30 19:39:45 +04:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-07-11 03:12:40 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/HangMonitor.h"
|
2014-10-21 21:48:08 +04:00
|
|
|
|
2014-12-31 00:52:39 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2014-01-14 20:33:31 +04:00
|
|
|
#include "mozilla/BackgroundHangMonitor.h"
|
2012-07-11 03:12:40 +04:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2012-08-22 01:14:38 +04:00
|
|
|
#include "mozilla/ProcessedStack.h"
|
2014-12-31 00:52:39 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-10-21 22:18:27 +04:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2014-12-31 00:52:39 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-10-21 21:48:08 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2015-06-10 23:32:45 +03:00
|
|
|
#include "mozilla/StackWalk.h"
|
2014-10-21 21:48:08 +04:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MOZ_ENABLE_PROFILER_SPS) && defined(MOZ_PROFILING) && defined(XP_WIN)
|
|
|
|
#define REPORT_CHROME_HANGS
|
|
|
|
#endif
|
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace HangMonitor {
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A flag which may be set from within a debugger to disable the hang
|
|
|
|
* monitor.
|
|
|
|
*/
|
|
|
|
volatile bool gDebugDisableHangMonitor = false;
|
|
|
|
|
|
|
|
const char kHangMonitorPrefName[] = "hangmonitor.timeout";
|
|
|
|
|
2014-05-09 21:55:29 +04:00
|
|
|
#ifdef REPORT_CHROME_HANGS
|
2012-07-11 03:12:40 +04:00
|
|
|
const char kTelemetryPrefName[] = "toolkit.telemetry.enabled";
|
2014-05-09 21:55:29 +04:00
|
|
|
#endif
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
// Monitor protects gShutdown and gTimeout, but not gTimestamp which rely on
|
|
|
|
// being atomically set by the processor; synchronization doesn't really matter
|
|
|
|
// in this use case.
|
|
|
|
Monitor* gMonitor;
|
|
|
|
|
|
|
|
// The timeout preference, in seconds.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t gTimeout;
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
PRThread* gThread;
|
|
|
|
|
|
|
|
// Set when shutdown begins to signal the thread to exit immediately.
|
|
|
|
bool gShutdown;
|
|
|
|
|
|
|
|
// The timestamp of the last event notification, or PR_INTERVAL_NO_WAIT if
|
|
|
|
// we're currently not processing events.
|
2013-10-29 03:29:00 +04:00
|
|
|
Atomic<PRIntervalTime> gTimestamp(PR_INTERVAL_NO_WAIT);
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
#ifdef REPORT_CHROME_HANGS
|
|
|
|
// Main thread ID used in reporting chrome hangs under Windows
|
2013-10-11 00:42:16 +04:00
|
|
|
static HANDLE winMainThreadHandle = nullptr;
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
// Default timeout for reporting chrome hangs to Telemetry (5 seconds)
|
2012-08-22 19:56:38 +04:00
|
|
|
static const int32_t DEFAULT_CHROME_HANG_INTERVAL = 5;
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
// Maximum number of PCs to gather from the stack
|
2012-08-22 19:56:38 +04:00
|
|
|
static const int32_t MAX_CALL_STACK_PCS = 400;
|
2012-07-11 03:12:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// PrefChangedFunc
|
2013-12-11 03:10:01 +04:00
|
|
|
void
|
2012-07-11 03:12:40 +04:00
|
|
|
PrefChanged(const char*, void*)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newval = Preferences::GetInt(kHangMonitorPrefName);
|
2012-07-11 03:12:40 +04:00
|
|
|
#ifdef REPORT_CHROME_HANGS
|
|
|
|
// Monitor chrome hangs on the profiling branch if Telemetry enabled
|
|
|
|
if (newval == 0) {
|
|
|
|
bool telemetryEnabled = Preferences::GetBool(kTelemetryPrefName);
|
|
|
|
if (telemetryEnabled) {
|
|
|
|
newval = DEFAULT_CHROME_HANG_INTERVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
MonitorAutoLock lock(*gMonitor);
|
|
|
|
if (newval != gTimeout) {
|
|
|
|
gTimeout = newval;
|
|
|
|
lock.Notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Crash()
|
|
|
|
{
|
|
|
|
if (gDebugDisableHangMonitor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (::IsDebuggerPresent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2015-12-27 03:34:11 +03:00
|
|
|
// If you change this, you must also deal with the threadsafety of AnnotateCrashReport in
|
|
|
|
// non-chrome processes!
|
|
|
|
if (GeckoProcessType_Default == XRE_GetProcessType()) {
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Hang"),
|
|
|
|
NS_LITERAL_CSTRING("1"));
|
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_RUNTIMEABORT("HangMonitor triggered");
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef REPORT_CHROME_HANGS
|
2014-10-21 21:48:08 +04:00
|
|
|
|
2012-07-11 03:12:40 +04:00
|
|
|
static void
|
2014-09-11 08:47:01 +04:00
|
|
|
ChromeStackWalker(uint32_t aFrameNumber, void* aPC, void* aSP, void* aClosure)
|
2012-07-11 03:12:40 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aClosure);
|
2014-05-27 11:15:35 +04:00
|
|
|
std::vector<uintptr_t>* stack =
|
2012-08-22 01:14:38 +04:00
|
|
|
static_cast<std::vector<uintptr_t>*>(aClosure);
|
2014-05-27 11:15:35 +04:00
|
|
|
if (stack->size() == MAX_CALL_STACK_PCS) {
|
2012-08-22 01:14:38 +04:00
|
|
|
return;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2012-08-22 01:14:38 +04:00
|
|
|
MOZ_ASSERT(stack->size() < MAX_CALL_STACK_PCS);
|
|
|
|
stack->push_back(reinterpret_cast<uintptr_t>(aPC));
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-27 11:15:35 +04:00
|
|
|
GetChromeHangReport(Telemetry::ProcessedStack& aStack,
|
|
|
|
int32_t& aSystemUptime,
|
|
|
|
int32_t& aFirefoxUptime)
|
2012-07-11 03:12:40 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(winMainThreadHandle);
|
|
|
|
|
|
|
|
// The thread we're about to suspend might have the alloc lock
|
|
|
|
// so allocate ahead of time
|
2012-08-22 01:14:38 +04:00
|
|
|
std::vector<uintptr_t> rawStack;
|
|
|
|
rawStack.reserve(MAX_CALL_STACK_PCS);
|
2012-07-11 03:12:40 +04:00
|
|
|
DWORD ret = ::SuspendThread(winMainThreadHandle);
|
2014-05-27 11:15:35 +04:00
|
|
|
if (ret == -1) {
|
2012-07-11 03:12:40 +04:00
|
|
|
return;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2015-06-10 23:32:45 +03:00
|
|
|
MozStackWalk(ChromeStackWalker, /* skipFrames */ 0, /* maxFrames */ 0,
|
2012-12-21 09:31:57 +04:00
|
|
|
reinterpret_cast<void*>(&rawStack),
|
2012-12-08 09:15:21 +04:00
|
|
|
reinterpret_cast<uintptr_t>(winMainThreadHandle), nullptr);
|
2012-07-11 03:12:40 +04:00
|
|
|
ret = ::ResumeThread(winMainThreadHandle);
|
2014-05-27 11:15:35 +04:00
|
|
|
if (ret == -1) {
|
2012-07-11 03:12:40 +04:00
|
|
|
return;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2012-11-20 18:45:14 +04:00
|
|
|
aStack = Telemetry::GetStackAndModules(rawStack);
|
2014-01-28 01:47:00 +04:00
|
|
|
|
|
|
|
// Record system uptime (in minutes) at the time of the hang
|
|
|
|
aSystemUptime = ((GetTickCount() / 1000) - (gTimeout * 2)) / 60;
|
|
|
|
|
|
|
|
// Record Firefox uptime (in minutes) at the time of the hang
|
|
|
|
bool error;
|
|
|
|
TimeStamp processCreation = TimeStamp::ProcessCreation(error);
|
|
|
|
if (!error) {
|
|
|
|
TimeDuration td = TimeStamp::Now() - processCreation;
|
|
|
|
aFirefoxUptime = (static_cast<int32_t>(td.ToSeconds()) - (gTimeout * 2)) / 60;
|
|
|
|
} else {
|
|
|
|
aFirefoxUptime = -1;
|
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
2014-10-21 21:48:08 +04:00
|
|
|
|
2012-07-11 03:12:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadMain(void*)
|
|
|
|
{
|
2012-06-12 21:06:20 +04:00
|
|
|
PR_SetCurrentThreadName("Hang Monitor");
|
|
|
|
|
2012-07-11 03:12:40 +04:00
|
|
|
MonitorAutoLock lock(*gMonitor);
|
|
|
|
|
|
|
|
// In order to avoid issues with the hang monitor incorrectly triggering
|
|
|
|
// during a general system stop such as sleeping, the monitor thread must
|
|
|
|
// run twice to trigger hang protection.
|
|
|
|
PRIntervalTime lastTimestamp = 0;
|
|
|
|
int waitCount = 0;
|
|
|
|
|
|
|
|
#ifdef REPORT_CHROME_HANGS
|
2012-08-22 01:14:38 +04:00
|
|
|
Telemetry::ProcessedStack stack;
|
2014-01-28 01:47:00 +04:00
|
|
|
int32_t systemUptime = -1;
|
|
|
|
int32_t firefoxUptime = -1;
|
2015-03-10 04:41:24 +03:00
|
|
|
UniquePtr<HangAnnotations> annotations;
|
2012-07-11 03:12:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (gShutdown) {
|
|
|
|
return; // Exit the thread
|
|
|
|
}
|
|
|
|
|
|
|
|
// avoid rereading the volatile value in this loop
|
|
|
|
PRIntervalTime timestamp = gTimestamp;
|
|
|
|
|
|
|
|
PRIntervalTime now = PR_IntervalNow();
|
|
|
|
|
|
|
|
if (timestamp != PR_INTERVAL_NO_WAIT &&
|
|
|
|
now < timestamp) {
|
|
|
|
// 32-bit overflow, reset for another waiting period
|
|
|
|
timestamp = 1; // lowest legal PRInterval value
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timestamp != PR_INTERVAL_NO_WAIT &&
|
|
|
|
timestamp == lastTimestamp &&
|
|
|
|
gTimeout > 0) {
|
|
|
|
++waitCount;
|
|
|
|
#ifdef REPORT_CHROME_HANGS
|
2014-01-28 01:47:00 +04:00
|
|
|
// Capture the chrome-hang stack + Firefox & system uptimes after
|
|
|
|
// the minimum hang duration has been reached (not when the hang ends)
|
|
|
|
if (waitCount == 2) {
|
|
|
|
GetChromeHangReport(stack, systemUptime, firefoxUptime);
|
2015-03-10 04:41:24 +03:00
|
|
|
annotations = ChromeHangAnnotatorCallout();
|
2014-01-28 01:47:00 +04:00
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
#else
|
2014-01-28 01:47:00 +04:00
|
|
|
// This is the crash-on-hang feature.
|
|
|
|
// See bug 867313 for the quirk in the waitCount comparison
|
|
|
|
if (waitCount >= 2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t delay =
|
|
|
|
int32_t(PR_IntervalToSeconds(now - timestamp));
|
2013-05-01 02:39:16 +04:00
|
|
|
if (delay >= gTimeout) {
|
2012-07-11 03:12:40 +04:00
|
|
|
MonitorAutoUnlock unlock(*gMonitor);
|
|
|
|
Crash();
|
|
|
|
}
|
|
|
|
}
|
2014-01-28 01:47:00 +04:00
|
|
|
#endif
|
2014-05-27 11:15:35 +04:00
|
|
|
} else {
|
2012-07-11 03:12:40 +04:00
|
|
|
#ifdef REPORT_CHROME_HANGS
|
|
|
|
if (waitCount >= 2) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t hangDuration = PR_IntervalToSeconds(now - lastTimestamp);
|
2014-10-21 21:48:08 +04:00
|
|
|
Telemetry::RecordChromeHang(hangDuration, stack, systemUptime,
|
2014-12-31 00:52:39 +03:00
|
|
|
firefoxUptime, Move(annotations));
|
2012-08-22 01:14:38 +04:00
|
|
|
stack.Clear();
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
lastTimestamp = timestamp;
|
|
|
|
waitCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntervalTime timeout;
|
|
|
|
if (gTimeout <= 0) {
|
|
|
|
timeout = PR_INTERVAL_NO_TIMEOUT;
|
2014-05-27 11:15:35 +04:00
|
|
|
} else {
|
2012-07-11 03:12:40 +04:00
|
|
|
timeout = PR_MillisecondsToInterval(gTimeout * 500);
|
|
|
|
}
|
|
|
|
lock.Wait(timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Startup()
|
|
|
|
{
|
2015-12-27 03:34:11 +03:00
|
|
|
if (GeckoProcessType_Default != XRE_GetProcessType() &&
|
|
|
|
GeckoProcessType_Content != XRE_GetProcessType()) {
|
2012-07-11 03:12:40 +04:00
|
|
|
return;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
|
2013-02-08 09:54:20 +04:00
|
|
|
MOZ_ASSERT(!gMonitor, "Hang monitor already initialized");
|
2012-07-11 03:12:40 +04:00
|
|
|
gMonitor = new Monitor("HangMonitor");
|
|
|
|
|
2013-10-11 00:42:16 +04:00
|
|
|
Preferences::RegisterCallback(PrefChanged, kHangMonitorPrefName, nullptr);
|
|
|
|
PrefChanged(nullptr, nullptr);
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
#ifdef REPORT_CHROME_HANGS
|
2013-10-11 00:42:16 +04:00
|
|
|
Preferences::RegisterCallback(PrefChanged, kTelemetryPrefName, nullptr);
|
2012-07-11 03:12:40 +04:00
|
|
|
winMainThreadHandle =
|
|
|
|
OpenThread(THREAD_ALL_ACCESS, FALSE, GetCurrentThreadId());
|
2014-05-27 11:15:35 +04:00
|
|
|
if (!winMainThreadHandle) {
|
2012-07-11 03:12:40 +04:00
|
|
|
return;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Don't actually start measuring hangs until we hit the main event loop.
|
|
|
|
// This potentially misses a small class of really early startup hangs,
|
|
|
|
// but avoids dealing with some xpcshell tests and other situations which
|
|
|
|
// start XPCOM but don't ever start the event loop.
|
|
|
|
Suspend();
|
|
|
|
|
|
|
|
gThread = PR_CreateThread(PR_USER_THREAD,
|
|
|
|
ThreadMain,
|
2013-10-11 00:42:16 +04:00
|
|
|
nullptr, PR_PRIORITY_LOW, PR_GLOBAL_THREAD,
|
2012-07-11 03:12:40 +04:00
|
|
|
PR_JOINABLE_THREAD, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Shutdown()
|
|
|
|
{
|
2015-12-27 03:34:11 +03:00
|
|
|
if (GeckoProcessType_Default != XRE_GetProcessType() &&
|
|
|
|
GeckoProcessType_Content != XRE_GetProcessType()) {
|
2012-07-11 03:12:40 +04:00
|
|
|
return;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
|
2013-02-08 09:54:20 +04:00
|
|
|
MOZ_ASSERT(gMonitor, "Hang monitor not started");
|
2012-07-11 03:12:40 +04:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
{
|
|
|
|
// Scope the lock we're going to delete later
|
2012-07-11 03:12:40 +04:00
|
|
|
MonitorAutoLock lock(*gMonitor);
|
|
|
|
gShutdown = true;
|
|
|
|
lock.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
// thread creation could theoretically fail
|
|
|
|
if (gThread) {
|
|
|
|
PR_JoinThread(gThread);
|
2013-10-11 00:42:16 +04:00
|
|
|
gThread = nullptr;
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
delete gMonitor;
|
2013-10-11 00:42:16 +04:00
|
|
|
gMonitor = nullptr;
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsUIMessageWaiting()
|
|
|
|
{
|
|
|
|
#ifndef XP_WIN
|
|
|
|
return false;
|
|
|
|
#else
|
2014-05-27 11:15:35 +04:00
|
|
|
#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
|
|
|
|
#define NS_WM_IMELAST WM_IME_KEYUP
|
2012-07-11 03:12:40 +04:00
|
|
|
BOOL haveUIMessageWaiting = FALSE;
|
|
|
|
MSG msg;
|
2014-05-27 11:15:35 +04:00
|
|
|
haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, WM_KEYFIRST,
|
2012-07-11 03:12:40 +04:00
|
|
|
WM_IME_KEYLAST, PM_NOREMOVE);
|
2013-10-11 00:42:16 +04:00
|
|
|
haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, NS_WM_IMEFIRST,
|
2012-07-11 03:12:40 +04:00
|
|
|
NS_WM_IMELAST, PM_NOREMOVE);
|
2013-10-11 00:42:16 +04:00
|
|
|
haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, WM_MOUSEFIRST,
|
2012-07-11 03:12:40 +04:00
|
|
|
WM_MOUSELAST, PM_NOREMOVE);
|
|
|
|
return haveUIMessageWaiting;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-27 11:15:35 +04:00
|
|
|
NotifyActivity(ActivityType aActivityType)
|
2012-07-11 03:12:40 +04:00
|
|
|
{
|
2013-02-08 09:54:20 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"HangMonitor::Notify called from off the main thread.");
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
// Determine the activity type more specifically
|
2014-05-27 11:15:35 +04:00
|
|
|
if (aActivityType == kGeneralActivity) {
|
|
|
|
aActivityType = IsUIMessageWaiting() ? kActivityUIAVail :
|
|
|
|
kActivityNoUIAVail;
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the cumulative amount of lag time since the last UI message
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t cumulativeUILagMS = 0;
|
2014-05-27 11:15:35 +04:00
|
|
|
switch (aActivityType) {
|
|
|
|
case kActivityNoUIAVail:
|
|
|
|
cumulativeUILagMS = 0;
|
|
|
|
break;
|
|
|
|
case kActivityUIAVail:
|
|
|
|
case kUIActivity:
|
|
|
|
if (gTimestamp != PR_INTERVAL_NO_WAIT) {
|
|
|
|
cumulativeUILagMS += PR_IntervalToMilliseconds(PR_IntervalNow() -
|
|
|
|
gTimestamp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is not a locked activity because PRTimeStamp is a 32-bit quantity
|
|
|
|
// which can be read/written atomically, and we don't want to pay locking
|
|
|
|
// penalties here.
|
|
|
|
gTimestamp = PR_IntervalNow();
|
|
|
|
|
2015-11-11 16:01:00 +03:00
|
|
|
// If we have UI activity we should reset the timer and report it
|
2014-05-27 11:15:35 +04:00
|
|
|
if (aActivityType == kUIActivity) {
|
2015-11-11 16:01:00 +03:00
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::EVENTLOOP_UI_ACTIVITY_EXP_MS,
|
2012-07-11 03:12:40 +04:00
|
|
|
cumulativeUILagMS);
|
|
|
|
cumulativeUILagMS = 0;
|
|
|
|
}
|
2014-01-14 20:33:31 +04:00
|
|
|
|
|
|
|
if (gThread && !gShutdown) {
|
|
|
|
mozilla::BackgroundHangMonitor().NotifyActivity();
|
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Suspend()
|
|
|
|
{
|
2013-02-08 09:54:20 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"HangMonitor::Suspend called from off the main thread.");
|
2012-07-11 03:12:40 +04:00
|
|
|
|
|
|
|
// Because gTimestamp changes this resets the wait count.
|
|
|
|
gTimestamp = PR_INTERVAL_NO_WAIT;
|
2014-01-14 20:33:31 +04:00
|
|
|
|
|
|
|
if (gThread && !gShutdown) {
|
|
|
|
mozilla::BackgroundHangMonitor().NotifyWait();
|
|
|
|
}
|
2012-07-11 03:12:40 +04:00
|
|
|
}
|
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
} // namespace HangMonitor
|
|
|
|
} // namespace mozilla
|