Bug 951431 - Monitor main thread hangs using BackgroundHangMonitor. r=vladan, a=lsblakk
☠☠ backed out by 6332a66fff72 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Tue, 14 Jan 2014 10:33:31 -0600
changeset 175808 990a21978a2dfc03bca8af57fe1843c0fe674518
parent 175807 17e6923abc9f04e8c725b03055dc158f7c882891
child 175809 73f3ce609c233a063b355d949a3fa02658df7c9b
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladan, lsblakk
bugs951431
milestone28.0a2
Bug 951431 - Monitor main thread hangs using BackgroundHangMonitor. r=vladan, a=lsblakk
xpcom/build/nsXPComInit.cpp
xpcom/threads/HangMonitor.cpp
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -140,16 +140,17 @@ using mozilla::eventtracer::VisualEventT
 #endif
 
 namespace {
 
 static AtExitManager* sExitManager;
 static MessageLoop* sMessageLoop;
 static bool sCommandLineWasInitialized;
 static BrowserProcessSubThread* sIOThread;
+static BackgroundHangMonitor* sMainHangMonitor;
 
 } /* anonymous namespace */
 
 // Registry Factory creation function defined in nsRegistry.cpp
 // We hook into this function locally to create and register the registry
 // Since noone outside xpcom needs to know about this and nsRegistry.cpp
 // does not have a local include file, we are putting this definition
 // here rather than in nsIRegistry.h
@@ -413,16 +414,20 @@ NS_InitXPCOM2(nsIServiceManager* *result
     NS_ASSERTION(!sExitManager && !sMessageLoop, "Bad logic!");
 
     if (!AtExitManager::AlreadyRegistered()) {
         sExitManager = new AtExitManager();
     }
 
     if (!MessageLoop::current()) {
         sMessageLoop = new MessageLoopForUI(MessageLoop::TYPE_MOZILLA_UI);
+        sMessageLoop->set_thread_name("Gecko");
+        // Set experimental values for main thread hangs:
+        // 512ms for transient hangs and 8192ms for permanent hangs
+        sMessageLoop->set_hang_timeouts(512, 8192);
     }
 
     if (XRE_GetProcessType() == GeckoProcessType_Default &&
         !BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO)) {
         scoped_ptr<BrowserProcessSubThread> ioThread(
             new BrowserProcessSubThread(BrowserProcessSubThread::IO));
 
         base::Thread::Options options;
@@ -585,16 +590,22 @@ NS_InitXPCOM2(nsIServiceManager* *result
     // ICU's memory usage.
     RegisterStrongMemoryReporter(new ICUReporter());
 
     mozilla::Telemetry::Init();
 
     mozilla::HangMonitor::Startup();
     mozilla::BackgroundHangMonitor::Startup();
 
+    const MessageLoop* const loop = MessageLoop::current();
+    sMainHangMonitor = new mozilla::BackgroundHangMonitor(
+        loop->thread_name().c_str(),
+        loop->transient_hang_timeout(),
+        loop->permanent_hang_timeout());
+
 #ifdef MOZ_VISUAL_EVENT_TRACER
     mozilla::eventtracer::Init();
 #endif
 
     return NS_OK;
 }
 
 
@@ -829,16 +840,21 @@ ShutdownXPCOM(nsIServiceManager* servMgr
     if (sExitManager) {
         delete sExitManager;
         sExitManager = nullptr;
     }
 
     Omnijar::CleanUp();
 
     HangMonitor::Shutdown();
+
+    if (sMainHangMonitor) {
+        delete sMainHangMonitor;
+        sMainHangMonitor = nullptr;
+    }
     BackgroundHangMonitor::Shutdown();
 
 #ifdef MOZ_VISUAL_EVENT_TRACER
     eventtracer::Shutdown();
 #endif
 
     profiler_shutdown();
 
--- a/xpcom/threads/HangMonitor.cpp
+++ b/xpcom/threads/HangMonitor.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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"
+#include "mozilla/BackgroundHangMonitor.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/ProcessedStack.h"
 #include "mozilla/Atomics.h"
 #include "nsXULAppAPI.h"
 #include "nsThreadUtils.h"
 #include "nsStackWalk.h"
@@ -341,21 +342,29 @@ NotifyActivity(ActivityType activityType
     // Mozilla's UI responsiveness goal is 50ms
     static const uint32_t kUIResponsivenessThresholdMS = 50;
     if (cumulativeUILagMS > kUIResponsivenessThresholdMS) {
       mozilla::Telemetry::Accumulate(mozilla::Telemetry::EVENTLOOP_UI_LAG_EXP_MS,
                                      cumulativeUILagMS);
     }
     cumulativeUILagMS = 0;
   }
+
+  if (gThread && !gShutdown) {
+    mozilla::BackgroundHangMonitor().NotifyActivity();
+  }
 }
 
 void
 Suspend()
 {
   MOZ_ASSERT(NS_IsMainThread(),
              "HangMonitor::Suspend called from off the main thread.");
 
   // Because gTimestamp changes this resets the wait count.
   gTimestamp = PR_INTERVAL_NO_WAIT;
+
+  if (gThread && !gShutdown) {
+    mozilla::BackgroundHangMonitor().NotifyWait();
+  }
 }
 
 } } // namespace mozilla::HangMonitor