| 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 14 matching lines...) Expand all Loading... |
| 25 'V8.MemoryMapSpaceBytesCommitted', | 25 'V8.MemoryMapSpaceBytesCommitted', |
| 26 'V8.MemoryMapSpaceBytesUsed', | 26 'V8.MemoryMapSpaceBytesUsed', |
| 27 'V8.MemoryCellSpaceBytesAvailable', | 27 'V8.MemoryCellSpaceBytesAvailable', |
| 28 'V8.MemoryCellSpaceBytesCommitted', | 28 'V8.MemoryCellSpaceBytesCommitted', |
| 29 'V8.MemoryCellSpaceBytesUsed', | 29 'V8.MemoryCellSpaceBytesUsed', |
| 30 'V8.MemoryPropertyCellSpaceBytesAvailable', | 30 'V8.MemoryPropertyCellSpaceBytesAvailable', |
| 31 'V8.MemoryPropertyCellSpaceBytesCommitted', | 31 'V8.MemoryPropertyCellSpaceBytesCommitted', |
| 32 'V8.MemoryPropertyCellSpaceBytesUsed', | 32 'V8.MemoryPropertyCellSpaceBytesUsed', |
| 33 'V8.MemoryLoSpaceBytesAvailable', | 33 'V8.MemoryLoSpaceBytesAvailable', |
| 34 'V8.MemoryLoSpaceBytesCommitted', | 34 'V8.MemoryLoSpaceBytesCommitted', |
| 35 'V8.MemoryLoSpaceBytesUsed)', | 35 'V8.MemoryLoSpaceBytesUsed', |
| 36 'V8.SizeOf_ACCESSOR_PAIR_TYPE', | 36 'V8.SizeOf_ACCESSOR_PAIR_TYPE', |
| 37 'V8.SizeOf_ACCESS_CHECK_INFO_TYPE', | 37 'V8.SizeOf_ACCESS_CHECK_INFO_TYPE', |
| 38 'V8.SizeOf_ALIASED_ARGUMENTS_ENTRY_TYPE', | 38 'V8.SizeOf_ALIASED_ARGUMENTS_ENTRY_TYPE', |
| 39 'V8.SizeOf_ALLOCATION_MEMENTO_TYPE', | 39 'V8.SizeOf_ALLOCATION_MEMENTO_TYPE', |
| 40 'V8.SizeOf_ALLOCATION_SITE_TYPE', | 40 'V8.SizeOf_ALLOCATION_SITE_TYPE', |
| 41 'V8.SizeOf_ASCII_INTERNALIZED_STRING_TYPE', | 41 'V8.SizeOf_ASCII_INTERNALIZED_STRING_TYPE', |
| 42 'V8.SizeOf_ASCII_STRING_TYPE', | 42 'V8.SizeOf_ASCII_STRING_TYPE', |
| 43 'V8.SizeOf_BOX_TYPE', | 43 'V8.SizeOf_BOX_TYPE', |
| 44 'V8.SizeOf_BREAK_POINT_INFO_TYPE', | 44 'V8.SizeOf_BREAK_POINT_INFO_TYPE', |
| 45 'V8.SizeOf_BYTE_ARRAY_TYPE', | 45 'V8.SizeOf_BYTE_ARRAY_TYPE', |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 def __init__(self): | 157 def __init__(self): |
| 158 super(V8ObjectStatsMetric, self).__init__() | 158 super(V8ObjectStatsMetric, self).__init__() |
| 159 self._results = None | 159 self._results = None |
| 160 | 160 |
| 161 @classmethod | 161 @classmethod |
| 162 def CustomizeBrowserOptions(cls, options): | 162 def CustomizeBrowserOptions(cls, options): |
| 163 options.AppendExtraBrowserArg('--enable-stats-table') | 163 options.AppendExtraBrowserArg('--enable-stats-table') |
| 164 options.AppendExtraBrowserArg('--enable-benchmarking') | 164 options.AppendExtraBrowserArg('--enable-benchmarking') |
| 165 options.AppendExtraBrowserArg( | 165 options.AppendExtraBrowserArg( |
| 166 '--js-flags=--track_gc_object_stats --expose_gc') | 166 '--js-flags=--track_gc_object_stats --expose_gc') |
| 167 # TODO(rmcilroy): This is needed for --enable-stats-table. Update once |
| 168 # https://codereview.chromium.org/22911027/ lands. |
| 169 options.AppendExtraBrowserArg('--no-sandbox') |
| 170 |
| 171 @staticmethod |
| 172 def GetV8StatsTable(tab, counters=None): |
| 173 counters = counters or _COUNTER_NAMES |
| 174 |
| 175 return tab.EvaluateJavaScript(""" |
| 176 (function(counters) { |
| 177 var results = {}; |
| 178 if (!window.chrome || !window.chrome.benchmarking) |
| 179 return results; |
| 180 window.gc(); // Trigger GC to ensure stats are checkpointed. |
| 181 for (var i = 0; i < counters.length; i++) |
| 182 results[counters[i]] = |
| 183 chrome.benchmarking.counterForRenderer(counters[i]); |
| 184 return results; |
| 185 })(%s); |
| 186 """ % json.dumps(counters)) |
| 167 | 187 |
| 168 def Start(self, page, tab): | 188 def Start(self, page, tab): |
| 169 """Do Nothing.""" | 189 """Do Nothing.""" |
| 170 pass | 190 pass |
| 171 | 191 |
| 172 def Stop(self, page, tab): | 192 def Stop(self, page, tab): |
| 173 """Get the values in the stats table after the page is loaded.""" | 193 """Get the values in the stats table after the page is loaded.""" |
| 174 self._results = tab.EvaluateJavaScript(""" | 194 self._results = V8ObjectStatsMetric.GetV8StatsTable(tab) |
| 175 (function(counters) { | |
| 176 var results = {}; | |
| 177 if (!window.chrome || !window.chrome.benchmarking) | |
| 178 return results; | |
| 179 window.gc(); // Trigger GC to ensure stats are checkpointed. | |
| 180 for (var i = 0; i < counters.length; i++) | |
| 181 results[counters[i]] = chrome.benchmarking.counterForRenderer(counters[i]); | |
| 182 return results; | |
| 183 })(%s); | |
| 184 """ % json.dumps(_COUNTER_NAMES)) | |
| 185 if not self._results: | 195 if not self._results: |
| 186 logging.warning('No V8 object stats from website: ' + page.display_url) | 196 logging.warning('No V8 object stats from website: ' + page.display_url) |
| 187 | 197 |
| 188 def AddResults(self, tab, results): | 198 def AddResults(self, tab, results): |
| 189 """Add results for this page to the results object.""" | 199 """Add results for this page to the results object.""" |
| 190 assert self._results != None, 'Must call Stop() first' | 200 assert self._results != None, 'Must call Stop() first' |
| 191 for counter_name in self._results: | 201 for counter_name in self._results: |
| 192 results.Add(counter_name, 'kb', self._results[counter_name] / 1024.0) | 202 results.Add(counter_name, 'kb', self._results[counter_name] / 1024.0) |
| OLD | NEW |