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() : startup_watchdog_(NULL) { |
834 CHECK(!g_startup_timebomb_); | |
835 g_startup_timebomb_ = this; | |
836 } | |
837 | |
838 StartupTimeBomb::~StartupTimeBomb() { | |
839 DCHECK(this == g_startup_timebomb_); | |
840 Disarm(); | |
841 g_startup_timebomb_ = NULL; | |
842 } | |
843 | |
834 void StartupTimeBomb::Arm(const base::TimeDelta& duration) { | 844 void StartupTimeBomb::Arm(const base::TimeDelta& duration) { |
835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
836 DCHECK(!startup_watchdog_); | 846 DCHECK(!startup_watchdog_); |
837 startup_watchdog_ = new StartupWatchDogThread(duration); | 847 startup_watchdog_ = new StartupWatchDogThread(duration); |
838 startup_watchdog_->Arm(); | 848 startup_watchdog_->Arm(); |
839 } | 849 } |
840 | 850 |
841 // static | |
842 void StartupTimeBomb::Disarm() { | 851 void StartupTimeBomb::Disarm() { |
843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 852 // This could be disarm'ed during shutdown when we are not on UI thread. |
jar (doing other things)
2011/11/30 17:18:39
I think this will be racy if called from other tha
ramant (doing other things)
2011/11/30 22:08:40
Added DCHECK's for thread_id for StartupTimeBomb a
| |
844 if (startup_watchdog_) { | 853 if (startup_watchdog_) { |
845 startup_watchdog_->Disarm(); | 854 startup_watchdog_->Disarm(); |
846 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns | 855 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns |
847 // very fast. | 856 // very fast. |
848 base::ThreadRestrictions::SetIOAllowed(true); | 857 base::ThreadRestrictions::SetIOAllowed(true); |
849 delete startup_watchdog_; | 858 delete startup_watchdog_; |
850 startup_watchdog_ = NULL; | 859 startup_watchdog_ = NULL; |
851 } | 860 } |
852 } | 861 } |
853 | 862 |
863 // static | |
864 void StartupTimeBomb::DisarmStartupTimeBomb() { | |
865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
866 if (g_startup_timebomb_) | |
867 g_startup_timebomb_->Disarm(); | |
868 } | |
869 | |
854 // ShutdownWatcherHelper methods and members. | 870 // ShutdownWatcherHelper methods and members. |
855 // | 871 // |
856 // ShutdownWatcherHelper is a wrapper class for detecting hangs during | 872 // ShutdownWatcherHelper is a wrapper class for detecting hangs during |
857 // shutdown. | 873 // shutdown. |
858 ShutdownWatcherHelper::ShutdownWatcherHelper() : shutdown_watchdog_(NULL) { | 874 ShutdownWatcherHelper::ShutdownWatcherHelper() : shutdown_watchdog_(NULL) { |
859 } | 875 } |
860 | 876 |
861 ShutdownWatcherHelper::~ShutdownWatcherHelper() { | 877 ShutdownWatcherHelper::~ShutdownWatcherHelper() { |
862 if (shutdown_watchdog_) { | 878 if (shutdown_watchdog_) { |
863 shutdown_watchdog_->Disarm(); | 879 shutdown_watchdog_->Disarm(); |
(...skipping 16 matching lines...) Expand all Loading... | |
880 | 896 |
881 #if defined(OS_WIN) | 897 #if defined(OS_WIN) |
882 // On Windows XP, give twice the time for shutdown. | 898 // On Windows XP, give twice the time for shutdown. |
883 if (base::win::GetVersion() <= base::win::VERSION_XP) | 899 if (base::win::GetVersion() <= base::win::VERSION_XP) |
884 actual_duration *= 2; | 900 actual_duration *= 2; |
885 #endif | 901 #endif |
886 | 902 |
887 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 903 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
888 shutdown_watchdog_->Arm(); | 904 shutdown_watchdog_->Arm(); |
889 } | 905 } |
OLD | NEW |