OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/metrics/thread_watcher.h" | 5 #include "chrome/browser/metrics/thread_watcher.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if (!WatchDogThread::CurrentlyOnWatchDogThread()) { | 72 if (!WatchDogThread::CurrentlyOnWatchDogThread()) { |
73 WatchDogThread::PostTask( | 73 WatchDogThread::PostTask( |
74 FROM_HERE, | 74 FROM_HERE, |
75 base::Bind(&ThreadWatcher::StartWatching, params)); | 75 base::Bind(&ThreadWatcher::StartWatching, params)); |
76 return; | 76 return; |
77 } | 77 } |
78 | 78 |
79 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 79 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
80 | 80 |
81 // Create a new thread watcher object for the given thread and activate it. | 81 // Create a new thread watcher object for the given thread and activate it. |
82 std::unique_ptr<ThreadWatcher> watcher(new ThreadWatcher(params)); | 82 ThreadWatcher* watcher = new ThreadWatcher(params); |
83 | 83 |
| 84 DCHECK(watcher); |
84 // If we couldn't register the thread watcher object, we are shutting down, | 85 // If we couldn't register the thread watcher object, we are shutting down, |
85 // so don't activate thread watching. | 86 // then don't activate thread watching. |
86 if (!ThreadWatcherList::Register(std::move(watcher))) | 87 if (!ThreadWatcherList::IsRegistered(params.thread_id)) |
87 return; | 88 return; |
88 watcher->ActivateThreadWatching(); | 89 watcher->ActivateThreadWatching(); |
89 } | 90 } |
90 | 91 |
91 void ThreadWatcher::ActivateThreadWatching() { | 92 void ThreadWatcher::ActivateThreadWatching() { |
92 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 93 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
93 if (active_) return; | 94 if (active_) return; |
94 active_ = true; | 95 active_ = true; |
95 ping_count_ = unresponsive_threshold_; | 96 ping_count_ = unresponsive_threshold_; |
96 ResetHangCounters(); | 97 ResetHangCounters(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 217 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
217 FROM_HERE, | 218 FROM_HERE, |
218 base::Bind(&ThreadWatcher::OnCheckResponsiveness, | 219 base::Bind(&ThreadWatcher::OnCheckResponsiveness, |
219 weak_ptr_factory_.GetWeakPtr(), ping_sequence_number_), | 220 weak_ptr_factory_.GetWeakPtr(), ping_sequence_number_), |
220 unresponsive_time_); | 221 unresponsive_time_); |
221 responsive_ = false; | 222 responsive_ = false; |
222 } | 223 } |
223 | 224 |
224 void ThreadWatcher::Initialize() { | 225 void ThreadWatcher::Initialize() { |
225 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 226 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
| 227 ThreadWatcherList::Register(this); |
226 | 228 |
227 const std::string response_time_histogram_name = | 229 const std::string response_time_histogram_name = |
228 "ThreadWatcher.ResponseTime." + thread_name_; | 230 "ThreadWatcher.ResponseTime." + thread_name_; |
229 response_time_histogram_ = base::Histogram::FactoryTimeGet( | 231 response_time_histogram_ = base::Histogram::FactoryTimeGet( |
230 response_time_histogram_name, | 232 response_time_histogram_name, |
231 base::TimeDelta::FromMilliseconds(1), | 233 base::TimeDelta::FromMilliseconds(1), |
232 base::TimeDelta::FromSeconds(100), 50, | 234 base::TimeDelta::FromSeconds(100), 50, |
233 base::Histogram::kUmaTargetedHistogramFlag); | 235 base::Histogram::kUmaTargetedHistogramFlag); |
234 | 236 |
235 const std::string unresponsive_time_histogram_name = | 237 const std::string unresponsive_time_histogram_name = |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 375 } |
374 | 376 |
375 // static | 377 // static |
376 void ThreadWatcherList::StopWatchingAll() { | 378 void ThreadWatcherList::StopWatchingAll() { |
377 // TODO(rtenneti): Enable ThreadWatcher. | 379 // TODO(rtenneti): Enable ThreadWatcher. |
378 ThreadWatcherObserver::RemoveNotifications(); | 380 ThreadWatcherObserver::RemoveNotifications(); |
379 DeleteAll(); | 381 DeleteAll(); |
380 } | 382 } |
381 | 383 |
382 // static | 384 // static |
383 bool ThreadWatcherList::Register(std::unique_ptr<ThreadWatcher> watcher) { | 385 void ThreadWatcherList::Register(ThreadWatcher* watcher) { |
384 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 386 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
385 if (!g_thread_watcher_list_) | 387 if (!g_thread_watcher_list_) |
386 return false; | 388 return; |
387 content::BrowserThread::ID thread_id = watcher->thread_id(); | 389 DCHECK(!g_thread_watcher_list_->Find(watcher->thread_id())); |
388 DCHECK(g_thread_watcher_list_->registered_.count(thread_id) == 0); | 390 g_thread_watcher_list_->registered_[watcher->thread_id()] = watcher; |
389 g_thread_watcher_list_->registered_[thread_id] = watcher.release(); | |
390 return true; | |
391 } | 391 } |
392 | 392 |
393 // static | 393 // static |
| 394 bool ThreadWatcherList::IsRegistered(const BrowserThread::ID thread_id) { |
| 395 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
| 396 return nullptr != ThreadWatcherList::Find(thread_id); |
| 397 } |
| 398 |
| 399 // static |
394 void ThreadWatcherList::GetStatusOfThreads( | 400 void ThreadWatcherList::GetStatusOfThreads( |
395 uint32_t* responding_thread_count, | 401 uint32_t* responding_thread_count, |
396 uint32_t* unresponding_thread_count) { | 402 uint32_t* unresponding_thread_count) { |
397 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 403 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
398 *responding_thread_count = 0; | 404 *responding_thread_count = 0; |
399 *unresponding_thread_count = 0; | 405 *unresponding_thread_count = 0; |
400 if (!g_thread_watcher_list_) | 406 if (!g_thread_watcher_list_) |
401 return; | 407 return; |
402 | 408 |
403 for (RegistrationList::iterator it = | 409 for (RegistrationList::iterator it = |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 | 999 |
994 #if defined(OS_WIN) | 1000 #if defined(OS_WIN) |
995 // On Windows XP, give twice the time for shutdown. | 1001 // On Windows XP, give twice the time for shutdown. |
996 if (base::win::GetVersion() <= base::win::VERSION_XP) | 1002 if (base::win::GetVersion() <= base::win::VERSION_XP) |
997 actual_duration *= 2; | 1003 actual_duration *= 2; |
998 #endif | 1004 #endif |
999 | 1005 |
1000 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 1006 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
1001 shutdown_watchdog_->Arm(); | 1007 shutdown_watchdog_->Arm(); |
1002 } | 1008 } |
OLD | NEW |