Bug 970358 - Disable BackgroundHangMonitor on release builds. r=froydnj, a=sledru
authorJim Chen <nchen@mozilla.com>
Wed, 12 Feb 2014 10:24:21 -0500
changeset 182799 d17893fc481a5e575538877cdbdaf2c084d72d42
parent 182798 3c307b71fec5c8afe32a10e4706869b8c68542dd
child 182800 4639d13d1ccf71ab37e9d3d573c77ac7f8fc6c8b
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, sledru
bugs970358
milestone29.0a2
Bug 970358 - Disable BackgroundHangMonitor on release builds. r=froydnj, a=sledru
toolkit/components/telemetry/Telemetry.cpp
xpcom/threads/BackgroundHangMonitor.cpp
xpcom/threads/BackgroundHangMonitor.h
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -2093,29 +2093,31 @@ NS_IMETHODIMP
 TelemetryImpl::GetThreadHangStats(JSContext* cx, JS::MutableHandle<JS::Value> ret)
 {
   JS::RootedObject retObj(cx, JS_NewArrayObject(cx, 0, nullptr));
   if (!retObj) {
     return NS_ERROR_FAILURE;
   }
   size_t threadIndex = 0;
 
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   /* First add active threads; we need to hold |iter| (and its lock)
      throughout this method to avoid a race condition where a thread can
      be recorded twice if the thread is destroyed while this method is
      running */
   BackgroundHangMonitor::ThreadHangStatsIterator iter;
   for (Telemetry::ThreadHangStats* histogram = iter.GetNext();
        histogram; histogram = iter.GetNext()) {
     JS::RootedObject obj(cx,
       CreateJSThreadHangStats(cx, *histogram));
     if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
       return NS_ERROR_FAILURE;
     }
   }
+#endif
 
   // Add saved threads next
   MutexAutoLock autoLock(mThreadHangStatsMutex);
   for (size_t i = 0; i < mThreadHangStats.length(); i++) {
     JS::RootedObject obj(cx,
       CreateJSThreadHangStats(cx, mThreadHangStats[i]));
     if (!JS_SetElement(cx, retObj, threadIndex++, obj)) {
       return NS_ERROR_FAILURE;
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -405,16 +405,17 @@ BackgroundHangThread::NotifyActivity()
     }
     mInterval = intervalNow;
   }
 }
 
 BackgroundHangThread*
 BackgroundHangThread::FindThread()
 {
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   if (sTlsKey.initialized()) {
     // Use TLS if available
     return sTlsKey.get();
   }
   // If TLS is unavailable, we can search through the thread list
   RefPtr<BackgroundHangManager> manager(BackgroundHangManager::sInstance);
   MOZ_ASSERT(manager, "Creating BackgroundHangMonitor after shutdown");
 
@@ -422,72 +423,85 @@ BackgroundHangThread::FindThread()
   // Lock thread list for traversal
   MonitorAutoLock autoLock(manager->mLock);
   for (BackgroundHangThread* thread = manager->mHangThreads.getFirst();
        thread; thread = thread->getNext()) {
     if (thread->mThreadID == threadID) {
       return thread;
     }
   }
+#endif
   // Current thread is not initialized
   return nullptr;
 }
 
 
 void
 BackgroundHangMonitor::Startup()
 {
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   MOZ_ASSERT(!BackgroundHangManager::sInstance, "Already initialized");
   ThreadStackHelper::Startup();
   BackgroundHangThread::Startup();
   BackgroundHangManager::sInstance = new BackgroundHangManager();
+#endif
 }
 
 void
 BackgroundHangMonitor::Shutdown()
 {
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   MOZ_ASSERT(BackgroundHangManager::sInstance, "Not initialized");
   /* Scope our lock inside Shutdown() because the sInstance object can
      be destroyed as soon as we set sInstance to nullptr below, and
      we don't want to hold the lock when it's being destroyed. */
   BackgroundHangManager::sInstance->Shutdown();
   BackgroundHangManager::sInstance = nullptr;
   ThreadStackHelper::Shutdown();
+#endif
 }
 
 BackgroundHangMonitor::BackgroundHangMonitor(const char* aName,
                                              uint32_t aTimeoutMs,
                                              uint32_t aMaxTimeoutMs)
   : mThread(BackgroundHangThread::FindThread())
 {
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   if (!mThread) {
     mThread = new BackgroundHangThread(aName, aTimeoutMs, aMaxTimeoutMs);
   }
+#endif
 }
 
 BackgroundHangMonitor::BackgroundHangMonitor()
   : mThread(BackgroundHangThread::FindThread())
 {
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   MOZ_ASSERT(mThread, "Thread not initialized for hang monitoring");
+#endif
 }
 
 BackgroundHangMonitor::~BackgroundHangMonitor()
 {
 }
 
 void
 BackgroundHangMonitor::NotifyActivity()
 {
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   mThread->NotifyActivity();
+#endif
 }
 
 void
 BackgroundHangMonitor::NotifyWait()
 {
+#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR
   mThread->NotifyWait();
+#endif
 }
 
 
 /* Because we are iterating through the BackgroundHangThread linked list,
    we need to take a lock. Using MonitorAutoLock as a base class makes
    sure all of that is taken care of for us. */
 BackgroundHangMonitor::ThreadHangStatsIterator::ThreadHangStatsIterator()
   : MonitorAutoLock(BackgroundHangManager::sInstance->mLock)
--- a/xpcom/threads/BackgroundHangMonitor.h
+++ b/xpcom/threads/BackgroundHangMonitor.h
@@ -12,16 +12,21 @@
 #include <stdint.h>
 
 namespace mozilla {
 
 namespace Telemetry {
 class ThreadHangStats;
 };
 
+#ifndef RELEASE_BUILD
+// Undefine to disable background hang monitor
+#define MOZ_ENABLE_BACKGROUND_HANG_MONITOR
+#endif
+
 class BackgroundHangThread;
 
 /**
  * The background hang monitor is responsible for detecting and reporting
  * hangs in background (non-main) threads. A thread registers itself using
  * the BackgroundHangMonitor object and periodically calls its methods to
  * inform the hang monitor of the thread's activity. Each thread is given
  * a thread name, a timeout, and a maximum timeout. If one of the thread's