OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 from perf_tools import histogram_measurement |
4 from telemetry import multi_page_benchmark | 5 from telemetry import multi_page_benchmark |
5 | 6 |
6 MEMORY_HISTOGRAMS = [ | 7 MEMORY_HISTOGRAMS = [ |
7 {'name': 'V8.MemoryExternalFragmentationTotal', 'units': 'percent'}, | 8 {'name': 'V8.MemoryExternalFragmentationTotal', 'units': 'percent'}, |
8 {'name': 'V8.MemoryHeapSampleTotalCommitted', 'units': 'kb'}, | 9 {'name': 'V8.MemoryHeapSampleTotalCommitted', 'units': 'kb'}, |
9 {'name': 'V8.MemoryHeapSampleTotalUsed', 'units': 'kb'}, | 10 {'name': 'V8.MemoryHeapSampleTotalUsed', 'units': 'kb'}, |
10 {'name': 'Memory.RendererUsed', 'units': 'kb'}] | 11 {'name': 'Memory.RendererUsed', 'units': 'kb'}] |
11 | 12 |
12 BROWSER_MEMORY_HISTOGRAMS = [ | 13 BROWSER_MEMORY_HISTOGRAMS = [ |
13 {'name': 'Memory.BrowserUsed', 'units': 'kb'}] | 14 {'name': 'Memory.BrowserUsed', 'units': 'kb'}] |
14 | 15 |
15 class MemoryBenchmark(multi_page_benchmark.MultiPageBenchmark): | 16 class MemoryBenchmark(multi_page_benchmark.MultiPageBenchmark): |
16 def __init__(self): | 17 def __init__(self): |
17 super(MemoryBenchmark, self).__init__('stress_memory') | 18 super(MemoryBenchmark, self).__init__('stress_memory') |
| 19 self.histograms = ( |
| 20 [histogram_measurement.HistogramMeasurement( |
| 21 h, histogram_measurement.RENDERER_HISTOGRAM) |
| 22 for h in MEMORY_HISTOGRAMS] + |
| 23 [histogram_measurement.HistogramMeasurement( |
| 24 h, histogram_measurement.BROWSER_HISTOGRAM) |
| 25 for h in BROWSER_MEMORY_HISTOGRAMS]) |
| 26 |
| 27 def DidNavigateToPage(self, page, tab): |
| 28 for h in self.histograms: |
| 29 h.Start(page, tab) |
18 | 30 |
19 def CustomizeBrowserOptions(self, options): | 31 def CustomizeBrowserOptions(self, options): |
20 options.AppendExtraBrowserArg('--dom-automation') | 32 options.AppendExtraBrowserArg('--dom-automation') |
21 # For a hard-coded set of Google pages (such as GMail), we produce custom | 33 # For a hard-coded set of Google pages (such as GMail), we produce custom |
22 # memory histograms (V8.Something_gmail) instead of the generic histograms | 34 # memory histograms (V8.Something_gmail) instead of the generic histograms |
23 # (V8.Something), if we detect that a renderer is only rendering this page | 35 # (V8.Something), if we detect that a renderer is only rendering this page |
24 # and no other pages. For this test, we need to disable histogram | 36 # and no other pages. For this test, we need to disable histogram |
25 # customizing, so that we get the same generic histograms produced for all | 37 # customizing, so that we get the same generic histograms produced for all |
26 # pages. | 38 # pages. |
27 options.AppendExtraBrowserArg('--disable-histogram-customizer') | 39 options.AppendExtraBrowserArg('--disable-histogram-customizer') |
28 options.AppendExtraBrowserArg('--memory-metrics') | 40 options.AppendExtraBrowserArg('--memory-metrics') |
29 | 41 |
30 def CanRunForPage(self, page): | 42 def CanRunForPage(self, page): |
31 return hasattr(page, 'stress_memory') | 43 return hasattr(page, 'stress_memory') |
32 | 44 |
33 def MeasurePage(self, page, tab, results): | 45 def MeasurePage(self, page, tab, results): |
34 for histogram in MEMORY_HISTOGRAMS: | 46 for h in self.histograms: |
35 self._GetHistogramFromDomAutomation(tab, 'getHistogram', histogram, | 47 h.GetValue(page, tab, results) |
36 results) | |
37 for histogram in BROWSER_MEMORY_HISTOGRAMS: | |
38 self._GetHistogramFromDomAutomation(tab, 'getBrowserHistogram', histogram, | |
39 results) | |
40 | |
41 def _GetHistogramFromDomAutomation(self, tab, func, histogram, results): | |
42 name = histogram['name'] | |
43 js = ('window.domAutomationController.%s ? ' | |
44 'window.domAutomationController.%s("%s") : ""' % (func, func, name)) | |
45 data = tab.EvaluateJavaScript(js) | |
46 if data: | |
47 results.Add(name.replace('.', '_'), histogram['units'], data, | |
48 data_type='histogram') | |
OLD | NEW |