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 metrics import histogram | 4 |
5 from metrics import memory | 5 from metrics import memory |
6 from telemetry.page import page_measurement | 6 from telemetry.page import page_measurement |
7 | 7 |
8 | |
9 MEMORY_HISTOGRAMS = [ | |
10 {'name': 'V8.MemoryExternalFragmentationTotal', 'units': 'percent'}, | |
11 {'name': 'V8.MemoryHeapSampleTotalCommitted', 'units': 'kb'}, | |
12 {'name': 'V8.MemoryHeapSampleTotalUsed', 'units': 'kb'}, | |
13 {'name': 'Memory.RendererUsed', 'units': 'kb'}] | |
14 | |
15 | |
16 BROWSER_MEMORY_HISTOGRAMS = [ | |
17 {'name': 'Memory.BrowserUsed', 'units': 'kb'}] | |
18 | |
19 | |
20 class Memory(page_measurement.PageMeasurement): | 8 class Memory(page_measurement.PageMeasurement): |
21 def __init__(self): | 9 def __init__(self): |
22 super(Memory, self).__init__('stress_memory') | 10 super(Memory, self).__init__('stress_memory') |
23 self.histograms = ( | |
24 [histogram.HistogramMetric( | |
25 h, histogram.RENDERER_HISTOGRAM) | |
26 for h in MEMORY_HISTOGRAMS] + | |
27 [histogram.HistogramMetric( | |
28 h, histogram.BROWSER_HISTOGRAM) | |
29 for h in BROWSER_MEMORY_HISTOGRAMS]) | |
30 | |
31 self._memory_metric = None | 11 self._memory_metric = None |
32 | 12 |
33 def DidStartBrowser(self, browser): | 13 def DidStartBrowser(self, browser): |
34 self._memory_metric = memory.MemoryMetric(browser) | 14 self._memory_metric = memory.MemoryMetric(browser) |
35 self._memory_metric.Start() | |
36 | 15 |
37 def DidNavigateToPage(self, page, tab): | 16 def DidNavigateToPage(self, page, tab): |
38 for h in self.histograms: | 17 self._memory_metric.Start(page, tab) |
39 h.Start(page, tab) | |
40 | 18 |
41 def CustomizeBrowserOptions(self, options): | 19 def CustomizeBrowserOptions(self, options): |
42 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') | 20 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') |
43 options.AppendExtraBrowserArg('--enable-memory-benchmarking') | 21 options.AppendExtraBrowserArg('--enable-memory-benchmarking') |
44 # For a hard-coded set of Google pages (such as GMail), we produce custom | 22 # For a hard-coded set of Google pages (such as GMail), we produce custom |
45 # memory histograms (V8.Something_gmail) instead of the generic histograms | 23 # memory histograms (V8.Something_gmail) instead of the generic histograms |
46 # (V8.Something), if we detect that a renderer is only rendering this page | 24 # (V8.Something), if we detect that a renderer is only rendering this page |
47 # and no other pages. For this test, we need to disable histogram | 25 # and no other pages. For this test, we need to disable histogram |
48 # customizing, so that we get the same generic histograms produced for all | 26 # customizing, so that we get the same generic histograms produced for all |
49 # pages. | 27 # pages. |
50 options.AppendExtraBrowserArg('--disable-histogram-customizer') | 28 options.AppendExtraBrowserArg('--disable-histogram-customizer') |
51 options.AppendExtraBrowserArg('--memory-metrics') | 29 options.AppendExtraBrowserArg('--memory-metrics') |
52 | 30 |
53 # Old commandline flags used for reference builds. | 31 # Old commandline flags used for reference builds. |
54 options.AppendExtraBrowserArg('--dom-automation') | 32 options.AppendExtraBrowserArg('--dom-automation') |
55 options.AppendExtraBrowserArg( | 33 options.AppendExtraBrowserArg( |
56 '--reduce-security-for-dom-automation-tests') | 34 '--reduce-security-for-dom-automation-tests') |
57 | 35 |
58 def CanRunForPage(self, page): | 36 def CanRunForPage(self, page): |
59 return hasattr(page, 'stress_memory') | 37 return hasattr(page, 'stress_memory') |
60 | 38 |
61 def MeasurePage(self, page, tab, results): | 39 def MeasurePage(self, page, tab, results): |
62 for h in self.histograms: | 40 self._memory_metric.Stop(page, tab) |
63 h.GetValue(page, tab, results) | 41 self._memory_metric.AddResults(tab, results) |
64 | 42 |
65 if tab.browser.is_profiler_active('tcmalloc-heap'): | 43 if tab.browser.is_profiler_active('tcmalloc-heap'): |
66 # The tcmalloc_heap_profiler dumps files at regular | 44 # The tcmalloc_heap_profiler dumps files at regular |
67 # intervals (~20 secs). | 45 # intervals (~20 secs). |
68 # This is a minor optimization to ensure it'll dump the last file when | 46 # This is a minor optimization to ensure it'll dump the last file when |
69 # the test completes. | 47 # the test completes. |
70 tab.ExecuteJavaScript(""" | 48 tab.ExecuteJavaScript(""" |
71 if (chrome && chrome.memoryBenchmarking) { | 49 if (chrome && chrome.memoryBenchmarking) { |
72 chrome.memoryBenchmarking.heapProfilerDump('final', 'renderer'); | 50 chrome.memoryBenchmarking.heapProfilerDump('final', 'renderer'); |
73 chrome.memoryBenchmarking.heapProfilerDump('final', 'browser'); | 51 chrome.memoryBenchmarking.heapProfilerDump('final', 'browser'); |
74 } | 52 } |
75 """) | 53 """) |
76 | 54 |
77 def DidRunTest(self, tab, results): | 55 def DidRunTest(self, tab, results): |
78 self._memory_metric.Stop() | 56 self._memory_metric.AddSummaryResults(results) |
79 self._memory_metric.AddResults(tab, results) | |
80 | 57 |
OLD | NEW |