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 telemetry import multi_page_benchmark | 4 from telemetry import multi_page_benchmark |
5 from telemetry import util | |
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._baselines = dict() | |
20 | |
21 def WillNavigateToPage(self, page, tab): | |
nduca
2013/02/12 18:33:15
not sure i'd call this baselines. The word 'Baseli
marja
2013/02/13 16:09:30
Done.
| |
22 for histogram in MEMORY_HISTOGRAMS: | |
23 name = histogram['name'] | |
nduca
2013/02/12 18:33:15
How about a histogram measurement object?
Histogr
marja
2013/02/13 16:09:30
Done.
| |
24 data = self._GetHistogramFromDomAutomation(tab, 'getHistogram', name) | |
25 if data: | |
26 self._baselines[page.url + name] = data | |
27 for histogram in BROWSER_MEMORY_HISTOGRAMS: | |
28 name = histogram['name'] | |
29 data = self._GetHistogramFromDomAutomation(tab, 'getBrowserHistogram', | |
30 name) | |
31 if data: | |
32 self._baselines[page.url + name] = data | |
18 | 33 |
19 def CustomizeBrowserOptions(self, options): | 34 def CustomizeBrowserOptions(self, options): |
20 options.AppendExtraBrowserArg('--dom-automation') | 35 options.AppendExtraBrowserArg('--dom-automation') |
21 # For a hard-coded set of Google pages (such as GMail), we produce custom | 36 # 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 | 37 # memory histograms (V8.Something_gmail) instead of the generic histograms |
23 # (V8.Something), if we detect that a renderer is only rendering this page | 38 # (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 | 39 # 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 | 40 # customizing, so that we get the same generic histograms produced for all |
26 # pages. | 41 # pages. |
27 options.AppendExtraBrowserArg('--disable-histogram-customizer') | 42 options.AppendExtraBrowserArg('--disable-histogram-customizer') |
28 options.AppendExtraBrowserArg('--memory-metrics') | 43 options.AppendExtraBrowserArg('--memory-metrics') |
29 | 44 |
30 def CanRunForPage(self, page): | 45 def CanRunForPage(self, page): |
31 return hasattr(page, 'stress_memory') | 46 return hasattr(page, 'stress_memory') |
32 | 47 |
33 def MeasurePage(self, page, tab, results): | 48 def MeasurePage(self, page, tab, results): |
34 for histogram in MEMORY_HISTOGRAMS: | 49 for histogram in MEMORY_HISTOGRAMS: |
35 self._GetHistogramFromDomAutomation(tab, 'getHistogram', histogram, | 50 name = histogram['name'] |
36 results) | 51 data = self._GetHistogramFromDomAutomation(tab, 'getHistogram', name) |
52 self._AddHistogramResult(histogram, page, data, results) | |
37 for histogram in BROWSER_MEMORY_HISTOGRAMS: | 53 for histogram in BROWSER_MEMORY_HISTOGRAMS: |
38 self._GetHistogramFromDomAutomation(tab, 'getBrowserHistogram', histogram, | 54 name = histogram['name'] |
39 results) | 55 data = self._GetHistogramFromDomAutomation(tab, 'getBrowserHistogram', |
56 name) | |
57 self._AddHistogramResult(histogram, page, data, results) | |
40 | 58 |
41 def _GetHistogramFromDomAutomation(self, tab, func, histogram, results): | 59 def _GetHistogramFromDomAutomation(self, tab, func, name): |
42 name = histogram['name'] | |
43 js = ('window.domAutomationController.%s ? ' | 60 js = ('window.domAutomationController.%s ? ' |
44 'window.domAutomationController.%s("%s") : ""' % (func, func, name)) | 61 'window.domAutomationController.%s("%s") : ""' % (func, func, name)) |
45 data = tab.EvaluateJavaScript(js) | 62 return tab.EvaluateJavaScript(js) |
46 if data: | 63 |
47 results.Add(name.replace('.', '_'), histogram['units'], data, | 64 def _AddHistogramResult(self, histogram, page, data, results): |
48 data_type='histogram') | 65 if not data: |
66 return | |
67 name = histogram['name'] | |
68 if page.url + name not in self._baselines: | |
69 return | |
70 results.Add(name.replace('.', '_'), histogram['units'], | |
71 util.SubtractHistogram(data, self._baselines[page.url + name]), | |
72 data_type='histogram') | |
OLD | NEW |