Chromium Code Reviews| Index: chrome/common/stack_sampling_configuration.cc |
| diff --git a/chrome/common/stack_sampling_configuration.cc b/chrome/common/stack_sampling_configuration.cc |
| index 02e5b01156ca50f982e1faae4b721b006bd53b68..10c97df773406b88a49ce26f08d36e8d426c5af2 100644 |
| --- a/chrome/common/stack_sampling_configuration.cc |
| +++ b/chrome/common/stack_sampling_configuration.cc |
| @@ -4,12 +4,19 @@ |
| #include "chrome/common/stack_sampling_configuration.h" |
| +#include "base/command_line.h" |
| +#include "base/lazy_instance.h" |
| #include "base/rand_util.h" |
| #include "chrome/common/channel_info.h" |
| +#include "chrome/common/chrome_switches.h" |
| #include "components/version_info/version_info.h" |
| +#include "content/public/common/content_switches.h" |
| namespace { |
| +static base::LazyInstance<StackSamplingConfiguration>::Leaky g_configuration = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| // The profiler is currently only implemented for Windows x64, and only runs on |
| // trunk, canary, and dev. |
| bool IsProfilerSupported() { |
| @@ -23,6 +30,14 @@ bool IsProfilerSupported() { |
| #endif |
| } |
| +bool ExecutingInBrowserProcess() { |
|
Ilya Sherman
2016/09/28 01:02:15
nit: I'd prepend an "Is" to this name. And, pleas
Mike Wittman
2016/09/28 19:34:26
Changed to IsBrowserProcess. IsExecutingInBrowserP
|
| + const base::CommandLine* command_line = |
| + base::CommandLine::ForCurrentProcess(); |
| + std::string process_type = |
| + command_line->GetSwitchValueASCII(switches::kProcessType); |
| + return process_type.empty(); |
| +} |
| + |
| } // namespace |
| StackSamplingConfiguration::StackSamplingConfiguration() |
| @@ -30,53 +45,40 @@ StackSamplingConfiguration::StackSamplingConfiguration() |
| } |
| base::StackSamplingProfiler::SamplingParams |
| -StackSamplingConfiguration::GetSamplingParams() const { |
| +StackSamplingConfiguration::GetSamplingParamsForCurrentProcess() const { |
| base::StackSamplingProfiler::SamplingParams params; |
| params.bursts = 1; |
| - const base::TimeDelta duration = base::TimeDelta::FromSeconds(30); |
| - |
| - switch (configuration_) { |
| - case PROFILE_DISABLED: |
| - case PROFILE_CONTROL: |
| - params.initial_delay = base::TimeDelta::FromMilliseconds(0); |
| - params.sampling_interval = base::TimeDelta::FromMilliseconds(0); |
| - params.samples_per_burst = 0; |
| - break; |
| - |
| - case PROFILE_NO_SAMPLES: |
| - params.initial_delay = duration; |
| - params.sampling_interval = base::TimeDelta::FromMilliseconds(0); |
| - params.samples_per_burst = 0; |
| - break; |
| - |
| - case PROFILE_5HZ: |
| - params.initial_delay = base::TimeDelta::FromMilliseconds(0); |
| - params.sampling_interval = base::TimeDelta::FromMilliseconds(200); |
| - params.samples_per_burst = duration / params.sampling_interval; |
| - break; |
| - |
| - case PROFILE_10HZ: |
| - params.initial_delay = base::TimeDelta::FromMilliseconds(0); |
| - params.sampling_interval = base::TimeDelta::FromMilliseconds(100); |
| - params.samples_per_burst = duration / params.sampling_interval; |
| - break; |
| - |
| - case PROFILE_100HZ: |
| - params.initial_delay = base::TimeDelta::FromMilliseconds(0); |
| - params.sampling_interval = base::TimeDelta::FromMilliseconds(10); |
| - params.samples_per_burst = duration / params.sampling_interval; |
| - break; |
| + params.initial_delay = base::TimeDelta::FromMilliseconds(0); |
| + params.sampling_interval = base::TimeDelta::FromMilliseconds(0); |
| + params.samples_per_burst = 0; |
| + |
| + if (IsProfilerEnabledForCurrentProcess()) { |
| + const base::TimeDelta duration = base::TimeDelta::FromSeconds(30); |
| + params.sampling_interval = base::TimeDelta::FromMilliseconds(100); |
| + params.samples_per_burst = duration / params.sampling_interval; |
| } |
| + |
| return params; |
| } |
| -bool StackSamplingConfiguration::IsProfilerEnabled() const { |
| - return (configuration_ != PROFILE_DISABLED && |
| - configuration_ != PROFILE_CONTROL); |
| +bool StackSamplingConfiguration::IsProfilerEnabledForCurrentProcess() const { |
| + if (ExecutingInBrowserProcess()) { |
| + return configuration_ == PROFILE_BROWSER_PROCESS || |
| + configuration_ == PROFILE_BROWSER_AND_GPU_PROCESS; |
| + } |
| + |
| + DCHECK(configuration_ == PROFILE_FROM_COMMAND_LINE); |
|
Ilya Sherman
2016/09/28 01:02:15
nit: DCHECK_EQ
Mike Wittman
2016/09/28 19:34:26
Done.
|
| + // This is a child process. The kStartStackProfiler switch passed by the |
| + // browser process determines whether the profiler is enabled for the process. |
| + const base::CommandLine* command_line = |
| + base::CommandLine::ForCurrentProcess(); |
| + return command_line->HasSwitch(switches::kStartStackProfiler); |
| } |
| void StackSamplingConfiguration::RegisterSyntheticFieldTrial( |
| const RegisterSyntheticFieldTrialFunction& register_field_trial) const { |
| + DCHECK(ExecutingInBrowserProcess()); |
| + |
| if (!IsProfilerSupported()) |
| return; |
| @@ -90,36 +92,56 @@ void StackSamplingConfiguration::RegisterSyntheticFieldTrial( |
| group = "Control"; |
| break; |
| - case PROFILE_NO_SAMPLES: |
| - group = "NoSamples"; |
| + case PROFILE_BROWSER_PROCESS: |
| + group = "BrowserProcess"; |
| break; |
| - case PROFILE_5HZ: |
| - group = "5Hz"; |
| + case PROFILE_GPU_PROCESS: |
| + group = "GpuProcess"; |
| break; |
| - case PROFILE_10HZ: |
| - group = "10Hz"; |
| + case PROFILE_BROWSER_AND_GPU_PROCESS: |
| + group = "BrowserAndGpuProcess"; |
| break; |
| - case PROFILE_100HZ: |
| - group = "100Hz"; |
| + case PROFILE_FROM_COMMAND_LINE: |
| + NOTREACHED(); |
| break; |
| } |
| register_field_trial.Run("SyntheticStackProfilingConfiguration", group); |
| } |
| +void StackSamplingConfiguration::AppendCommandLineSwitchForChildProcess( |
| + const std::string process_type, |
| + base::CommandLine* command_line) const { |
| + DCHECK(ExecutingInBrowserProcess()); |
| + |
| + if (process_type == switches::kGpuProcess && |
| + (configuration_ == PROFILE_GPU_PROCESS || |
| + configuration_ == PROFILE_BROWSER_AND_GPU_PROCESS)) { |
| + command_line->AppendSwitch(switches::kStartStackProfiler); |
| + } |
| +} |
| + |
| +// static |
| +StackSamplingConfiguration* StackSamplingConfiguration::Get() { |
| + return g_configuration.Pointer(); |
| +} |
| + |
| // static |
| StackSamplingConfiguration::ProfileConfiguration |
| StackSamplingConfiguration::GenerateConfiguration() { |
| + if (!ExecutingInBrowserProcess()) |
| + return PROFILE_FROM_COMMAND_LINE; |
| + |
| if (!IsProfilerSupported()) |
| return PROFILE_DISABLED; |
| - // Enable the profiler in the intended ultimate production configuration for |
| + // Enable the profiler in the ultimate production configuration for |
| // development/waterfall builds. |
| if (chrome::GetChannel() == version_info::Channel::UNKNOWN) |
| - return PROFILE_10HZ; |
| + return PROFILE_BROWSER_AND_GPU_PROCESS; |
| // Enable according to the variations below in canary and dev. |
| if (chrome::GetChannel() == version_info::Channel::CANARY || |
| @@ -131,7 +153,9 @@ StackSamplingConfiguration::GenerateConfiguration() { |
| // Generate a configuration according to the associated weights. |
| const Variation variations[] = { |
| - { PROFILE_10HZ, 100}, |
| + { PROFILE_BROWSER_PROCESS, 100}, |
| + { PROFILE_GPU_PROCESS, 0}, |
| + { PROFILE_BROWSER_AND_GPU_PROCESS, 0}, |
| { PROFILE_CONTROL, 0}, |
| { PROFILE_DISABLED, 0} |
| }; |