From a84cc5b06a037e081c439ffceab4c073799efb25 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Fri, 27 Feb 2015 14:45:02 -0500 Subject: [PATCH] Backed out changeset 2bac1ea5b5c6 (bug 1133521) for bustage. --- toolkit/components/telemetry/Telemetry.cpp | 18 ++-- xpcom/threads/BackgroundHangMonitor.cpp | 104 ++------------------- xpcom/threads/BackgroundHangMonitor.h | 20 ++-- xpcom/threads/moz.build | 5 - 4 files changed, 24 insertions(+), 123 deletions(-) diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index 524ad7b0ff1..761ca678efb 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -2904,21 +2904,21 @@ TelemetryImpl::GetThreadHangStats(JSContext* cx, JS::MutableHandle re } 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 */ - if (!BackgroundHangMonitor::IsDisabled()) { - 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; - } + 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); diff --git a/xpcom/threads/BackgroundHangMonitor.cpp b/xpcom/threads/BackgroundHangMonitor.cpp index a819974e933..c09ff745d8a 100644 --- a/xpcom/threads/BackgroundHangMonitor.cpp +++ b/xpcom/threads/BackgroundHangMonitor.cpp @@ -9,7 +9,6 @@ #include "mozilla/LinkedList.h" #include "mozilla/Monitor.h" #include "mozilla/Move.h" -#include "mozilla/Preferences.h" #include "mozilla/StaticPtr.h" #include "mozilla/Telemetry.h" #include "mozilla/ThreadHangStats.h" @@ -21,23 +20,16 @@ #include "prinrval.h" #include "prthread.h" #include "ThreadStackHelper.h" -#include "nsIObserverService.h" -#include "nsIObserver.h" -#include "mozilla/Services.h" -#include "nsXULAppAPI.h" #include -// Activate BHR only for one every BHR_BETA_MOD users. -#define BHR_BETA_MOD 100; - namespace mozilla { /** * BackgroundHangManager is the global object that * manages all instances of BackgroundHangThread. */ -class BackgroundHangManager : public nsIObserver +class BackgroundHangManager { private: // Background hang monitor thread function @@ -69,11 +61,9 @@ private: void RunMonitorThread(); public: - NS_DECL_THREADSAFE_ISUPPORTS - NS_DECL_NSIOBSERVER + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BackgroundHangManager) static StaticRefPtr sInstance; static bool sProhibited; - static bool sDisabled; // Lock for access to members of this class Monitor mLock; @@ -100,23 +90,9 @@ public: BackgroundHangManager(); private: - virtual ~BackgroundHangManager(); + ~BackgroundHangManager(); }; -NS_IMPL_ISUPPORTS(BackgroundHangManager, nsIObserver) - -NS_IMETHODIMP -BackgroundHangManager::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { - NS_ENSURE_TRUE(!strcmp(aTopic, "profile-after-change"), NS_ERROR_UNEXPECTED); - BackgroundHangMonitor::DisableOnBeta(); - - nsCOMPtr observerService = mozilla::services::GetObserverService(); - MOZ_ASSERT(observerService); - observerService->RemoveObserver(this, "profile-after-change"); - - return NS_OK; -} - /** * BackgroundHangThread is a per-thread object that is used * by all instances of BackgroundHangMonitor to monitor hangs. @@ -186,7 +162,6 @@ public: StaticRefPtr BackgroundHangManager::sInstance; bool BackgroundHangManager::sProhibited = false; -bool BackgroundHangManager::sDisabled = false; ThreadLocal BackgroundHangThread::sTlsKey; @@ -446,7 +421,7 @@ BackgroundHangThread::FindThread() { #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR if (BackgroundHangManager::sInstance == nullptr) { - MOZ_ASSERT(BackgroundHangManager::sProhibited || BackgroundHangManager::sDisabled, + MOZ_ASSERT(BackgroundHangManager::sProhibited, "BackgroundHandleManager is not initialized"); return nullptr; } @@ -475,38 +450,6 @@ BackgroundHangThread::FindThread() return nullptr; } -bool -BackgroundHangMonitor::ShouldDisableOnBeta(const nsCString &clientID) { - MOZ_ASSERT(clientID, "clientID is null"); - const char *suffix = clientID.get() + clientID.Length() - 4; - return strtol(suffix, NULL, 16) % BHR_BETA_MOD; -} - -bool -BackgroundHangMonitor::IsDisabled() { -#ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR - return BackgroundHangManager::sDisabled; -#else - return true; -#endif -} - -bool -BackgroundHangMonitor::DisableOnBeta() { - nsAdoptingCString clientID = Preferences::GetCString("toolkit.telemetry.cachedClientID"); - bool telemetryEnabled = Preferences::GetBool("toolkit.telemetry.enabled"); - - if (!telemetryEnabled || !clientID || BackgroundHangMonitor::ShouldDisableOnBeta(clientID)) { - if (XRE_IsParentProcess()) { - BackgroundHangMonitor::Shutdown(); - } else { - BackgroundHangManager::sDisabled = true; - } - return true; - } - - return false; -} void BackgroundHangMonitor::Startup() @@ -514,23 +457,6 @@ BackgroundHangMonitor::Startup() #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR MOZ_ASSERT(!BackgroundHangManager::sProhibited, "Prohibited"); MOZ_ASSERT(!BackgroundHangManager::sInstance, "Already initialized"); - - if (!strcmp(NS_STRINGIFY(MOZ_UPDATE_CHANNEL), "beta")) { - if (XRE_IsParentProcess()) { // cached ClientID hasn't been read yet - ThreadStackHelper::Startup(); - BackgroundHangThread::Startup(); - BackgroundHangManager::sInstance = new BackgroundHangManager(); - - nsCOMPtr observerService = mozilla::services::GetObserverService(); - MOZ_ASSERT(observerService); - - observerService->AddObserver(BackgroundHangManager::sInstance, "profile-after-change", false); - return; - } else if(DisableOnBeta()){ - return; - } - } - ThreadStackHelper::Startup(); BackgroundHangThread::Startup(); BackgroundHangManager::sInstance = new BackgroundHangManager(); @@ -541,11 +467,6 @@ void BackgroundHangMonitor::Shutdown() { #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR - if (BackgroundHangManager::sDisabled) { - MOZ_ASSERT(!BackgroundHangManager::sInstance, "Initialized"); - return; - } - MOZ_ASSERT(!BackgroundHangManager::sProhibited, "Prohibited"); MOZ_ASSERT(BackgroundHangManager::sInstance, "Not initialized"); /* Scope our lock inside Shutdown() because the sInstance object can @@ -554,7 +475,6 @@ BackgroundHangMonitor::Shutdown() BackgroundHangManager::sInstance->Shutdown(); BackgroundHangManager::sInstance = nullptr; ThreadStackHelper::Shutdown(); - BackgroundHangManager::sDisabled = true; #endif } @@ -564,7 +484,7 @@ BackgroundHangMonitor::BackgroundHangMonitor(const char* aName, : mThread(BackgroundHangThread::FindThread()) { #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR - if (!BackgroundHangManager::sDisabled && !BackgroundHangManager::sProhibited && !mThread) { + if (!BackgroundHangManager::sProhibited && !mThread) { // If sProhibit is true, mThread would be null, and no monitoring. mThread = new BackgroundHangThread(aName, aTimeoutMs, aMaxTimeoutMs); } @@ -575,10 +495,6 @@ BackgroundHangMonitor::BackgroundHangMonitor() : mThread(BackgroundHangThread::FindThread()) { #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR - if (BackgroundHangManager::sDisabled) { - return; - } - MOZ_ASSERT(!BackgroundHangManager::sProhibited || mThread, "This thread is not initialized for hang monitoring"); #endif @@ -593,8 +509,7 @@ BackgroundHangMonitor::NotifyActivity() { #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR if (mThread == nullptr) { - MOZ_ASSERT(BackgroundHangManager::sProhibited || - BackgroundHangManager::sDisabled, + MOZ_ASSERT(BackgroundHangManager::sProhibited, "This thread is not initialized for hang monitoring"); return; } @@ -610,8 +525,7 @@ BackgroundHangMonitor::NotifyWait() { #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR if (mThread == nullptr) { - MOZ_ASSERT(BackgroundHangManager::sProhibited || - BackgroundHangManager::sDisabled, + MOZ_ASSERT(BackgroundHangManager::sProhibited, "This thread is not initialized for hang monitoring"); return; } @@ -653,9 +567,7 @@ BackgroundHangMonitor::ThreadHangStatsIterator::ThreadHangStatsIterator() nullptr) { #ifdef MOZ_ENABLE_BACKGROUND_HANG_MONITOR - MOZ_ASSERT(BackgroundHangManager::sInstance || - BackgroundHangManager::sProhibited || - BackgroundHangManager::sDisabled, + MOZ_ASSERT(BackgroundHangManager::sInstance || BackgroundHangManager::sProhibited, "Inconsistent state"); #endif } diff --git a/xpcom/threads/BackgroundHangMonitor.h b/xpcom/threads/BackgroundHangMonitor.h index 333ae086b70..059fb0a08ff 100644 --- a/xpcom/threads/BackgroundHangMonitor.h +++ b/xpcom/threads/BackgroundHangMonitor.h @@ -10,8 +10,6 @@ #include "mozilla/RefPtr.h" #include "mozilla/Monitor.h" -#include "nsString.h" - #include namespace mozilla { @@ -20,8 +18,14 @@ namespace Telemetry { class ThreadHangStats; }; +// Disabled for Beta/Release builds because of bug 965392. +// Disabled for debug builds because of bug 979069. +#if !defined(RELEASE_BUILD) && !defined(DEBUG) +// Undefine to disable background hang monitor +#define MOZ_ENABLE_BACKGROUND_HANG_MONITOR +#endif + class BackgroundHangThread; -class BackgroundHangManager; /** * The background hang monitor is responsible for detecting and reporting @@ -109,13 +113,8 @@ class BackgroundHangManager; class BackgroundHangMonitor { private: - friend BackgroundHangManager; - RefPtr mThread; - static bool ShouldDisableOnBeta(const nsCString &); - static bool DisableOnBeta(); - public: static const uint32_t kNoTimeout = 0; @@ -169,11 +168,6 @@ public: */ static void Shutdown(); - /** - * Returns true if BHR is disabled. - */ - static bool IsDisabled(); - /** * Start monitoring hangs for the current thread. * diff --git a/xpcom/threads/moz.build b/xpcom/threads/moz.build index 05aa656c2ed..32cd6124596 100644 --- a/xpcom/threads/moz.build +++ b/xpcom/threads/moz.build @@ -59,11 +59,6 @@ LOCAL_INCLUDES += [ '/tools/profiler', ] -# BHR disabled for Release builds because of bug 965392. -# BHR disabled for debug builds because of bug 979069. -if CONFIG['MOZ_UPDATE_CHANNEL'] not in ('release') and not CONFIG['DEBUG']: - DEFINES['MOZ_ENABLE_BACKGROUND_HANG_MONITOR'] = 1 - FAIL_ON_WARNINGS = True FINAL_LIBRARY = 'xul'