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 | |
105 // This method starts performing health check on the given |thread_id|. It | 107 // This method starts performing health check on the given |thread_id|. It |
106 // will create ThreadWatcher object for the given |thread_id|, |thread_name|. | 108 // will create ThreadWatcher object for the given |thread_id|, |thread_name|. |
107 // |sleep_time| is the wait time between ping messages. |unresponsive_time| is | 109 // |sleep_time| is the wait time between ping messages. |unresponsive_time| is |
108 // the wait time after ping message is sent, to check if we have received pong | 110 // the wait time after ping message is sent, to check if we have received pong |
109 // message or not. |unresponsive_threshold| is used to determine if the thread | 111 // message or not. |unresponsive_threshold| is used to determine if the thread |
110 // is responsive or not. The watched thread is considered unresponsive if it | 112 // is responsive or not. The watched thread is considered unresponsive if it |
111 // hasn't responded with a pong message for |unresponsive_threshold| number of | 113 // hasn't responded with a pong message for |unresponsive_threshold| number of |
112 // ping messages. |crash_on_hang| specifies if browser should be crashed when | 114 // ping messages. |crash_on_hang| specifies if browser should be crashed when |
113 // the watched thread is unresponsive. |live_threads_threshold| specifies the | 115 // the watched thread is unresponsive. |live_threads_threshold| specifies the |
114 // number of browser threads that are to be responsive when we want to crash | 116 // number of browser threads that are to be responsive when we want to crash |
(...skipping 22 matching lines...) Expand all Loading... | |
137 | 139 |
138 // Returns |ping_sequence_number_| (used by unit tests). | 140 // Returns |ping_sequence_number_| (used by unit tests). |
139 uint64_t ping_sequence_number() const { return ping_sequence_number_; } | 141 uint64_t ping_sequence_number() const { return ping_sequence_number_; } |
140 | 142 |
141 protected: | 143 protected: |
142 // Construct a ThreadWatcher for the given |thread_id|. |sleep_time| is the | 144 // Construct a ThreadWatcher for the given |thread_id|. |sleep_time| is the |
143 // wait time between ping messages. |unresponsive_time| is the wait time after | 145 // wait time between ping messages. |unresponsive_time| is the wait time after |
144 // ping message is sent, to check if we have received pong message or not. | 146 // ping message is sent, to check if we have received pong message or not. |
145 explicit ThreadWatcher(const WatchingParams& params); | 147 explicit ThreadWatcher(const WatchingParams& params); |
146 | 148 |
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 static void Register(ThreadWatcher* watcher); | 397 // Returns the pointer if it was successfully registered. |
Ilya Sherman
2016/09/01 20:30:25
nit: Please add ", null otherwise" to the end of t
Joshua LeVasseur
2016/09/01 21:28:22
Done.
| |
398 | 398 static ThreadWatcher* Register(std::unique_ptr<ThreadWatcher> watcher); |
399 // This method returns true if the ThreadWatcher object is registerd. | |
400 static bool IsRegistered(const content::BrowserThread::ID thread_id); | |
401 | 399 |
402 // This method returns number of responsive and unresponsive watched threads. | 400 // This method returns number of responsive and unresponsive watched threads. |
403 static void GetStatusOfThreads(uint32_t* responding_thread_count, | 401 static void GetStatusOfThreads(uint32_t* responding_thread_count, |
404 uint32_t* unresponding_thread_count); | 402 uint32_t* unresponding_thread_count); |
405 | 403 |
406 // This will ensure that the watching is actively taking place, and awaken | 404 // This will ensure that the watching is actively taking place, and awaken |
407 // all thread watchers that are registered. | 405 // all thread watchers that are registered. |
408 static void WakeUpAll(); | 406 static void WakeUpAll(); |
409 | 407 |
410 private: | 408 private: |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 // shutdown_watchdog_ watches for hangs during shutdown. | 686 // shutdown_watchdog_ watches for hangs during shutdown. |
689 base::Watchdog* shutdown_watchdog_; | 687 base::Watchdog* shutdown_watchdog_; |
690 | 688 |
691 // The |thread_id_| on which this object is constructed. | 689 // The |thread_id_| on which this object is constructed. |
692 const base::PlatformThreadId thread_id_; | 690 const base::PlatformThreadId thread_id_; |
693 | 691 |
694 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); | 692 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); |
695 }; | 693 }; |
696 | 694 |
697 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ | 695 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ |
OLD | NEW |