summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-04 04:00:40 +0000
committerrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-04 04:00:40 +0000
commitdedfabae74c92bf54454f5c1d69e07ad642993c4 (patch)
tree4174f5bc42a57d5c85ff6d9078b3ae3f89d22aff
parent76ff86af64d9260bc6042b3ab80adf78cc1a1582 (diff)
downloadchromium_src-dedfabae74c92bf54454f5c1d69e07ad642993c4.zip
chromium_src-dedfabae74c92bf54454f5c1d69e07ad642993c4.tar.gz
chromium_src-dedfabae74c92bf54454f5c1d69e07ad642993c4.tar.bz2
Start Watching threads only if we are running. Activate
thread watching only if we have registered the Thread Watcher objects. BUG=74855 TEST=thread watcher, run browser with -uninstall option R=jar Review URL: http://codereview.chromium.org/6611031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76871 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc6
-rw-r--r--chrome/browser/metrics/thread_watcher.cc20
-rw-r--r--chrome/browser/metrics/thread_watcher.h3
3 files changed, 22 insertions, 7 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 3e481a2..7c3ce0f 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -1318,9 +1318,6 @@ int BrowserMain(const MainFunctionParams& parameters) {
CreateChildThreads(browser_process.get());
- // Start watching all browser threads for responsiveness.
- ThreadWatcherList::StartWatchingAll();
-
#if defined(OS_CHROMEOS)
// Now that the file thread exists we can record our stats.
chromeos::BootTimesLoader::Get()->RecordChromeMainStats();
@@ -1752,6 +1749,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
DCHECK(gpu_data_manager);
+ // Start watching all browser threads for responsiveness.
+ ThreadWatcherList::StartWatchingAll();
+
int result_code = ResultCodes::NORMAL_EXIT;
if (parameters.ui_task) {
// We are in test mode. Run one task and enter the main message loop.
diff --git a/chrome/browser/metrics/thread_watcher.cc b/chrome/browser/metrics/thread_watcher.cc
index b1597f7..84bc71b 100644
--- a/chrome/browser/metrics/thread_watcher.cc
+++ b/chrome/browser/metrics/thread_watcher.cc
@@ -61,6 +61,10 @@ void ThreadWatcher::StartWatching(const BrowserThread::ID thread_id,
ThreadWatcher* watcher =
new ThreadWatcher(thread_id, thread_name, sleep_time, unresponsive_time);
DCHECK(watcher);
+ // If we couldn't register the thread watcher object, we are shutting down,
+ // then don't activate thread watching.
+ if (!ThreadWatcherList::IsRegistered(thread_id))
+ return;
watcher->ActivateThreadWatching();
}
@@ -207,22 +211,27 @@ ThreadWatcherList::~ThreadWatcherList() {
// static
void ThreadWatcherList::Register(ThreadWatcher* watcher) {
- DCHECK(global_);
+ if (!global_)
+ return;
base::AutoLock auto_lock(global_->lock_);
DCHECK(!global_->PreLockedFind(watcher->thread_id()));
global_->registered_[watcher->thread_id()] = watcher;
}
// static
+bool ThreadWatcherList::IsRegistered(const BrowserThread::ID thread_id) {
+ return NULL != ThreadWatcherList::Find(thread_id);
+}
+
+// static
void ThreadWatcherList::StartWatchingAll() {
if (!WatchDogThread::CurrentlyOnWatchDogThread()) {
WatchDogThread::PostDelayedTask(
FROM_HERE,
NewRunnableFunction(&ThreadWatcherList::StartWatchingAll),
- base::TimeDelta::FromSeconds(10).InMilliseconds());
+ base::TimeDelta::FromSeconds(5).InMilliseconds());
return;
}
-
DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
const base::TimeDelta kSleepTime = base::TimeDelta::FromSeconds(5);
const base::TimeDelta kUnresponsiveTime = base::TimeDelta::FromSeconds(10);
@@ -309,6 +318,8 @@ void ThreadWatcherList::Observe(NotificationType type,
void ThreadWatcherList::WakeUpAll() {
DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
+ if (!global_)
+ return;
base::AutoLock auto_lock(lock_);
for (RegistrationList::iterator it = global_->registered_.begin();
global_->registered_.end() != it;
@@ -318,7 +329,8 @@ void ThreadWatcherList::WakeUpAll() {
// static
ThreadWatcher* ThreadWatcherList::Find(const BrowserThread::ID thread_id) {
- DCHECK(global_);
+ if (!global_)
+ return NULL;
base::AutoLock auto_lock(global_->lock_);
return global_->PreLockedFind(thread_id);
}
diff --git a/chrome/browser/metrics/thread_watcher.h b/chrome/browser/metrics/thread_watcher.h
index b9fb6e0..43768d3 100644
--- a/chrome/browser/metrics/thread_watcher.h
+++ b/chrome/browser/metrics/thread_watcher.h
@@ -208,6 +208,9 @@ class ThreadWatcherList : public NotificationObserver {
// Register() stores a pointer to the given ThreadWatcher in a global map.
static void Register(ThreadWatcher* watcher);
+ // This method returns true if the ThreadWatcher object is registerd.
+ static bool IsRegistered(const BrowserThread::ID thread_id);
+
// This method posts a task on WatchDogThread to start watching all browser
// threads.
// This method is accessible on UI thread.