Home | History | Annotate | Download | only in measurements
      1 # Copyright 2013 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 
      5 """Multi tab memory test.
      6 
      7 This test is a multi tab test, but we're interested in measurements for
      8 the entire test rather than each single page.
      9 """
     10 
     11 
     12 from metrics import memory
     13 from telemetry.page import page_measurement
     14 
     15 class MemoryMultiTab(page_measurement.PageMeasurement):
     16   def __init__(self, *args, **kwargs):
     17     super(MemoryMultiTab, self).__init__(*args, **kwargs)
     18     self._memory_metric = None
     19     # _first_tab is used to make memory measurements
     20     self._first_tab = None
     21 
     22   def DidStartBrowser(self, browser):
     23     self._memory_metric = memory.MemoryMetric(browser)
     24 
     25   def CustomizeBrowserOptions(self, options):
     26     memory.MemoryMetric.CustomizeBrowserOptions(options)
     27     # Since this is a memory benchmark, we want to sample memory histograms at
     28     # a high frequency.
     29     options.AppendExtraBrowserArgs('--memory-metrics')
     30 
     31   def TabForPage(self, page, browser):
     32     return browser.tabs.New()
     33 
     34   def DidNavigateToPage(self, page, tab):
     35     # Start measurement on the first tab.
     36     if not self._first_tab:
     37       self._memory_metric.Start(page, tab)
     38       self._first_tab = tab
     39 
     40   def MeasurePage(self, page, tab, results):
     41     # Finalize measurement on the last tab.
     42     if len(tab.browser.tabs) == len(page.page_set.pages):
     43       self._memory_metric.Stop(page, self._first_tab)
     44       self._memory_metric.AddResults(self._first_tab, results)
     45