OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 import copy |
| 5 |
| 6 from chrome_remote_control import interaction |
| 7 from chrome_remote_control import multi_page_benchmark |
| 8 from chrome_remote_control import test_helper_interaction #pylint: disable=W0611 |
| 9 |
| 10 MEMORY_HISTOGRAMS = [ |
| 11 {'name': 'V8.MemoryExternalFragmentationTotal', 'units': 'percent'}, |
| 12 {'name': 'V8.MemoryHeapSampleTotalCommitted', 'units': 'kb'}, |
| 13 {'name': 'V8.MemoryHeapSampleTotalUsed', 'units': 'kb'}] |
| 14 |
| 15 class MemoryBenchmark(multi_page_benchmark.MultiPageBenchmark): |
| 16 def __init__(self): |
| 17 super(MemoryBenchmark, self).__init__() |
| 18 self._interactions = [] |
| 19 self._results = {} |
| 20 |
| 21 @staticmethod |
| 22 def GetMemoryHistograms(tab, results): |
| 23 for histogram in MEMORY_HISTOGRAMS: |
| 24 name = histogram['name'] |
| 25 data = tab.runtime.Evaluate( |
| 26 'window.domAutomationController.getHistogram("%s")' % name) |
| 27 results.AddHistogram(name, histogram['units'], data) |
| 28 |
| 29 def CustomizeBrowserOptions(self, options): |
| 30 options.extra_browser_args.append('--dom-automation') |
| 31 |
| 32 def DoNextInteraction(self, page, tab): |
| 33 if not self._interactions: |
| 34 return False |
| 35 data = self._interactions[0] |
| 36 self._interactions = self._interactions[1:] |
| 37 i = interaction.FindClassWithName(data['type'])(data) |
| 38 i.PerformInteraction(page, tab, self) |
| 39 return True |
| 40 |
| 41 def DidPerformInteraction(self, _, page, tab): |
| 42 if not self.DoNextInteraction(page, tab): |
| 43 self.GetMemoryHistograms(tab, self._results) |
| 44 |
| 45 def MeasurePage(self, page, tab, results): |
| 46 self._interactions = copy.copy(page.interactions) |
| 47 self._results = results |
| 48 tab.WaitForDocumentReadyStateToBeComplete() |
| 49 self.DoNextInteraction(page, tab) |
OLD | NEW |