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 from metrics import histogram 5 from metrics import memory 6 from telemetry.page import page_measurement 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): 21 def __init__(self): 22 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 32 33 def DidStartBrowser(self, browser): 34 self._memory_metric = memory.MemoryMetric(browser) 35 self._memory_metric.Start() 36 37 def DidNavigateToPage(self, page, tab): 38 for h in self.histograms: 39 h.Start(page, tab) 40 41 def CustomizeBrowserOptions(self, options): 42 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') 43 options.AppendExtraBrowserArg('--enable-memory-benchmarking') 44 # 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 46 # (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 48 # customizing, so that we get the same generic histograms produced for all 49 # pages. 50 options.AppendExtraBrowserArg('--disable-histogram-customizer') 51 options.AppendExtraBrowserArg('--memory-metrics') 52 53 # Old commandline flags used for reference builds. 54 options.AppendExtraBrowserArg('--dom-automation') 55 options.AppendExtraBrowserArg( 56 '--reduce-security-for-dom-automation-tests') 57 58 def CanRunForPage(self, page): 59 return hasattr(page, 'stress_memory') 60 61 def MeasurePage(self, page, tab, results): 62 for h in self.histograms: 63 h.GetValue(page, tab, results) 64 65 if tab.browser.is_profiler_active('tcmalloc-heap'): 66 # The tcmalloc_heap_profiler dumps files at regular 67 # intervals (~20 secs). 68 # This is a minor optimization to ensure it'll dump the last file when 69 # the test completes. 70 tab.ExecuteJavaScript(""" 71 if (chrome && chrome.memoryBenchmarking) { 72 chrome.memoryBenchmarking.heapProfilerDump('final', 'renderer'); 73 chrome.memoryBenchmarking.heapProfilerDump('final', 'browser'); 74 } 75 """) 76 77 def DidRunTest(self, tab, results): 78 self._memory_metric.Stop() 79 self._memory_metric.AddResults(tab, results) 80 81