OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/stack_sampling_configuration.h" | 5 #include "chrome/common/stack_sampling_configuration.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/common/channel_info.h" | 11 #include "chrome/common/channel_info.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "components/metrics/call_stack_profile_metrics_provider.h" |
13 #include "components/version_info/version_info.h" | 14 #include "components/version_info/version_info.h" |
14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 base::LazyInstance<StackSamplingConfiguration>::Leaky g_configuration = | 19 base::LazyInstance<StackSamplingConfiguration>::Leaky g_configuration = |
19 LAZY_INSTANCE_INITIALIZER; | 20 LAZY_INSTANCE_INITIALIZER; |
20 | 21 |
21 // The profiler is currently only implemented for Windows x64 and Mac x64. | 22 // The profiler is currently only implemented for Windows x64 and Mac x64. |
22 bool IsProfilerSupported() { | 23 bool IsProfilerSupported() { |
(...skipping 19 matching lines...) Expand all Loading... |
42 const base::CommandLine* command_line = | 43 const base::CommandLine* command_line = |
43 base::CommandLine::ForCurrentProcess(); | 44 base::CommandLine::ForCurrentProcess(); |
44 std::string process_type = | 45 std::string process_type = |
45 command_line->GetSwitchValueASCII(switches::kProcessType); | 46 command_line->GetSwitchValueASCII(switches::kProcessType); |
46 return process_type.empty(); | 47 return process_type.empty(); |
47 } | 48 } |
48 | 49 |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 StackSamplingConfiguration::StackSamplingConfiguration() | 52 StackSamplingConfiguration::StackSamplingConfiguration() |
52 : configuration_(GenerateConfiguration()) { | 53 : configuration_(GenerateConfiguration()), |
53 } | 54 profile_params_(metrics::CallStackProfileParams::BROWSER_PROCESS, |
| 55 metrics::CallStackProfileParams::UI_THREAD, |
| 56 metrics::CallStackProfileParams::PROCESS_STARTUP, |
| 57 metrics::CallStackProfileParams::MAY_SHUFFLE) {} |
54 | 58 |
55 base::StackSamplingProfiler::SamplingParams | 59 base::StackSamplingProfiler::SamplingParams |
56 StackSamplingConfiguration::GetSamplingParamsForCurrentProcess() const { | 60 StackSamplingConfiguration::GetSamplingParamsForCurrentProcess() const { |
57 base::StackSamplingProfiler::SamplingParams params; | 61 base::StackSamplingProfiler::SamplingParams params; |
58 params.bursts = 1; | 62 params.bursts = 1; |
59 params.initial_delay = base::TimeDelta::FromMilliseconds(0); | 63 params.initial_delay = base::TimeDelta::FromMilliseconds(0); |
60 params.sampling_interval = base::TimeDelta::FromMilliseconds(0); | 64 params.sampling_interval = base::TimeDelta::FromMilliseconds(0); |
61 params.samples_per_burst = 0; | 65 params.samples_per_burst = 0; |
62 | 66 |
63 if (IsProfilerEnabledForCurrentProcess()) { | 67 if (IsProfilerEnabledForCurrentProcess()) { |
64 const base::TimeDelta duration = base::TimeDelta::FromSeconds(30); | 68 const base::TimeDelta duration = base::TimeDelta::FromSeconds(30); |
65 params.sampling_interval = base::TimeDelta::FromMilliseconds(100); | 69 params.sampling_interval = base::TimeDelta::FromMilliseconds(100); |
66 params.samples_per_burst = duration / params.sampling_interval; | 70 params.samples_per_burst = duration / params.sampling_interval; |
67 } | 71 } |
68 | 72 |
69 return params; | 73 return params; |
70 } | 74 } |
71 | 75 |
| 76 base::StackSamplingProfiler::CompletedCallback |
| 77 StackSamplingConfiguration::GetProfilerCallbackForCurrentProcess() { |
| 78 return metrics::CallStackProfileMetricsProvider::GetProfilerCallback( |
| 79 &profile_params_); |
| 80 } |
| 81 |
72 bool StackSamplingConfiguration::IsProfilerEnabledForCurrentProcess() const { | 82 bool StackSamplingConfiguration::IsProfilerEnabledForCurrentProcess() const { |
73 if (IsBrowserProcess()) { | 83 if (IsBrowserProcess()) { |
74 switch (configuration_) { | 84 switch (configuration_) { |
75 case PROFILE_BROWSER_PROCESS: | 85 case PROFILE_BROWSER_PROCESS: |
76 case PROFILE_BROWSER_AND_GPU_PROCESS: | 86 case PROFILE_BROWSER_AND_GPU_PROCESS: |
77 #if !defined(OS_MACOSX) | 87 #if !defined(OS_MACOSX) |
78 case PROFILE_CONTROL: // The profiler is disabled for the control group | 88 case PROFILE_CONTROL: // The profiler is disabled for the control group |
79 // on Mac during ramp-up. | 89 // on Mac during ramp-up. |
80 #endif | 90 #endif |
81 return true; | 91 return true; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 {PROFILE_GPU_PROCESS, 0}, | 219 {PROFILE_GPU_PROCESS, 0}, |
210 {PROFILE_BROWSER_AND_GPU_PROCESS, 10}, | 220 {PROFILE_BROWSER_AND_GPU_PROCESS, 10}, |
211 {PROFILE_CONTROL, 10}, | 221 {PROFILE_CONTROL, 10}, |
212 {PROFILE_DISABLED, 80}}); | 222 {PROFILE_DISABLED, 80}}); |
213 #endif | 223 #endif |
214 | 224 |
215 default: | 225 default: |
216 return PROFILE_DISABLED; | 226 return PROFILE_DISABLED; |
217 } | 227 } |
218 } | 228 } |
OLD | NEW |