| 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 // This file defines a WatchDog thread that monitors the responsiveness of other | 5 // This file defines a WatchDog thread that monitors the responsiveness of other |
| 6 // browser threads like UI, IO, DB, FILE and CACHED threads. It also defines | 6 // browser threads like UI, IO, DB, FILE and CACHED threads. It also defines |
| 7 // ThreadWatcher class which performs health check on threads that would like to | 7 // ThreadWatcher class which performs health check on threads that would like to |
| 8 // be watched. This file also defines ThreadWatcherList class that has list of | 8 // be watched. This file also defines ThreadWatcherList class that has list of |
| 9 // all active ThreadWatcher objects. | 9 // all active ThreadWatcher objects. |
| 10 // | 10 // |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 uint32_t live_threads_threshold_in) | 95 uint32_t live_threads_threshold_in) |
| 96 : thread_id(thread_id_in), | 96 : thread_id(thread_id_in), |
| 97 thread_name(thread_name_in), | 97 thread_name(thread_name_in), |
| 98 sleep_time(sleep_time_in), | 98 sleep_time(sleep_time_in), |
| 99 unresponsive_time(unresponsive_time_in), | 99 unresponsive_time(unresponsive_time_in), |
| 100 unresponsive_threshold(unresponsive_threshold_in), | 100 unresponsive_threshold(unresponsive_threshold_in), |
| 101 crash_on_hang(crash_on_hang_in), | 101 crash_on_hang(crash_on_hang_in), |
| 102 live_threads_threshold(live_threads_threshold_in) {} | 102 live_threads_threshold(live_threads_threshold_in) {} |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 virtual ~ThreadWatcher(); | |
| 106 | |
| 107 // This method starts performing health check on the given |thread_id|. It | 105 // This method starts performing health check on the given |thread_id|. It |
| 108 // will create ThreadWatcher object for the given |thread_id|, |thread_name|. | 106 // will create ThreadWatcher object for the given |thread_id|, |thread_name|. |
| 109 // |sleep_time| is the wait time between ping messages. |unresponsive_time| is | 107 // |sleep_time| is the wait time between ping messages. |unresponsive_time| is |
| 110 // the wait time after ping message is sent, to check if we have received pong | 108 // the wait time after ping message is sent, to check if we have received pong |
| 111 // message or not. |unresponsive_threshold| is used to determine if the thread | 109 // message or not. |unresponsive_threshold| is used to determine if the thread |
| 112 // is responsive or not. The watched thread is considered unresponsive if it | 110 // is responsive or not. The watched thread is considered unresponsive if it |
| 113 // hasn't responded with a pong message for |unresponsive_threshold| number of | 111 // hasn't responded with a pong message for |unresponsive_threshold| number of |
| 114 // ping messages. |crash_on_hang| specifies if browser should be crashed when | 112 // ping messages. |crash_on_hang| specifies if browser should be crashed when |
| 115 // the watched thread is unresponsive. |live_threads_threshold| specifies the | 113 // the watched thread is unresponsive. |live_threads_threshold| specifies the |
| 116 // number of browser threads that are to be responsive when we want to crash | 114 // number of browser threads that are to be responsive when we want to crash |
| (...skipping 22 matching lines...) Expand all Loading... |
| 139 | 137 |
| 140 // Returns |ping_sequence_number_| (used by unit tests). | 138 // Returns |ping_sequence_number_| (used by unit tests). |
| 141 uint64_t ping_sequence_number() const { return ping_sequence_number_; } | 139 uint64_t ping_sequence_number() const { return ping_sequence_number_; } |
| 142 | 140 |
| 143 protected: | 141 protected: |
| 144 // Construct a ThreadWatcher for the given |thread_id|. |sleep_time| is the | 142 // Construct a ThreadWatcher for the given |thread_id|. |sleep_time| is the |
| 145 // wait time between ping messages. |unresponsive_time| is the wait time after | 143 // wait time between ping messages. |unresponsive_time| is the wait time after |
| 146 // ping message is sent, to check if we have received pong message or not. | 144 // ping message is sent, to check if we have received pong message or not. |
| 147 explicit ThreadWatcher(const WatchingParams& params); | 145 explicit ThreadWatcher(const WatchingParams& params); |
| 148 | 146 |
| 147 virtual ~ThreadWatcher(); |
| 148 |
| 149 // This method activates the thread watching which starts ping/pong messaging. | 149 // This method activates the thread watching which starts ping/pong messaging. |
| 150 virtual void ActivateThreadWatching(); | 150 virtual void ActivateThreadWatching(); |
| 151 | 151 |
| 152 // This method de-activates the thread watching and revokes all tasks. | 152 // This method de-activates the thread watching and revokes all tasks. |
| 153 virtual void DeActivateThreadWatching(); | 153 virtual void DeActivateThreadWatching(); |
| 154 | 154 |
| 155 // This will ensure that the watching is actively taking place, and awaken | 155 // This will ensure that the watching is actively taking place, and awaken |
| 156 // (i.e., post a PostPingMessage()) if the watcher has stopped pinging due to | 156 // (i.e., post a PostPingMessage()) if the watcher has stopped pinging due to |
| 157 // lack of user activity. It will also reset |ping_count_| to | 157 // lack of user activity. It will also reset |ping_count_| to |
| 158 // |unresponsive_threshold_|. | 158 // |unresponsive_threshold_|. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // This method is accessible on UI thread. | 387 // This method is accessible on UI thread. |
| 388 static void StartWatchingAll(const base::CommandLine& command_line); | 388 static void StartWatchingAll(const base::CommandLine& command_line); |
| 389 | 389 |
| 390 // This method posts a task on WatchDogThread to RevokeAll tasks and to | 390 // This method posts a task on WatchDogThread to RevokeAll tasks and to |
| 391 // deactive thread watching of other threads and tell NotificationService to | 391 // deactive thread watching of other threads and tell NotificationService to |
| 392 // stop calling Observe. | 392 // stop calling Observe. |
| 393 // This method is accessible on UI thread. | 393 // This method is accessible on UI thread. |
| 394 static void StopWatchingAll(); | 394 static void StopWatchingAll(); |
| 395 | 395 |
| 396 // Register() stores a pointer to the given ThreadWatcher in a global map. | 396 // Register() stores a pointer to the given ThreadWatcher in a global map. |
| 397 // Returns true if it was successfully registered. | 397 static void Register(ThreadWatcher* watcher); |
| 398 static bool Register(std::unique_ptr<ThreadWatcher> watcher); | 398 |
| 399 // This method returns true if the ThreadWatcher object is registerd. |
| 400 static bool IsRegistered(const content::BrowserThread::ID thread_id); |
| 399 | 401 |
| 400 // This method returns number of responsive and unresponsive watched threads. | 402 // This method returns number of responsive and unresponsive watched threads. |
| 401 static void GetStatusOfThreads(uint32_t* responding_thread_count, | 403 static void GetStatusOfThreads(uint32_t* responding_thread_count, |
| 402 uint32_t* unresponding_thread_count); | 404 uint32_t* unresponding_thread_count); |
| 403 | 405 |
| 404 // This will ensure that the watching is actively taking place, and awaken | 406 // This will ensure that the watching is actively taking place, and awaken |
| 405 // all thread watchers that are registered. | 407 // all thread watchers that are registered. |
| 406 static void WakeUpAll(); | 408 static void WakeUpAll(); |
| 407 | 409 |
| 408 private: | 410 private: |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 // shutdown_watchdog_ watches for hangs during shutdown. | 688 // shutdown_watchdog_ watches for hangs during shutdown. |
| 687 base::Watchdog* shutdown_watchdog_; | 689 base::Watchdog* shutdown_watchdog_; |
| 688 | 690 |
| 689 // The |thread_id_| on which this object is constructed. | 691 // The |thread_id_| on which this object is constructed. |
| 690 const base::PlatformThreadId thread_id_; | 692 const base::PlatformThreadId thread_id_; |
| 691 | 693 |
| 692 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); | 694 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); |
| 693 }; | 695 }; |
| 694 | 696 |
| 695 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ | 697 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ |
| OLD | NEW |