summaryrefslogtreecommitdiffstats
path: root/chrome/browser/metrics
diff options
context:
space:
mode:
authorrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 20:01:13 +0000
committerrtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 20:01:13 +0000
commit8fd1183f775fbc24041bf75ec484fc1205327a6b (patch)
treeec1e7c112b439881939d94c5e6d7f548cbe72064 /chrome/browser/metrics
parentb3ba270195d50aab0874ee0946000b83c2f69ce6 (diff)
downloadchromium_src-8fd1183f775fbc24041bf75ec484fc1205327a6b.zip
chromium_src-8fd1183f775fbc24041bf75ec484fc1205327a6b.tar.gz
chromium_src-8fd1183f775fbc24041bf75ec484fc1205327a6b.tar.bz2
Use BrowserThreadMessageLoopProxy to post messages to
watched browser thread. Store away thread_id using Debug::Alias so that optimizer doesn't optimize away the code so that we can see the thread_id that is hung from the crash dumps in windbg. Stop the WatchDog thread before stopping other threads to see if it fixes the racy condition duriong shutdown. BUG=83564, 86818, 89141, 83343, 83430 TEST=ThreadWatcher unit tests R=jar Review URL: http://codereview.chromium.org/7218030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/metrics')
-rw-r--r--chrome/browser/metrics/thread_watcher.cc19
-rw-r--r--chrome/browser/metrics/thread_watcher.h3
2 files changed, 12 insertions, 10 deletions
diff --git a/chrome/browser/metrics/thread_watcher.cc b/chrome/browser/metrics/thread_watcher.cc
index 2b0da7e..536402d 100644
--- a/chrome/browser/metrics/thread_watcher.cc
+++ b/chrome/browser/metrics/thread_watcher.cc
@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/metrics/thread_watcher.h"
+
#include <math.h> // ceil
+#include "base/debug/alias.h"
#include "base/string_tokenizer.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/metrics/metrics_service.h"
-#include "chrome/browser/metrics/thread_watcher.h"
#include "chrome/common/chrome_switches.h"
#include "content/common/notification_service.h"
@@ -29,6 +31,7 @@ ThreadWatcher::ThreadWatcher(const BrowserThread::ID& thread_id,
uint32 live_threads_threshold)
: thread_id_(thread_id),
thread_name_(thread_name),
+ watched_loop_(BrowserThread::GetMessageLoopProxyForThread(thread_id)),
sleep_time_(sleep_time),
unresponsive_time_(unresponsive_time),
ping_time_(base::TimeTicks::Now()),
@@ -141,8 +144,7 @@ void ThreadWatcher::PostPingMessage() {
// Send a ping message to the watched thread.
Task* callback_task = method_factory_.NewRunnableMethod(
&ThreadWatcher::OnPongMessage, ping_sequence_number_);
- if (BrowserThread::PostTask(
- thread_id(),
+ if (watched_loop_->PostTask(
FROM_HERE,
NewRunnableFunction(
&ThreadWatcher::OnPingMessage, thread_id_, callback_task))) {
@@ -292,10 +294,10 @@ void ThreadWatcher::GotNoResponse() {
// Crash the browser if the watched thread is to be crashed on hang and if the
// number of other threads responding is equal to live_threads_threshold_.
- if (crash_on_hang_ && responding_thread_count == live_threads_threshold_) {
- int* crash = NULL;
- CHECK(crash + thread_id_);
- }
+ int thread_id = thread_id_;
+ base::debug::Alias(&thread_id);
+ if (crash_on_hang_ && responding_thread_count == live_threads_threshold_)
+ CHECK(false);
hung_processing_complete_ = true;
}
@@ -486,9 +488,6 @@ void ThreadWatcherList::StartWatching(
uint32 live_threads_threshold) {
DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
- if (!BrowserThread::IsMessageLoopValid(thread_id))
- return;
-
std::set<std::string>::const_iterator it =
crash_on_hang_thread_names.find(thread_name);
bool crash_on_hang = (it != crash_on_hang_thread_names.end());
diff --git a/chrome/browser/metrics/thread_watcher.h b/chrome/browser/metrics/thread_watcher.h
index a53316c..a66a837 100644
--- a/chrome/browser/metrics/thread_watcher.h
+++ b/chrome/browser/metrics/thread_watcher.h
@@ -199,6 +199,9 @@ class ThreadWatcher {
// The name of the thread being watched.
const std::string thread_name_;
+ // Used to post messages to watched thread.
+ scoped_refptr<base::MessageLoopProxy> watched_loop_;
+
// It is the sleep time between the receipt of a pong message back, and the
// sending of another ping message.
const base::TimeDelta sleep_time_;