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" |
11 #include "base/debug/dump_without_crashing.h" | 11 #include "base/debug/dump_without_crashing.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_tokenizer.h" | 16 #include "base/strings/string_tokenizer.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/metrics/thread_watcher_report_hang.h" | 22 #include "chrome/browser/metrics/thread_watcher_report_hang.h" |
| 23 #include "chrome/common/channel_info.h" |
23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/chrome_version_info.h" | |
25 #include "chrome/common/logging_chrome.h" | 25 #include "chrome/common/logging_chrome.h" |
| 26 #include "components/version_info/version_info.h" |
26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
30 #endif | 31 #endif |
31 | 32 |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 | 34 |
34 // ThreadWatcher methods and members. | 35 // ThreadWatcher methods and members. |
35 ThreadWatcher::ThreadWatcher(const WatchingParams& params) | 36 ThreadWatcher::ThreadWatcher(const WatchingParams& params) |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // static | 443 // static |
443 void ThreadWatcherList::ParseCommandLine( | 444 void ThreadWatcherList::ParseCommandLine( |
444 const base::CommandLine& command_line, | 445 const base::CommandLine& command_line, |
445 uint32* unresponsive_threshold, | 446 uint32* unresponsive_threshold, |
446 CrashOnHangThreadMap* crash_on_hang_threads) { | 447 CrashOnHangThreadMap* crash_on_hang_threads) { |
447 // Initialize |unresponsive_threshold| to a default value. | 448 // Initialize |unresponsive_threshold| to a default value. |
448 *unresponsive_threshold = kUnresponsiveCount; | 449 *unresponsive_threshold = kUnresponsiveCount; |
449 | 450 |
450 // Increase the unresponsive_threshold on the Stable and Beta channels to | 451 // Increase the unresponsive_threshold on the Stable and Beta channels to |
451 // reduce the number of crashes due to ThreadWatcher. | 452 // reduce the number of crashes due to ThreadWatcher. |
452 version_info::Channel channel = chrome::VersionInfo::GetChannel(); | 453 version_info::Channel channel = chrome::GetChannel(); |
453 if (channel == version_info::Channel::STABLE) { | 454 if (channel == version_info::Channel::STABLE) { |
454 *unresponsive_threshold *= 4; | 455 *unresponsive_threshold *= 4; |
455 } else if (channel == version_info::Channel::BETA) { | 456 } else if (channel == version_info::Channel::BETA) { |
456 *unresponsive_threshold *= 2; | 457 *unresponsive_threshold *= 2; |
457 } | 458 } |
458 | 459 |
459 #if defined(OS_WIN) | 460 #if defined(OS_WIN) |
460 // For Windows XP (old systems), double the unresponsive_threshold to give | 461 // For Windows XP (old systems), double the unresponsive_threshold to give |
461 // the OS a chance to schedule UI/IO threads a time slice to respond with a | 462 // the OS a chance to schedule UI/IO threads a time slice to respond with a |
462 // pong message (to get around limitations with the OS). | 463 // pong message (to get around limitations with the OS). |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 if (g_thread_watcher_list_ || g_stopped_) | 536 if (g_thread_watcher_list_ || g_stopped_) |
536 return; | 537 return; |
537 | 538 |
538 ThreadWatcherList* thread_watcher_list = new ThreadWatcherList(); | 539 ThreadWatcherList* thread_watcher_list = new ThreadWatcherList(); |
539 CHECK(thread_watcher_list); | 540 CHECK(thread_watcher_list); |
540 | 541 |
541 // TODO(rtenneti): Because we don't generate crash dumps for ThreadWatcher in | 542 // TODO(rtenneti): Because we don't generate crash dumps for ThreadWatcher in |
542 // stable channel, disable ThreadWatcher in stable and unknown channels. We | 543 // stable channel, disable ThreadWatcher in stable and unknown channels. We |
543 // will also not collect histogram data in these channels until | 544 // will also not collect histogram data in these channels until |
544 // http://crbug.com/426203 is fixed. | 545 // http://crbug.com/426203 is fixed. |
545 version_info::Channel channel = chrome::VersionInfo::GetChannel(); | 546 version_info::Channel channel = chrome::GetChannel(); |
546 if (channel == version_info::Channel::STABLE || | 547 if (channel == version_info::Channel::STABLE || |
547 channel == version_info::Channel::UNKNOWN) { | 548 channel == version_info::Channel::UNKNOWN) { |
548 return; | 549 return; |
549 } | 550 } |
550 | 551 |
551 const base::TimeDelta kSleepTime = | 552 const base::TimeDelta kSleepTime = |
552 base::TimeDelta::FromSeconds(kSleepSeconds); | 553 base::TimeDelta::FromSeconds(kSleepSeconds); |
553 const base::TimeDelta kUnresponsiveTime = | 554 const base::TimeDelta kUnresponsiveTime = |
554 base::TimeDelta::FromSeconds(kUnresponsiveSeconds); | 555 base::TimeDelta::FromSeconds(kUnresponsiveSeconds); |
555 | 556 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 delete shutdown_watchdog_; | 913 delete shutdown_watchdog_; |
913 shutdown_watchdog_ = NULL; | 914 shutdown_watchdog_ = NULL; |
914 } | 915 } |
915 } | 916 } |
916 | 917 |
917 void ShutdownWatcherHelper::Arm(const base::TimeDelta& duration) { | 918 void ShutdownWatcherHelper::Arm(const base::TimeDelta& duration) { |
918 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); | 919 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); |
919 DCHECK(!shutdown_watchdog_); | 920 DCHECK(!shutdown_watchdog_); |
920 base::TimeDelta actual_duration = duration; | 921 base::TimeDelta actual_duration = duration; |
921 | 922 |
922 version_info::Channel channel = chrome::VersionInfo::GetChannel(); | 923 version_info::Channel channel = chrome::GetChannel(); |
923 if (channel == version_info::Channel::STABLE) { | 924 if (channel == version_info::Channel::STABLE) { |
924 actual_duration *= 20; | 925 actual_duration *= 20; |
925 } else if (channel == version_info::Channel::BETA || | 926 } else if (channel == version_info::Channel::BETA || |
926 channel == version_info::Channel::DEV) { | 927 channel == version_info::Channel::DEV) { |
927 actual_duration *= 10; | 928 actual_duration *= 10; |
928 } | 929 } |
929 | 930 |
930 #if defined(OS_WIN) | 931 #if defined(OS_WIN) |
931 // On Windows XP, give twice the time for shutdown. | 932 // On Windows XP, give twice the time for shutdown. |
932 if (base::win::GetVersion() <= base::win::VERSION_XP) | 933 if (base::win::GetVersion() <= base::win::VERSION_XP) |
933 actual_duration *= 2; | 934 actual_duration *= 2; |
934 #endif | 935 #endif |
935 | 936 |
936 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 937 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
937 shutdown_watchdog_->Arm(); | 938 shutdown_watchdog_->Arm(); |
938 } | 939 } |
OLD | NEW |