OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import json | 5 import json |
6 import logging | 6 import logging |
7 | 7 |
8 from metrics import Metric | 8 from metrics import Metric |
9 | 9 |
10 _COUNTER_NAMES = [ | 10 _COUNTER_NAMES = [ |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 'V8.SizeOf_TYPE_SWITCH_INFO_TYPE' | 155 'V8.SizeOf_TYPE_SWITCH_INFO_TYPE' |
156 ] | 156 ] |
157 | 157 |
158 class V8ObjectStatsMetric(Metric): | 158 class V8ObjectStatsMetric(Metric): |
159 """V8ObjectStatsMetric gathers statistics on the size of types in the V8 heap. | 159 """V8ObjectStatsMetric gathers statistics on the size of types in the V8 heap. |
160 | 160 |
161 It does this by enabling the --track_gc_object_stats flag on V8 and reading | 161 It does this by enabling the --track_gc_object_stats flag on V8 and reading |
162 these statistics from the StatsTableMetric. | 162 these statistics from the StatsTableMetric. |
163 """ | 163 """ |
164 | 164 |
165 def __init__(self): | 165 def __init__(self, counters=None): |
166 super(V8ObjectStatsMetric, self).__init__() | 166 super(V8ObjectStatsMetric, self).__init__() |
167 self._results = None | 167 self._results = None |
| 168 self._counters = counters or _COUNTER_NAMES |
168 | 169 |
169 @classmethod | 170 @classmethod |
170 def CustomizeBrowserOptions(cls, options): | 171 def CustomizeBrowserOptions(cls, options): |
171 options.AppendExtraBrowserArgs([ | 172 options.AppendExtraBrowserArgs([ |
172 '--enable-stats-table', | 173 '--enable-stats-table', |
173 '--enable-benchmarking', | 174 '--enable-benchmarking', |
174 '--js-flags=--track_gc_object_stats --expose_gc', | 175 '--js-flags=--track_gc_object_stats --expose_gc', |
175 # TODO(rmcilroy): This is needed for --enable-stats-table. Update once | 176 # TODO(rmcilroy): This is needed for --enable-stats-table. Update once |
176 # https://codereview.chromium.org/22911027/ lands. | 177 # https://codereview.chromium.org/22911027/ lands. |
177 '--no-sandbox' | 178 '--no-sandbox' |
178 ]) | 179 ]) |
179 | 180 |
180 @staticmethod | 181 @staticmethod |
181 def GetV8StatsTable(tab, counters=None): | 182 def GetV8StatsTable(tab, counters): |
182 counters = counters or _COUNTER_NAMES | |
183 | 183 |
184 return tab.EvaluateJavaScript(""" | 184 return tab.EvaluateJavaScript(""" |
185 (function(counters) { | 185 (function(counters) { |
186 var results = {}; | 186 var results = {}; |
187 if (!window.chrome || !window.chrome.benchmarking) | 187 if (!window.chrome || !window.chrome.benchmarking) |
188 return results; | 188 return results; |
189 try { | 189 try { |
190 window.gc(); // Trigger GC to ensure stats are checkpointed. | 190 window.gc(); // Trigger GC to ensure stats are checkpointed. |
191 } catch(e) { | 191 } catch(e) { |
192 // window.gc() could have been mapped to something else, just continue. | 192 // window.gc() could have been mapped to something else, just continue. |
193 } | 193 } |
194 for (var i = 0; i < counters.length; i++) | 194 for (var i = 0; i < counters.length; i++) |
195 results[counters[i]] = | 195 results[counters[i]] = |
196 chrome.benchmarking.counterForRenderer(counters[i]); | 196 chrome.benchmarking.counterForRenderer(counters[i]); |
197 return results; | 197 return results; |
198 })(%s); | 198 })(%s); |
199 """ % json.dumps(counters)) | 199 """ % json.dumps(counters)) |
200 | 200 |
201 def Start(self, page, tab): | 201 def Start(self, page, tab): |
202 """Do Nothing.""" | 202 """Do Nothing.""" |
203 pass | 203 pass |
204 | 204 |
205 def Stop(self, page, tab): | 205 def Stop(self, page, tab): |
206 """Get the values in the stats table after the page is loaded.""" | 206 """Get the values in the stats table after the page is loaded.""" |
207 self._results = V8ObjectStatsMetric.GetV8StatsTable(tab) | 207 self._results = V8ObjectStatsMetric.GetV8StatsTable(tab, self._counters) |
208 if not self._results: | 208 if not self._results: |
209 logging.warning('No V8 object stats from website: ' + page.display_name) | 209 logging.warning('No V8 object stats from website: ' + page.display_name) |
210 | 210 |
211 def AddResults(self, tab, results): | 211 def AddResults(self, tab, results): |
212 """Add results for this page to the results object.""" | 212 """Add results for this page to the results object.""" |
213 assert self._results != None, 'Must call Stop() first' | 213 assert self._results != None, 'Must call Stop() first' |
214 for counter_name in self._results: | 214 for counter_name in self._results: |
215 results.Add(counter_name, 'kb', self._results[counter_name] / 1024.0) | 215 results.Add(counter_name, 'kb', self._results[counter_name] / 1024.0) |
OLD | NEW |