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 176292 3c2d1430b3d177ebea13dfd30d8cbb57a835e64d
parent 176291 0e77fc5ebdb3ad6007d2d03b9ba98491ba4f9970
child 176293 54f798e1ae0f01eb1424fa69027bd43c33788eea
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)
reviewersfroydnj, sledru
bugs970358
milestone28.0
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
@@ -1846,30 +1846,32 @@ NS_IMETHODIMP
 TelemetryImpl::GetThreadHangStats(JSContext* cx, 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));
     JS::RootedValue thread(cx, OBJECT_TO_JSVAL(obj));
     if (!JS_SetElement(cx, retObj, threadIndex++, &thread)) {
       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]));
     JS::RootedValue thread(cx, OBJECT_TO_JSVAL(obj));
     if (!JS_SetElement(cx, retObj, threadIndex++, &thread)) {
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -403,16 +403,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");
 
@@ -420,72 +421,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