OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 StartWatching(BrowserThread::FILE, "FILE", kSleepTime, kUnresponsiveTime, | 583 StartWatching(BrowserThread::FILE, "FILE", kSleepTime, kUnresponsiveTime, |
584 unresponsive_threshold, crash_on_hang_thread_names, | 584 unresponsive_threshold, crash_on_hang_thread_names, |
585 live_threads_threshold); | 585 live_threads_threshold); |
586 StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, kUnresponsiveTime, | 586 StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, kUnresponsiveTime, |
587 unresponsive_threshold, crash_on_hang_thread_names, | 587 unresponsive_threshold, crash_on_hang_thread_names, |
588 live_threads_threshold); | 588 live_threads_threshold); |
589 | 589 |
590 BrowserThread::PostTask( | 590 BrowserThread::PostTask( |
591 BrowserThread::UI, | 591 BrowserThread::UI, |
592 FROM_HERE, | 592 FROM_HERE, |
593 base::Bind(StartupTimeBomb::Disarm)); | 593 base::Bind(&StartupTimeBomb::DisarmStartupTimeBomb)); |
594 } | 594 } |
595 | 595 |
596 // static | 596 // static |
597 void ThreadWatcherList::StartWatching( | 597 void ThreadWatcherList::StartWatching( |
598 const BrowserThread::ID& thread_id, | 598 const BrowserThread::ID& thread_id, |
599 const std::string& thread_name, | 599 const std::string& thread_name, |
600 const base::TimeDelta& sleep_time, | 600 const base::TimeDelta& sleep_time, |
601 const base::TimeDelta& unresponsive_time, | 601 const base::TimeDelta& unresponsive_time, |
602 uint32 unresponsive_threshold, | 602 uint32 unresponsive_threshold, |
603 const std::set<std::string>& crash_on_hang_thread_names, | 603 const std::set<std::string>& crash_on_hang_thread_names, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 CHECK(false); | 821 CHECK(false); |
822 } | 822 } |
823 | 823 |
824 DISALLOW_COPY_AND_ASSIGN(ShutdownWatchDogThread); | 824 DISALLOW_COPY_AND_ASSIGN(ShutdownWatchDogThread); |
825 }; | 825 }; |
826 } // namespace | 826 } // namespace |
827 | 827 |
828 // StartupTimeBomb methods and members. | 828 // StartupTimeBomb methods and members. |
829 // | 829 // |
830 // static | 830 // static |
831 base::Watchdog* StartupTimeBomb::startup_watchdog_ = NULL; | 831 StartupTimeBomb* StartupTimeBomb::g_startup_timebomb_ = NULL; |
832 | 832 |
833 // static | 833 StartupTimeBomb::StartupTimeBomb() |
| 834 : startup_watchdog_(NULL), |
| 835 thread_id_(base::PlatformThread::CurrentId()) { |
| 836 CHECK(!g_startup_timebomb_); |
| 837 g_startup_timebomb_ = this; |
| 838 } |
| 839 |
| 840 StartupTimeBomb::~StartupTimeBomb() { |
| 841 DCHECK(this == g_startup_timebomb_); |
| 842 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); |
| 843 if (startup_watchdog_) |
| 844 Disarm(); |
| 845 g_startup_timebomb_ = NULL; |
| 846 } |
| 847 |
834 void StartupTimeBomb::Arm(const base::TimeDelta& duration) { | 848 void StartupTimeBomb::Arm(const base::TimeDelta& duration) { |
| 849 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); |
835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
836 DCHECK(!startup_watchdog_); | 851 DCHECK(!startup_watchdog_); |
837 startup_watchdog_ = new StartupWatchDogThread(duration); | 852 startup_watchdog_ = new StartupWatchDogThread(duration); |
838 startup_watchdog_->Arm(); | 853 startup_watchdog_->Arm(); |
839 } | 854 } |
840 | 855 |
841 // static | |
842 void StartupTimeBomb::Disarm() { | 856 void StartupTimeBomb::Disarm() { |
| 857 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); |
843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 858 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
844 if (startup_watchdog_) { | 859 if (startup_watchdog_) { |
845 startup_watchdog_->Disarm(); | 860 startup_watchdog_->Disarm(); |
846 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns | 861 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns |
847 // very fast. | 862 // very fast. |
848 base::ThreadRestrictions::SetIOAllowed(true); | 863 base::ThreadRestrictions::SetIOAllowed(true); |
849 delete startup_watchdog_; | 864 delete startup_watchdog_; |
850 startup_watchdog_ = NULL; | 865 startup_watchdog_ = NULL; |
851 } | 866 } |
852 } | 867 } |
853 | 868 |
| 869 // static |
| 870 void StartupTimeBomb::DisarmStartupTimeBomb() { |
| 871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 872 if (g_startup_timebomb_) |
| 873 g_startup_timebomb_->Disarm(); |
| 874 } |
| 875 |
854 // ShutdownWatcherHelper methods and members. | 876 // ShutdownWatcherHelper methods and members. |
855 // | 877 // |
856 // ShutdownWatcherHelper is a wrapper class for detecting hangs during | 878 // ShutdownWatcherHelper is a wrapper class for detecting hangs during |
857 // shutdown. | 879 // shutdown. |
858 ShutdownWatcherHelper::ShutdownWatcherHelper() : shutdown_watchdog_(NULL) { | 880 ShutdownWatcherHelper::ShutdownWatcherHelper() |
| 881 : shutdown_watchdog_(NULL), |
| 882 thread_id_(base::PlatformThread::CurrentId()) { |
859 } | 883 } |
860 | 884 |
861 ShutdownWatcherHelper::~ShutdownWatcherHelper() { | 885 ShutdownWatcherHelper::~ShutdownWatcherHelper() { |
| 886 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); |
862 if (shutdown_watchdog_) { | 887 if (shutdown_watchdog_) { |
863 shutdown_watchdog_->Disarm(); | 888 shutdown_watchdog_->Disarm(); |
864 delete shutdown_watchdog_; | 889 delete shutdown_watchdog_; |
865 shutdown_watchdog_ = NULL; | 890 shutdown_watchdog_ = NULL; |
866 } | 891 } |
867 } | 892 } |
868 | 893 |
869 void ShutdownWatcherHelper::Arm(const base::TimeDelta& duration) { | 894 void ShutdownWatcherHelper::Arm(const base::TimeDelta& duration) { |
| 895 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); |
870 DCHECK(!shutdown_watchdog_); | 896 DCHECK(!shutdown_watchdog_); |
871 base::TimeDelta actual_duration = duration; | 897 base::TimeDelta actual_duration = duration; |
872 | 898 |
873 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 899 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
874 if (channel == chrome::VersionInfo::CHANNEL_STABLE) { | 900 if (channel == chrome::VersionInfo::CHANNEL_STABLE) { |
875 actual_duration *= 50; | 901 actual_duration *= 50; |
876 } else if (channel == chrome::VersionInfo::CHANNEL_BETA || | 902 } else if (channel == chrome::VersionInfo::CHANNEL_BETA || |
877 channel == chrome::VersionInfo::CHANNEL_DEV) { | 903 channel == chrome::VersionInfo::CHANNEL_DEV) { |
878 actual_duration *= 25; | 904 actual_duration *= 25; |
879 } | 905 } |
880 | 906 |
881 #if defined(OS_WIN) | 907 #if defined(OS_WIN) |
882 // On Windows XP, give twice the time for shutdown. | 908 // On Windows XP, give twice the time for shutdown. |
883 if (base::win::GetVersion() <= base::win::VERSION_XP) | 909 if (base::win::GetVersion() <= base::win::VERSION_XP) |
884 actual_duration *= 2; | 910 actual_duration *= 2; |
885 #endif | 911 #endif |
886 | 912 |
887 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 913 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
888 shutdown_watchdog_->Arm(); | 914 shutdown_watchdog_->Arm(); |
889 } | 915 } |
OLD | NEW |