Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/metrics/thread_watcher.cc

Issue 9173002: Watchdog - Added a JOINABLE state to avoid StartupTimebomb (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/thread_watcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // static 557 // static
558 void ThreadWatcherList::InitializeAndStartWatching( 558 void ThreadWatcherList::InitializeAndStartWatching(
559 uint32 unresponsive_threshold, 559 uint32 unresponsive_threshold,
560 const std::set<std::string>& crash_on_hang_thread_names, 560 const std::set<std::string>& crash_on_hang_thread_names,
561 uint32 live_threads_threshold) { 561 uint32 live_threads_threshold) {
562 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); 562 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
563 563
564 ThreadWatcherList* thread_watcher_list = new ThreadWatcherList(); 564 ThreadWatcherList* thread_watcher_list = new ThreadWatcherList();
565 CHECK(thread_watcher_list); 565 CHECK(thread_watcher_list);
566 566
567 BrowserThread::PostTask(
568 BrowserThread::UI,
569 FROM_HERE,
570 base::Bind(&StartupTimeBomb::DisarmStartupTimeBomb));
571
567 const base::TimeDelta kSleepTime = 572 const base::TimeDelta kSleepTime =
568 base::TimeDelta::FromSeconds(kSleepSeconds); 573 base::TimeDelta::FromSeconds(kSleepSeconds);
569 const base::TimeDelta kUnresponsiveTime = 574 const base::TimeDelta kUnresponsiveTime =
570 base::TimeDelta::FromSeconds(kUnresponsiveSeconds); 575 base::TimeDelta::FromSeconds(kUnresponsiveSeconds);
571 576
572 StartWatching(BrowserThread::UI, "UI", kSleepTime, kUnresponsiveTime, 577 StartWatching(BrowserThread::UI, "UI", kSleepTime, kUnresponsiveTime,
573 unresponsive_threshold, crash_on_hang_thread_names, 578 unresponsive_threshold, crash_on_hang_thread_names,
574 live_threads_threshold); 579 live_threads_threshold);
575 StartWatching(BrowserThread::IO, "IO", kSleepTime, kUnresponsiveTime, 580 StartWatching(BrowserThread::IO, "IO", kSleepTime, kUnresponsiveTime,
576 unresponsive_threshold, crash_on_hang_thread_names, 581 unresponsive_threshold, crash_on_hang_thread_names,
577 live_threads_threshold); 582 live_threads_threshold);
578 StartWatching(BrowserThread::DB, "DB", kSleepTime, kUnresponsiveTime, 583 StartWatching(BrowserThread::DB, "DB", kSleepTime, kUnresponsiveTime,
579 unresponsive_threshold, crash_on_hang_thread_names, 584 unresponsive_threshold, crash_on_hang_thread_names,
580 live_threads_threshold); 585 live_threads_threshold);
581 StartWatching(BrowserThread::FILE, "FILE", kSleepTime, kUnresponsiveTime, 586 StartWatching(BrowserThread::FILE, "FILE", kSleepTime, kUnresponsiveTime,
582 unresponsive_threshold, crash_on_hang_thread_names, 587 unresponsive_threshold, crash_on_hang_thread_names,
583 live_threads_threshold); 588 live_threads_threshold);
584 StartWatching(BrowserThread::FILE_USER_BLOCKING, "FILE_USER_BLOCKING", 589 StartWatching(BrowserThread::FILE_USER_BLOCKING, "FILE_USER_BLOCKING",
585 kSleepTime, kUnresponsiveTime, 590 kSleepTime, kUnresponsiveTime,
586 unresponsive_threshold, crash_on_hang_thread_names, 591 unresponsive_threshold, crash_on_hang_thread_names,
587 live_threads_threshold); 592 live_threads_threshold);
588 StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, kUnresponsiveTime, 593 StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, kUnresponsiveTime,
589 unresponsive_threshold, crash_on_hang_thread_names, 594 unresponsive_threshold, crash_on_hang_thread_names,
590 live_threads_threshold); 595 live_threads_threshold);
591
592 BrowserThread::PostTask(
593 BrowserThread::UI,
594 FROM_HERE,
595 base::Bind(&StartupTimeBomb::DisarmStartupTimeBomb));
596 } 596 }
597 597
598 // static 598 // static
599 void ThreadWatcherList::StartWatching( 599 void ThreadWatcherList::StartWatching(
600 const BrowserThread::ID& thread_id, 600 const BrowserThread::ID& thread_id,
601 const std::string& thread_name, 601 const std::string& thread_name,
602 const base::TimeDelta& sleep_time, 602 const base::TimeDelta& sleep_time,
603 const base::TimeDelta& unresponsive_time, 603 const base::TimeDelta& unresponsive_time,
604 uint32 unresponsive_threshold, 604 uint32 unresponsive_threshold,
605 const std::set<std::string>& crash_on_hang_thread_names, 605 const std::set<std::string>& crash_on_hang_thread_names,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 StartupTimeBomb::~StartupTimeBomb() { 837 StartupTimeBomb::~StartupTimeBomb() {
838 DCHECK(this == g_startup_timebomb_); 838 DCHECK(this == g_startup_timebomb_);
839 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); 839 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
840 if (startup_watchdog_) 840 if (startup_watchdog_)
841 Disarm(); 841 Disarm();
842 g_startup_timebomb_ = NULL; 842 g_startup_timebomb_ = NULL;
843 } 843 }
844 844
845 void StartupTimeBomb::Arm(const base::TimeDelta& duration) { 845 void StartupTimeBomb::Arm(const base::TimeDelta& duration) {
846 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); 846 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
847 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
848 DCHECK(!startup_watchdog_); 847 DCHECK(!startup_watchdog_);
849 startup_watchdog_ = new StartupWatchDogThread(duration); 848 startup_watchdog_ = new StartupWatchDogThread(duration);
850 startup_watchdog_->Arm(); 849 startup_watchdog_->Arm();
851 } 850 }
852 851
853 void StartupTimeBomb::Disarm() { 852 void StartupTimeBomb::Disarm() {
854 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); 853 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
856 if (startup_watchdog_) { 854 if (startup_watchdog_) {
857 startup_watchdog_->Disarm(); 855 startup_watchdog_->Disarm();
856 startup_watchdog_->Cleanup();
857 DeleteStartupWatchdog();
858 }
859 }
860
861 void StartupTimeBomb::DeleteStartupWatchdog() {
862 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
863 if (startup_watchdog_->IsJoinable()) {
858 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns 864 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns
859 // very fast. 865 // very fast.
860 base::ThreadRestrictions::SetIOAllowed(true); 866 base::ThreadRestrictions::SetIOAllowed(true);
861 delete startup_watchdog_; 867 delete startup_watchdog_;
862 startup_watchdog_ = NULL; 868 startup_watchdog_ = NULL;
869 return;
863 } 870 }
871 MessageLoop::current()->PostDelayedTask(
872 FROM_HERE,
873 base::Bind(&StartupTimeBomb::DeleteStartupWatchdog,
874 base::Unretained(this)),
875 base::TimeDelta::FromSeconds(10).InMilliseconds());
864 } 876 }
865 877
866 // static 878 // static
867 void StartupTimeBomb::DisarmStartupTimeBomb() { 879 void StartupTimeBomb::DisarmStartupTimeBomb() {
868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
869 if (g_startup_timebomb_) 881 if (g_startup_timebomb_)
870 g_startup_timebomb_->Disarm(); 882 g_startup_timebomb_->Disarm();
871 } 883 }
872 884
873 // ShutdownWatcherHelper methods and members. 885 // ShutdownWatcherHelper methods and members.
(...skipping 29 matching lines...) Expand all
903 915
904 #if defined(OS_WIN) 916 #if defined(OS_WIN)
905 // On Windows XP, give twice the time for shutdown. 917 // On Windows XP, give twice the time for shutdown.
906 if (base::win::GetVersion() <= base::win::VERSION_XP) 918 if (base::win::GetVersion() <= base::win::VERSION_XP)
907 actual_duration *= 2; 919 actual_duration *= 2;
908 #endif 920 #endif
909 921
910 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); 922 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration);
911 shutdown_watchdog_->Arm(); 923 shutdown_watchdog_->Arm();
912 } 924 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/thread_watcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698