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 "chrome/common/channel_info.h" | 10 #include "chrome/common/channel_info.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 const base::TimeDelta duration = base::TimeDelta::FromSeconds(30); | 57 const base::TimeDelta duration = base::TimeDelta::FromSeconds(30); |
58 params.sampling_interval = base::TimeDelta::FromMilliseconds(100); | 58 params.sampling_interval = base::TimeDelta::FromMilliseconds(100); |
59 params.samples_per_burst = duration / params.sampling_interval; | 59 params.samples_per_burst = duration / params.sampling_interval; |
60 } | 60 } |
61 | 61 |
62 return params; | 62 return params; |
63 } | 63 } |
64 | 64 |
65 bool StackSamplingConfiguration::IsProfilerEnabledForCurrentProcess() const { | 65 bool StackSamplingConfiguration::IsProfilerEnabledForCurrentProcess() const { |
66 if (IsBrowserProcess()) { | 66 if (IsBrowserProcess()) { |
67 return configuration_ == PROFILE_BROWSER_PROCESS || | 67 switch (configuration_) { |
68 configuration_ == PROFILE_BROWSER_AND_GPU_PROCESS; | 68 case PROFILE_BROWSER_PROCESS: |
69 case PROFILE_BROWSER_AND_GPU_PROCESS: | |
70 case PROFILE_CONTROL: | |
71 return true; | |
72 | |
73 default: | |
74 return false; | |
75 } | |
69 } | 76 } |
70 | 77 |
71 DCHECK_EQ(PROFILE_FROM_COMMAND_LINE, configuration_); | 78 DCHECK_EQ(PROFILE_FROM_COMMAND_LINE, configuration_); |
72 // This is a child process. The |kStartStackProfiler| switch passed by the | 79 // This is a child process. The |kStartStackProfiler| switch passed by the |
73 // browser process determines whether the profiler is enabled for the process. | 80 // browser process determines whether the profiler is enabled for the process. |
74 const base::CommandLine* command_line = | 81 const base::CommandLine* command_line = |
75 base::CommandLine::ForCurrentProcess(); | 82 base::CommandLine::ForCurrentProcess(); |
76 return command_line->HasSwitch(switches::kStartStackProfiler); | 83 return command_line->HasSwitch(switches::kStartStackProfiler); |
77 } | 84 } |
78 | 85 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 } | 134 } |
128 } | 135 } |
129 | 136 |
130 // static | 137 // static |
131 StackSamplingConfiguration* StackSamplingConfiguration::Get() { | 138 StackSamplingConfiguration* StackSamplingConfiguration::Get() { |
132 return g_configuration.Pointer(); | 139 return g_configuration.Pointer(); |
133 } | 140 } |
134 | 141 |
135 // static | 142 // static |
136 StackSamplingConfiguration::ProfileConfiguration | 143 StackSamplingConfiguration::ProfileConfiguration |
144 StackSamplingConfiguration::ChooseConfiguration( | |
145 const std::vector<Variation>& variations) { | |
146 int total_weight = 0; | |
147 for (const Variation& variation : variations) | |
148 total_weight += variation.weight; | |
149 DCHECK_EQ(100, total_weight); | |
150 | |
151 int chosen = base::RandInt(0, total_weight - 1); // Max is inclusive. | |
152 int cumulative_weight = 0; | |
153 for (const Variation& variation : variations) { | |
154 if (chosen >= cumulative_weight && | |
155 chosen < cumulative_weight + variation.weight) { | |
156 return variation.config; | |
157 } | |
158 cumulative_weight += variation.weight; | |
159 } | |
160 NOTREACHED(); | |
161 return PROFILE_DISABLED; | |
162 } | |
Ilya Sherman
2016/10/12 20:52:31
Hmm, it looks like you're re-implementing the fiel
Mike Wittman
2016/10/12 21:50:41
The profiler can't use the standard field trial me
Ilya Sherman
2016/10/12 22:16:17
Ah, makes sense -- thanks for the reminder. Is th
Mike Wittman
2016/10/12 23:00:32
Not explicitly. Added to the comment on GetSynthet
| |
163 | |
164 // static | |
165 StackSamplingConfiguration::ProfileConfiguration | |
137 StackSamplingConfiguration::GenerateConfiguration() { | 166 StackSamplingConfiguration::GenerateConfiguration() { |
138 if (!IsBrowserProcess()) | 167 if (!IsBrowserProcess()) |
139 return PROFILE_FROM_COMMAND_LINE; | 168 return PROFILE_FROM_COMMAND_LINE; |
140 | 169 |
141 if (!IsProfilerSupported()) | 170 if (!IsProfilerSupported()) |
142 return PROFILE_DISABLED; | 171 return PROFILE_DISABLED; |
143 | 172 |
144 // Enable the profiler in the ultimate production configuration for | 173 switch (chrome::GetChannel()) { |
145 // development/waterfall builds. | 174 // Enable the profiler in the ultimate production configuration for |
146 if (chrome::GetChannel() == version_info::Channel::UNKNOWN) | 175 // development/waterfall builds. |
147 return PROFILE_BROWSER_AND_GPU_PROCESS; | 176 case version_info::Channel::UNKNOWN: |
177 return PROFILE_BROWSER_AND_GPU_PROCESS; | |
148 | 178 |
149 // Enable according to the variations below in canary and dev. | 179 case version_info::Channel::CANARY: |
150 if (chrome::GetChannel() == version_info::Channel::CANARY || | 180 return ChooseConfiguration({ |
151 chrome::GetChannel() == version_info::Channel::DEV) { | 181 { PROFILE_BROWSER_PROCESS, 80}, |
152 struct Variation { | 182 { PROFILE_GPU_PROCESS, 0}, |
153 ProfileConfiguration config; | 183 { PROFILE_BROWSER_AND_GPU_PROCESS, 10}, |
154 int weight; | 184 { PROFILE_CONTROL, 10}, |
155 }; | 185 { PROFILE_DISABLED, 0} |
186 }); | |
156 | 187 |
157 // Generate a configuration according to the associated weights. | 188 case version_info::Channel::DEV: |
158 const Variation variations[] = { | 189 return ChooseConfiguration({ |
159 { PROFILE_BROWSER_PROCESS, 100}, | 190 { PROFILE_BROWSER_PROCESS, 100}, |
160 { PROFILE_GPU_PROCESS, 0}, | 191 { PROFILE_GPU_PROCESS, 0}, |
161 { PROFILE_BROWSER_AND_GPU_PROCESS, 0}, | 192 { PROFILE_BROWSER_AND_GPU_PROCESS, 0}, |
162 { PROFILE_CONTROL, 0}, | 193 { PROFILE_CONTROL, 0}, |
163 { PROFILE_DISABLED, 0} | 194 { PROFILE_DISABLED, 0} |
164 }; | 195 }); |
165 | |
166 int total_weight = 0; | |
167 for (const Variation& variation : variations) | |
168 total_weight += variation.weight; | |
169 DCHECK_EQ(100, total_weight); | |
170 | |
171 int chosen = base::RandInt(0, total_weight - 1); // Max is inclusive. | |
172 int cumulative_weight = 0; | |
173 for (const Variation& variation : variations) { | |
174 if (chosen >= cumulative_weight && | |
175 chosen < cumulative_weight + variation.weight) { | |
176 return variation.config; | |
177 } | |
178 cumulative_weight += variation.weight; | |
179 } | |
180 NOTREACHED(); | |
181 } | 196 } |
182 | 197 |
183 return PROFILE_DISABLED; | 198 return PROFILE_DISABLED; |
184 } | 199 } |
OLD | NEW |