| 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 // static | 442 // static |
| 443 void ThreadWatcherList::ParseCommandLine( | 443 void ThreadWatcherList::ParseCommandLine( |
| 444 const base::CommandLine& command_line, | 444 const base::CommandLine& command_line, |
| 445 uint32* unresponsive_threshold, | 445 uint32* unresponsive_threshold, |
| 446 CrashOnHangThreadMap* crash_on_hang_threads) { | 446 CrashOnHangThreadMap* crash_on_hang_threads) { |
| 447 // Initialize |unresponsive_threshold| to a default value. | 447 // Initialize |unresponsive_threshold| to a default value. |
| 448 *unresponsive_threshold = kUnresponsiveCount; | 448 *unresponsive_threshold = kUnresponsiveCount; |
| 449 | 449 |
| 450 // Increase the unresponsive_threshold on the Stable and Beta channels to | 450 // Increase the unresponsive_threshold on the Stable and Beta channels to |
| 451 // reduce the number of crashes due to ThreadWatcher. | 451 // reduce the number of crashes due to ThreadWatcher. |
| 452 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 452 version_info::Channel channel = chrome::VersionInfo::GetChannel(); |
| 453 if (channel == chrome::VersionInfo::CHANNEL_STABLE) { | 453 if (channel == version_info::Channel::STABLE) { |
| 454 *unresponsive_threshold *= 4; | 454 *unresponsive_threshold *= 4; |
| 455 } else if (channel == chrome::VersionInfo::CHANNEL_BETA) { | 455 } else if (channel == version_info::Channel::BETA) { |
| 456 *unresponsive_threshold *= 2; | 456 *unresponsive_threshold *= 2; |
| 457 } | 457 } |
| 458 | 458 |
| 459 #if defined(OS_WIN) | 459 #if defined(OS_WIN) |
| 460 // For Windows XP (old systems), double the unresponsive_threshold to give | 460 // 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 | 461 // 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). | 462 // pong message (to get around limitations with the OS). |
| 463 if (base::win::GetVersion() <= base::win::VERSION_XP) | 463 if (base::win::GetVersion() <= base::win::VERSION_XP) |
| 464 *unresponsive_threshold *= 2; | 464 *unresponsive_threshold *= 2; |
| 465 #endif | 465 #endif |
| 466 | 466 |
| 467 uint32 crash_seconds = *unresponsive_threshold * kUnresponsiveSeconds; | 467 uint32 crash_seconds = *unresponsive_threshold * kUnresponsiveSeconds; |
| 468 std::string crash_on_hang_thread_names; | 468 std::string crash_on_hang_thread_names; |
| 469 if (command_line.HasSwitch(switches::kCrashOnHangThreads)) { | 469 if (command_line.HasSwitch(switches::kCrashOnHangThreads)) { |
| 470 crash_on_hang_thread_names = | 470 crash_on_hang_thread_names = |
| 471 command_line.GetSwitchValueASCII(switches::kCrashOnHangThreads); | 471 command_line.GetSwitchValueASCII(switches::kCrashOnHangThreads); |
| 472 } else if (channel != chrome::VersionInfo::CHANNEL_STABLE) { | 472 } else if (channel != version_info::Channel::STABLE) { |
| 473 // Default to crashing the browser if UI or IO or FILE threads are not | 473 // Default to crashing the browser if UI or IO or FILE threads are not |
| 474 // responsive except in stable channel. | 474 // responsive except in stable channel. |
| 475 crash_on_hang_thread_names = base::StringPrintf( | 475 crash_on_hang_thread_names = base::StringPrintf( |
| 476 "UI:%d:%d,IO:%d:%d,FILE:%d:%d", | 476 "UI:%d:%d,IO:%d:%d,FILE:%d:%d", |
| 477 kLiveThreadsThreshold, crash_seconds, | 477 kLiveThreadsThreshold, crash_seconds, |
| 478 kLiveThreadsThreshold, crash_seconds, | 478 kLiveThreadsThreshold, crash_seconds, |
| 479 kLiveThreadsThreshold, crash_seconds * 5); | 479 kLiveThreadsThreshold, crash_seconds * 5); |
| 480 } | 480 } |
| 481 | 481 |
| 482 ParseCommandLineCrashOnHangThreads(crash_on_hang_thread_names, | 482 ParseCommandLineCrashOnHangThreads(crash_on_hang_thread_names, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 if (g_thread_watcher_list_ || g_stopped_) | 535 if (g_thread_watcher_list_ || g_stopped_) |
| 536 return; | 536 return; |
| 537 | 537 |
| 538 ThreadWatcherList* thread_watcher_list = new ThreadWatcherList(); | 538 ThreadWatcherList* thread_watcher_list = new ThreadWatcherList(); |
| 539 CHECK(thread_watcher_list); | 539 CHECK(thread_watcher_list); |
| 540 | 540 |
| 541 // TODO(rtenneti): Because we don't generate crash dumps for ThreadWatcher in | 541 // TODO(rtenneti): Because we don't generate crash dumps for ThreadWatcher in |
| 542 // stable channel, disable ThreadWatcher in stable and unknown channels. We | 542 // stable channel, disable ThreadWatcher in stable and unknown channels. We |
| 543 // will also not collect histogram data in these channels until | 543 // will also not collect histogram data in these channels until |
| 544 // http://crbug.com/426203 is fixed. | 544 // http://crbug.com/426203 is fixed. |
| 545 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 545 version_info::Channel channel = chrome::VersionInfo::GetChannel(); |
| 546 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 546 if (channel == version_info::Channel::STABLE || |
| 547 channel == chrome::VersionInfo::CHANNEL_UNKNOWN) { | 547 channel == version_info::Channel::UNKNOWN) { |
| 548 return; | 548 return; |
| 549 } | 549 } |
| 550 | 550 |
| 551 const base::TimeDelta kSleepTime = | 551 const base::TimeDelta kSleepTime = |
| 552 base::TimeDelta::FromSeconds(kSleepSeconds); | 552 base::TimeDelta::FromSeconds(kSleepSeconds); |
| 553 const base::TimeDelta kUnresponsiveTime = | 553 const base::TimeDelta kUnresponsiveTime = |
| 554 base::TimeDelta::FromSeconds(kUnresponsiveSeconds); | 554 base::TimeDelta::FromSeconds(kUnresponsiveSeconds); |
| 555 | 555 |
| 556 StartWatching(BrowserThread::UI, "UI", kSleepTime, kUnresponsiveTime, | 556 StartWatching(BrowserThread::UI, "UI", kSleepTime, kUnresponsiveTime, |
| 557 unresponsive_threshold, crash_on_hang_threads); | 557 unresponsive_threshold, crash_on_hang_threads); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 delete shutdown_watchdog_; | 912 delete shutdown_watchdog_; |
| 913 shutdown_watchdog_ = NULL; | 913 shutdown_watchdog_ = NULL; |
| 914 } | 914 } |
| 915 } | 915 } |
| 916 | 916 |
| 917 void ShutdownWatcherHelper::Arm(const base::TimeDelta& duration) { | 917 void ShutdownWatcherHelper::Arm(const base::TimeDelta& duration) { |
| 918 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); | 918 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); |
| 919 DCHECK(!shutdown_watchdog_); | 919 DCHECK(!shutdown_watchdog_); |
| 920 base::TimeDelta actual_duration = duration; | 920 base::TimeDelta actual_duration = duration; |
| 921 | 921 |
| 922 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 922 version_info::Channel channel = chrome::VersionInfo::GetChannel(); |
| 923 if (channel == chrome::VersionInfo::CHANNEL_STABLE) { | 923 if (channel == version_info::Channel::STABLE) { |
| 924 actual_duration *= 20; | 924 actual_duration *= 20; |
| 925 } else if (channel == chrome::VersionInfo::CHANNEL_BETA || | 925 } else if (channel == version_info::Channel::BETA || |
| 926 channel == chrome::VersionInfo::CHANNEL_DEV) { | 926 channel == version_info::Channel::DEV) { |
| 927 actual_duration *= 10; | 927 actual_duration *= 10; |
| 928 } | 928 } |
| 929 | 929 |
| 930 #if defined(OS_WIN) | 930 #if defined(OS_WIN) |
| 931 // On Windows XP, give twice the time for shutdown. | 931 // On Windows XP, give twice the time for shutdown. |
| 932 if (base::win::GetVersion() <= base::win::VERSION_XP) | 932 if (base::win::GetVersion() <= base::win::VERSION_XP) |
| 933 actual_duration *= 2; | 933 actual_duration *= 2; |
| 934 #endif | 934 #endif |
| 935 | 935 |
| 936 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 936 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
| 937 shutdown_watchdog_->Arm(); | 937 shutdown_watchdog_->Arm(); |
| 938 } | 938 } |
| OLD | NEW |