| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/threading/thread_restrictions.h" | 5 #include "base/threading/thread_restrictions.h" |
| 6 #include "chrome/browser/metrics/metrics_service.h" | 6 #include "chrome/browser/metrics/metrics_service.h" |
| 7 #include "chrome/browser/metrics/thread_watcher.h" | 7 #include "chrome/browser/metrics/thread_watcher.h" |
| 8 #include "chrome/common/notification_service.h" | 8 #include "chrome/common/notification_service.h" |
| 9 | 9 |
| 10 // static | 10 // static |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // ping messages. | 97 // ping messages. |
| 98 if (!active_ || ping_count_ <= 0) | 98 if (!active_ || ping_count_ <= 0) |
| 99 return; | 99 return; |
| 100 | 100 |
| 101 // Save the current time when we have sent ping message. | 101 // Save the current time when we have sent ping message. |
| 102 ping_time_ = base::TimeTicks::Now(); | 102 ping_time_ = base::TimeTicks::Now(); |
| 103 | 103 |
| 104 // Send a ping message to the watched thread. | 104 // Send a ping message to the watched thread. |
| 105 Task* callback_task = method_factory_.NewRunnableMethod( | 105 Task* callback_task = method_factory_.NewRunnableMethod( |
| 106 &ThreadWatcher::OnPongMessage, ping_sequence_number_); | 106 &ThreadWatcher::OnPongMessage, ping_sequence_number_); |
| 107 BrowserThread::PostTask( | 107 if (BrowserThread::PostTask( |
| 108 thread_id(), | 108 thread_id(), |
| 109 FROM_HERE, | 109 FROM_HERE, |
| 110 NewRunnableFunction( | 110 NewRunnableFunction( |
| 111 &ThreadWatcher::OnPingMessage, thread_id_, callback_task)); | 111 &ThreadWatcher::OnPingMessage, thread_id_, callback_task))) { |
| 112 | 112 // Post a task to check the responsiveness of watched thread. |
| 113 // Post a task to check the responsiveness of watched thread. | 113 MessageLoop::current()->PostDelayedTask( |
| 114 MessageLoop::current()->PostDelayedTask( | 114 FROM_HERE, |
| 115 FROM_HERE, | 115 method_factory_.NewRunnableMethod( |
| 116 method_factory_.NewRunnableMethod( | 116 &ThreadWatcher::OnCheckResponsiveness, ping_sequence_number_), |
| 117 &ThreadWatcher::OnCheckResponsiveness, ping_sequence_number_), | 117 unresponsive_time_.InMilliseconds()); |
| 118 unresponsive_time_.InMilliseconds()); | 118 } else { |
| 119 // Watched thread might have gone away, stop watching it. |
| 120 delete callback_task; |
| 121 DeActivateThreadWatching(); |
| 122 } |
| 119 } | 123 } |
| 120 | 124 |
| 121 void ThreadWatcher::OnPongMessage(uint64 ping_sequence_number) { | 125 void ThreadWatcher::OnPongMessage(uint64 ping_sequence_number) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); |
| 123 // Record watched thread's response time. | 127 // Record watched thread's response time. |
| 124 base::TimeDelta response_time = base::TimeTicks::Now() - ping_time_; | 128 base::TimeDelta response_time = base::TimeTicks::Now() - ping_time_; |
| 125 histogram_->AddTime(response_time); | 129 histogram_->AddTime(response_time); |
| 126 | 130 |
| 127 // Check if there are any extra pings in flight. | 131 // Check if there are any extra pings in flight. |
| 128 DCHECK_EQ(ping_sequence_number_, ping_sequence_number); | 132 DCHECK_EQ(ping_sequence_number_, ping_sequence_number); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 kUnresponsiveTime); | 315 kUnresponsiveTime); |
| 312 ThreadWatcher::StartWatching(BrowserThread::IO, "IO", kSleepTime, | 316 ThreadWatcher::StartWatching(BrowserThread::IO, "IO", kSleepTime, |
| 313 kUnresponsiveTime); | 317 kUnresponsiveTime); |
| 314 ThreadWatcher::StartWatching(BrowserThread::DB, "DB", kSleepTime, | 318 ThreadWatcher::StartWatching(BrowserThread::DB, "DB", kSleepTime, |
| 315 kUnresponsiveTime); | 319 kUnresponsiveTime); |
| 316 ThreadWatcher::StartWatching(BrowserThread::FILE, "FILE", kSleepTime, | 320 ThreadWatcher::StartWatching(BrowserThread::FILE, "FILE", kSleepTime, |
| 317 kUnresponsiveTime); | 321 kUnresponsiveTime); |
| 318 ThreadWatcher::StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, | 322 ThreadWatcher::StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, |
| 319 kUnresponsiveTime); | 323 kUnresponsiveTime); |
| 320 } | 324 } |
| OLD | NEW |