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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // ping messages. | 95 // ping messages. |
96 if (!active_ || ping_count_ <= 0) | 96 if (!active_ || ping_count_ <= 0) |
97 return; | 97 return; |
98 | 98 |
99 // Save the current time when we have sent ping message. | 99 // Save the current time when we have sent ping message. |
100 ping_time_ = base::TimeTicks::Now(); | 100 ping_time_ = base::TimeTicks::Now(); |
101 | 101 |
102 // Send a ping message to the watched thread. | 102 // Send a ping message to the watched thread. |
103 Task* callback_task = method_factory_.NewRunnableMethod( | 103 Task* callback_task = method_factory_.NewRunnableMethod( |
104 &ThreadWatcher::OnPongMessage, ping_sequence_number_); | 104 &ThreadWatcher::OnPongMessage, ping_sequence_number_); |
105 BrowserThread::PostTask( | 105 if (BrowserThread::PostTask( |
106 thread_id(), | 106 thread_id(), |
107 FROM_HERE, | 107 FROM_HERE, |
108 NewRunnableFunction( | 108 NewRunnableFunction( |
109 &ThreadWatcher::OnPingMessage, thread_id_, callback_task)); | 109 &ThreadWatcher::OnPingMessage, thread_id_, callback_task))) { |
110 | 110 // Post a task to check the responsiveness of watched thread. |
111 // Post a task to check the responsiveness of watched thread. | 111 MessageLoop::current()->PostDelayedTask( |
112 MessageLoop::current()->PostDelayedTask( | 112 FROM_HERE, |
113 FROM_HERE, | 113 method_factory_.NewRunnableMethod( |
114 method_factory_.NewRunnableMethod( | 114 &ThreadWatcher::OnCheckResponsiveness, ping_sequence_number_), |
115 &ThreadWatcher::OnCheckResponsiveness, ping_sequence_number_), | 115 unresponsive_time_.InMilliseconds()); |
116 unresponsive_time_.InMilliseconds()); | 116 } else { |
117 // Watched thread might have gone away, stop watching it. | |
118 delete callback_task; | |
119 DeActivateThreadWatching(); | |
willchan no longer on Chromium
2011/02/23 23:39:02
I have not re-read the changelist since the last r
| |
120 } | |
117 } | 121 } |
118 | 122 |
119 void ThreadWatcher::OnPongMessage(uint64 ping_sequence_number) { | 123 void ThreadWatcher::OnPongMessage(uint64 ping_sequence_number) { |
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WATCHDOG)); |
121 // Record watched thread's response time. | 125 // Record watched thread's response time. |
122 base::TimeDelta response_time = base::TimeTicks::Now() - ping_time_; | 126 base::TimeDelta response_time = base::TimeTicks::Now() - ping_time_; |
123 histogram_->AddTime(response_time); | 127 histogram_->AddTime(response_time); |
124 | 128 |
125 // Check if there are any extra pings in flight. | 129 // Check if there are any extra pings in flight. |
126 DCHECK_EQ(ping_sequence_number_, ping_sequence_number); | 130 DCHECK_EQ(ping_sequence_number_, ping_sequence_number); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 kUnresponsiveTime); | 313 kUnresponsiveTime); |
310 ThreadWatcher::StartWatching(BrowserThread::IO, "IO", kSleepTime, | 314 ThreadWatcher::StartWatching(BrowserThread::IO, "IO", kSleepTime, |
311 kUnresponsiveTime); | 315 kUnresponsiveTime); |
312 ThreadWatcher::StartWatching(BrowserThread::DB, "DB", kSleepTime, | 316 ThreadWatcher::StartWatching(BrowserThread::DB, "DB", kSleepTime, |
313 kUnresponsiveTime); | 317 kUnresponsiveTime); |
314 ThreadWatcher::StartWatching(BrowserThread::FILE, "FILE", kSleepTime, | 318 ThreadWatcher::StartWatching(BrowserThread::FILE, "FILE", kSleepTime, |
315 kUnresponsiveTime); | 319 kUnresponsiveTime); |
316 ThreadWatcher::StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, | 320 ThreadWatcher::StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, |
317 kUnresponsiveTime); | 321 kUnresponsiveTime); |
318 } | 322 } |
OLD | NEW |