| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 | 4 |
| 5 """Multi tab memory test. | 5 """Multi tab memory test. |
| 6 | 6 |
| 7 This test is a multi tab test, but we're interested in measurements for | 7 This test is a multi tab test, but we're interested in measurements for |
| 8 the entire test rather than each single page. | 8 the entire test rather than each single page. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import logging | 11 import logging |
| 12 | 12 |
| 13 from metrics import histogram_util | 13 from metrics import histogram_util |
| 14 from telemetry.page import page_measurement | 14 from telemetry.page import page_measurement |
| 15 | 15 |
| 16 |
| 16 class MemoryPressure(page_measurement.PageMeasurement): | 17 class MemoryPressure(page_measurement.PageMeasurement): |
| 17 def __init__(self, *args, **kwargs): | 18 def __init__(self, *args, **kwargs): |
| 18 super(MemoryPressure, self).__init__(*args, **kwargs) | 19 super(MemoryPressure, self).__init__(*args, **kwargs) |
| 19 # _first_tab is used to access histograms | 20 # _first_tab is used to access histograms |
| 20 self._is_first_page = True | 21 self._is_first_page = True |
| 21 self._tab_count = 0 | 22 self._tab_count = 0 |
| 22 | 23 |
| 23 # Allow histogram collection | 24 # Allow histogram collection |
| 24 def CustomizeBrowserOptions(self, options): | 25 def CustomizeBrowserOptions(self, options): |
| 25 histogram_util.CustomizeBrowserOptions(options) | 26 histogram_util.CustomizeBrowserOptions(options) |
| 26 | 27 |
| 27 # Open a new tab at each page | 28 # Open a new tab at each page |
| 28 def TabForPage(self, page, tab): | 29 def TabForPage(self, page, browser): |
| 29 return tab.browser.tabs.New() | 30 return browser.tabs.New() |
| 30 | 31 |
| 31 def GetTabsHistogramCounts(self, tab): | 32 def GetTabsHistogramCounts(self, tab): |
| 32 histogram_type = histogram_util.BROWSER_HISTOGRAM | 33 histogram_type = histogram_util.BROWSER_HISTOGRAM |
| 33 discard_count = histogram_util.GetHistogramCount( | 34 discard_count = histogram_util.GetHistogramCount( |
| 34 histogram_type, "Tabs.Discard.DiscardCount", tab) | 35 histogram_type, "Tabs.Discard.DiscardCount", tab) |
| 35 kill_count = histogram_util.GetHistogramCount( | 36 kill_count = histogram_util.GetHistogramCount( |
| 36 histogram_type, "Tabs.SadTab.KillCreated", tab) | 37 histogram_type, "Tabs.SadTab.KillCreated", tab) |
| 37 return (discard_count, kill_count) | 38 return (discard_count, kill_count) |
| 38 | 39 |
| 39 def DidRunPageRepeats(self, page, tab): | 40 def MeasurePage(self, page, tab, results): |
| 40 # After navigating to each page, check if it triggered tab discards or | 41 # After navigating to each page, check if it triggered tab discards or |
| 41 # kills. | 42 # kills. |
| 42 (discard_count, kill_count) = self.GetTabsHistogramCounts(tab) | 43 (discard_count, kill_count) = self.GetTabsHistogramCounts(tab) |
| 43 # Done with this tab. Disconnect cleanly from it to avoid a possible | 44 # Done with this tab. Disconnect cleanly from it to avoid a possible |
| 44 # TabCrashException if the tab is discarded or killed. | 45 # TabCrashException if the tab is discarded or killed. |
| 45 tab.Disconnect() | 46 tab.Disconnect() |
| 46 # Sanity check for first page | 47 # Sanity check for first page |
| 47 if self._is_first_page: | 48 if self._is_first_page: |
| 48 self._is_first_page = False | 49 self._is_first_page = False |
| 49 assert discard_count == 0 and kill_count == 0 | 50 assert discard_count == 0 and kill_count == 0 |
| 50 | 51 |
| 51 self._tab_count += 1 | 52 self._tab_count += 1 |
| 52 # End the test at the first kill or discard. | 53 # End the test at the first kill or discard. |
| 53 if kill_count > 0 or discard_count > 0: | 54 if kill_count > 0 or discard_count > 0: |
| 54 logging.info("test ending at tab %d, discards = %d, kills = %d" % | 55 logging.info("test ending at tab %d, discards = %d, kills = %d" % |
| 55 (self._tab_count, discard_count, kill_count)) | 56 (self._tab_count, discard_count, kill_count)) |
| 56 self.RequestExit() | 57 self.RequestExit() |
| 57 | |
| 58 def MeasurePage(self, page, tab, results): # pylint: disable=W0613 | |
| 59 pass | |
| OLD | NEW |