OLD | NEW |
| (Empty) |
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 import logging | |
12 | |
13 from telemetry.value import histogram_util | |
14 from telemetry.page import page_test | |
15 | |
16 | |
17 class MemoryPressure(page_test.PageTest): | |
18 def __init__(self, *args, **kwargs): | |
19 super(MemoryPressure, self).__init__(*args, **kwargs) | |
20 # _first_tab is used to access histograms | |
21 self._is_first_page = True | |
22 self._tab_count = 0 | |
23 | |
24 # Allow histogram collection | |
25 def CustomizeBrowserOptions(self, options): | |
26 histogram_util.CustomizeBrowserOptions(options) | |
27 | |
28 # Open a new tab at each page | |
29 def TabForPage(self, page, browser): | |
30 return browser.tabs.New() | |
31 | |
32 def GetTabsHistogramCounts(self, tab): | |
33 histogram_type = histogram_util.BROWSER_HISTOGRAM | |
34 discard_count = histogram_util.GetHistogramCount( | |
35 histogram_type, "Tabs.Discard.DiscardCount", tab) | |
36 kill_count = histogram_util.GetHistogramCount( | |
37 histogram_type, "Tabs.SadTab.KillCreated", tab) | |
38 return (discard_count, kill_count) | |
39 | |
40 def ValidateAndMeasurePage(self, page, tab, results): | |
41 # After navigating to each page, check if it triggered tab discards or | |
42 # kills. | |
43 (discard_count, kill_count) = self.GetTabsHistogramCounts(tab) | |
44 | |
45 # Sanity check for first page | |
46 if self._is_first_page: | |
47 self._is_first_page = False | |
48 assert discard_count == 0 and kill_count == 0 | |
49 | |
50 self._tab_count += 1 | |
51 # End the test at the first kill or discard. | |
52 if kill_count > 0 or discard_count > 0: | |
53 logging.info("test ending at tab %d, discards = %d, kills = %d" % | |
54 (self._tab_count, discard_count, kill_count)) | |
55 self.RequestExit() | |
OLD | NEW |