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 17 matching lines...) Expand all Loading... |
28 #include "components/metrics/call_stack_profile_metrics_provider.h" | 28 #include "components/metrics/call_stack_profile_metrics_provider.h" |
29 #include "components/version_info/version_info.h" | 29 #include "components/version_info/version_info.h" |
30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 | 31 |
32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
33 #include "base/win/windows_version.h" | 33 #include "base/win/windows_version.h" |
34 #endif | 34 #endif |
35 | 35 |
36 using content::BrowserThread; | 36 using content::BrowserThread; |
37 | 37 |
| 38 namespace { |
| 39 |
| 40 base::StackSamplingProfiler::SamplingParams GetJankTimeBombSamplingParams() { |
| 41 base::StackSamplingProfiler::SamplingParams params; |
| 42 params.initial_delay = base::TimeDelta::FromMilliseconds(0); |
| 43 params.bursts = 1; |
| 44 // 5 seconds at 10Hz. |
| 45 params.samples_per_burst = 50; |
| 46 params.sampling_interval = base::TimeDelta::FromMilliseconds(100); |
| 47 return params; |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
38 // ThreadWatcher methods and members. | 52 // ThreadWatcher methods and members. |
39 ThreadWatcher::ThreadWatcher(const WatchingParams& params) | 53 ThreadWatcher::ThreadWatcher(const WatchingParams& params) |
40 : thread_id_(params.thread_id), | 54 : thread_id_(params.thread_id), |
41 thread_name_(params.thread_name), | 55 thread_name_(params.thread_name), |
42 watched_runner_(BrowserThread::GetTaskRunnerForThread(params.thread_id)), | 56 watched_runner_(BrowserThread::GetTaskRunnerForThread(params.thread_id)), |
43 sleep_time_(params.sleep_time), | 57 sleep_time_(params.sleep_time), |
44 unresponsive_time_(params.unresponsive_time), | 58 unresponsive_time_(params.unresponsive_time), |
45 ping_time_(base::TimeTicks::Now()), | 59 ping_time_(base::TimeTicks::Now()), |
46 pong_time_(ping_time_), | 60 pong_time_(ping_time_), |
47 ping_sequence_number_(0), | 61 ping_sequence_number_(0), |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 base::TimeDelta::FromSeconds(10)); | 922 base::TimeDelta::FromSeconds(10)); |
909 } | 923 } |
910 | 924 |
911 // static | 925 // static |
912 void StartupTimeBomb::DisarmStartupTimeBomb() { | 926 void StartupTimeBomb::DisarmStartupTimeBomb() { |
913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
914 if (g_startup_timebomb_) | 928 if (g_startup_timebomb_) |
915 g_startup_timebomb_->Disarm(); | 929 g_startup_timebomb_->Disarm(); |
916 } | 930 } |
917 | 931 |
918 base::StackSamplingProfiler::SamplingParams GetJankTimeBombSamplingParams() { | |
919 base::StackSamplingProfiler::SamplingParams params; | |
920 params.initial_delay = base::TimeDelta::FromMilliseconds(0); | |
921 params.bursts = 1; | |
922 // 5 seconds at 10Hz. | |
923 params.samples_per_burst = 50; | |
924 params.sampling_interval = base::TimeDelta::FromMilliseconds(100); | |
925 return params; | |
926 } | |
927 | |
928 // JankTimeBomb methods and members. | 932 // JankTimeBomb methods and members. |
929 // | 933 // |
930 JankTimeBomb::JankTimeBomb(base::TimeDelta duration) | 934 JankTimeBomb::JankTimeBomb(base::TimeDelta duration, |
931 : weak_ptr_factory_(this) { | 935 metrics::CallStackProfileParams::Thread thread) |
| 936 : thread_(thread), weak_ptr_factory_(this) { |
932 if (IsEnabled()) { | 937 if (IsEnabled()) { |
933 WatchDogThread::PostDelayedTask( | 938 WatchDogThread::PostDelayedTask( |
934 FROM_HERE, | 939 FROM_HERE, |
935 base::Bind(&JankTimeBomb::Alarm, | 940 base::Bind(&JankTimeBomb::Alarm, |
936 weak_ptr_factory_.GetWeakPtr(), | 941 weak_ptr_factory_.GetWeakPtr(), |
937 base::PlatformThread::CurrentId()), | 942 base::PlatformThread::CurrentId()), |
938 duration); | 943 duration); |
939 } | 944 } |
940 } | 945 } |
941 | 946 |
942 JankTimeBomb::~JankTimeBomb() { | 947 JankTimeBomb::~JankTimeBomb() { |
943 } | 948 } |
944 | 949 |
945 bool JankTimeBomb::IsEnabled() const { | 950 bool JankTimeBomb::IsEnabled() const { |
946 version_info::Channel channel = chrome::GetChannel(); | 951 version_info::Channel channel = chrome::GetChannel(); |
947 return channel == version_info::Channel::UNKNOWN || | 952 return channel == version_info::Channel::UNKNOWN || |
948 channel == version_info::Channel::CANARY || | 953 channel == version_info::Channel::CANARY || |
949 channel == version_info::Channel::DEV; | 954 channel == version_info::Channel::DEV; |
950 } | 955 } |
951 | 956 |
952 void JankTimeBomb::Alarm(base::PlatformThreadId thread_id) { | 957 void JankTimeBomb::Alarm(base::PlatformThreadId thread_id) { |
953 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 958 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
954 sampling_profiler_.reset(new base::StackSamplingProfiler( | 959 sampling_profiler_.reset(new base::StackSamplingProfiler( |
955 thread_id, | 960 thread_id, |
956 GetJankTimeBombSamplingParams(), | 961 GetJankTimeBombSamplingParams(), |
957 metrics::CallStackProfileMetricsProvider::GetProfilerCallback( | 962 metrics::CallStackProfileMetricsProvider::GetProfilerCallback( |
958 metrics::CallStackProfileParams( | 963 metrics::CallStackProfileParams( |
| 964 metrics::CallStackProfileParams::BROWSER_PROCESS, |
| 965 thread_, |
959 metrics::CallStackProfileParams::JANKY_TASK, | 966 metrics::CallStackProfileParams::JANKY_TASK, |
960 metrics::CallStackProfileParams::PRESERVE_ORDER)))); | 967 metrics::CallStackProfileParams::PRESERVE_ORDER)))); |
961 // Use synchronous profiler. It will automatically stop collection when | 968 // Use synchronous profiler. It will automatically stop collection when |
962 // destroyed. | 969 // destroyed. |
963 sampling_profiler_->Start(); | 970 sampling_profiler_->Start(); |
964 } | 971 } |
965 | 972 |
966 // ShutdownWatcherHelper methods and members. | 973 // ShutdownWatcherHelper methods and members. |
967 // | 974 // |
968 // ShutdownWatcherHelper is a wrapper class for detecting hangs during | 975 // ShutdownWatcherHelper is a wrapper class for detecting hangs during |
(...skipping 30 matching lines...) Expand all Loading... |
999 | 1006 |
1000 #if defined(OS_WIN) | 1007 #if defined(OS_WIN) |
1001 // On Windows XP, give twice the time for shutdown. | 1008 // On Windows XP, give twice the time for shutdown. |
1002 if (base::win::GetVersion() <= base::win::VERSION_XP) | 1009 if (base::win::GetVersion() <= base::win::VERSION_XP) |
1003 actual_duration *= 2; | 1010 actual_duration *= 2; |
1004 #endif | 1011 #endif |
1005 | 1012 |
1006 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 1013 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
1007 shutdown_watchdog_->Arm(); | 1014 shutdown_watchdog_->Arm(); |
1008 } | 1015 } |
OLD | NEW |