Chromium Code Reviews| 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 #ifndef CHROME_COMMON_STACK_SAMPLING_CONFIGURATION_H_ | 5 #ifndef CHROME_COMMON_STACK_SAMPLING_CONFIGURATION_H_ |
| 6 #define CHROME_COMMON_STACK_SAMPLING_CONFIGURATION_H_ | 6 #define CHROME_COMMON_STACK_SAMPLING_CONFIGURATION_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 9 #include "base/profiler/stack_sampling_profiler.h" | 12 #include "base/profiler/stack_sampling_profiler.h" |
| 10 | 13 |
| 11 // Chooses a configuration for the stack sampling profiler for browser process | 14 namespace base { |
| 12 // startup. This must live outside of ChromeBrowserMainParts so it can be | 15 class CommandLine; |
| 13 // friended by ChromeMetricsServiceAccessor. | 16 } // namespace base |
| 17 | |
| 18 // StackSamplingConfiguration chooses a configuration for the enable state of | |
| 19 // the stack sampling profiler across all processes. This configuration is | |
| 20 // determined once at browser process startup. Configurations for child | |
| 21 // processes are communicated via command line arguments. | |
| 14 class StackSamplingConfiguration { | 22 class StackSamplingConfiguration { |
| 15 public: | 23 public: |
| 16 // This callback indirection is required to avoid a DEPS on | 24 // This callback indirection is required to avoid a DEPS on |
| 17 // chrome/browser/metrics. | 25 // chrome/browser/metrics. |
| 18 using RegisterSyntheticFieldTrialFunction = base::Callback<bool( | 26 using RegisterSyntheticFieldTrialFunction = base::Callback<bool( |
| 19 const std::string& trial_name, | 27 const std::string& trial_name, |
| 20 const std::string& group_name)>; | 28 const std::string& group_name)>; |
| 29 | |
| 21 StackSamplingConfiguration(); | 30 StackSamplingConfiguration(); |
| 22 | 31 |
| 23 // Get the stack sampling params to use for this session. | 32 // Get the stack sampling params to use for this process. |
| 24 base::StackSamplingProfiler::SamplingParams GetSamplingParams() const; | 33 base::StackSamplingProfiler::SamplingParams |
| 34 GetSamplingParamsForCurrentProcess() const; | |
| 25 | 35 |
| 26 // Returns true if the profiler should be started at all. | 36 // Returns true if the profiler should be started for the current process. |
| 27 bool IsProfilerEnabled() const; | 37 bool IsProfilerEnabledForCurrentProcess() const; |
| 28 | 38 |
| 29 // Register the chosen configuration as a synthetic field trial. | 39 // Register the chosen configuration as a synthetic field trial. This should |
| 40 // only be called from the browser process. | |
| 30 void RegisterSyntheticFieldTrial( | 41 void RegisterSyntheticFieldTrial( |
| 31 const RegisterSyntheticFieldTrialFunction& register_field_trial) const; | 42 const RegisterSyntheticFieldTrialFunction& register_field_trial) const; |
| 32 | 43 |
| 44 // Add a command line switch that instructs the child process to run the | |
| 45 // profiler. This should only be called from the browser process. | |
| 46 void AppendCommandLineSwitchForChildProcess( | |
| 47 const std::string process_type, | |
|
Ilya Sherman
2016/09/28 01:02:15
nit: Did you mean to pass by const-reference? We
Mike Wittman
2016/09/28 19:34:26
Oops, yes that was the intent. Done.
| |
| 48 base::CommandLine* command_line) const; | |
| 49 | |
| 50 // Returns the StackSamplingConfiguration for the process. | |
| 51 static StackSamplingConfiguration* Get(); | |
| 52 | |
| 33 private: | 53 private: |
| 34 enum ProfileConfiguration { | 54 enum ProfileConfiguration { |
| 55 // Chrome-wide configurations set in the browser process. | |
| 35 PROFILE_DISABLED, | 56 PROFILE_DISABLED, |
| 36 PROFILE_CONTROL, | 57 PROFILE_CONTROL, |
| 37 PROFILE_NO_SAMPLES, // Run the profiler thread, but don't collect profiles. | 58 PROFILE_BROWSER_PROCESS, |
| 38 PROFILE_5HZ, | 59 PROFILE_GPU_PROCESS, |
| 39 PROFILE_10HZ, | 60 PROFILE_BROWSER_AND_GPU_PROCESS, |
| 40 PROFILE_100HZ | 61 |
| 62 // Configuration set in the child processes, which receive their enable | |
| 63 // state on the command line from the browser process. | |
| 64 PROFILE_FROM_COMMAND_LINE | |
| 41 }; | 65 }; |
| 42 | 66 |
| 67 // Generates sampling profiler configurations for all processes. | |
| 43 static ProfileConfiguration GenerateConfiguration(); | 68 static ProfileConfiguration GenerateConfiguration(); |
| 44 | 69 |
| 70 // In the browser process this represents the configuration to use across all | |
| 71 // Chrome processes. In the child processes it is alwasys | |
| 72 // PROFILE_FROM_COMMAND_LINE. | |
| 45 const ProfileConfiguration configuration_; | 73 const ProfileConfiguration configuration_; |
| 46 | 74 |
| 47 DISALLOW_COPY_AND_ASSIGN(StackSamplingConfiguration); | 75 DISALLOW_COPY_AND_ASSIGN(StackSamplingConfiguration); |
| 48 }; | 76 }; |
| 49 | 77 |
| 50 #endif // CHROME_COMMON_STACK_SAMPLING_CONFIGURATION_H_ | 78 #endif // CHROME_COMMON_STACK_SAMPLING_CONFIGURATION_H_ |
| OLD | NEW |