Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: tools/perf/measurements/tab_switching.py

Issue 2809813003: Revert of Using multi-tab story in TabSwitching Benchmark (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 """The tab switching measurement. 5 """The tab switching measurement.
6 6
7 This measurement opens pages in different tabs. After all the tabs have opened, 7 This measurement opens pages in different tabs. After all the tabs have opened,
8 it cycles through each tab in sequence, and records a histogram of the time 8 it cycles through each tab in sequence, and records a histogram of the time
9 between when a tab was first requested to be shown, and when it was painted. 9 between when a tab was first requested to be shown, and when it was painted.
10 Power usage is also measured. 10 Power usage is also measured.
11 """ 11 """
12 12
13 import json
14 import time
15
16 from telemetry.core import util
13 from telemetry.page import legacy_page_test 17 from telemetry.page import legacy_page_test
14 from telemetry.value import histogram 18 from telemetry.value import histogram
15 from telemetry.value import histogram_util 19 from telemetry.value import histogram_util
16 20
17 from metrics import keychain_metric 21 from metrics import keychain_metric
22 from metrics import power
23
24 # TODO: Revisit this test once multitab support is finalized.
18 25
19 26
20 class TabSwitching(legacy_page_test.LegacyPageTest): 27 class TabSwitching(legacy_page_test.LegacyPageTest):
28
29 # Amount of time to measure, in seconds.
30 SAMPLE_TIME = 30
31
21 def __init__(self): 32 def __init__(self):
22 super(TabSwitching, self).__init__() 33 super(TabSwitching, self).__init__()
23 self._first_histogram = None 34 self.first_page_in_storyset = True
35 self._power_metric = None
24 36
25 def CustomizeBrowserOptions(self, options): 37 def CustomizeBrowserOptions(self, options):
26 keychain_metric.KeychainMetric.CustomizeBrowserOptions(options) 38 keychain_metric.KeychainMetric.CustomizeBrowserOptions(options)
27 39
28 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings']) 40 options.AppendExtraBrowserArgs([
41 '--enable-stats-collection-bindings'
42 ])
43 # Enable background networking so we can test its impact on power usage.
44 options.disable_background_networking = False
45 power.PowerMetric.CustomizeBrowserOptions(options)
29 46
30 @classmethod 47 def WillStartBrowser(self, platform):
31 def _GetTabSwitchHistogram(cls, tab_to_switch): 48 self.first_page_in_storyset = True
49 self._power_metric = power.PowerMetric(platform, TabSwitching.SAMPLE_TIME)
50
51 def TabForPage(self, page, browser):
52 del page # unused
53 if self.first_page_in_storyset:
54 # The initial browser window contains a single tab, navigate that tab
55 # rather than creating a new one.
56 self.first_page_in_storyset = False
57 return browser.tabs[0]
58
59 return browser.tabs.New()
60
61 def StopBrowserAfterPage(self, browser, page):
62 # Restart the browser after the last page in the pageset.
63 return len(browser.tabs) >= len(page.story_set.stories)
64
65 def ValidateAndMeasurePage(self, page, tab, results):
66 """On the last tab, cycle through each tab that was opened and then record
67 a single histogram for the tab switching metric."""
68 browser = tab.browser
69 if len(browser.tabs) != len(page.story_set.stories):
70 return
71
72 if browser.tabs < 2:
73 raise Exception('Should have at least two tabs for tab switching')
74
75 # Measure power usage of tabs after quiescence.
76 util.WaitFor(tab.HasReachedQuiescence, 60)
77
78 if browser.platform.CanMonitorPower():
79 self._power_metric.Start(page, tab)
80 time.sleep(TabSwitching.SAMPLE_TIME)
81 self._power_metric.Stop(page, tab)
82 self._power_metric.AddResults(tab, results,)
83
32 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' 84 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
33 histogram_type = histogram_util.BROWSER_HISTOGRAM 85 histogram_type = histogram_util.BROWSER_HISTOGRAM
34 return histogram_util.GetHistogram( 86 display_name = 'MPArch_RWH_TabSwitchPaintDuration'
35 histogram_type, histogram_name, tab_to_switch) 87 first_histogram = histogram_util.GetHistogram(
88 histogram_type, histogram_name, tab)
89 prev_histogram = first_histogram
36 90
37 def DidNavigateToPage(self, page, tab): 91 for tab_to_switch in browser.tabs:
38 """record the starting histogram""" 92 tab_to_switch.Activate()
39 self._first_histogram = self._GetTabSwitchHistogram(tab) 93 def _IsDone():
94 # pylint: disable=W0640
95 cur_histogram = histogram_util.GetHistogram(
96 histogram_type, histogram_name, tab_to_switch)
97 diff_histogram = histogram_util.SubtractHistogram(
98 cur_histogram, prev_histogram)
99 # TODO(deanliao): Add SubtractHistogramRawValue to process histogram
100 # object instead of JSON string.
101 diff_histogram_count = json.loads(diff_histogram).get('count', 0)
102 return diff_histogram_count > 0
103 util.WaitFor(_IsDone, 30)
40 104
41 def ValidateAndMeasurePage(self, page, tab, results): 105 # We need to get histogram again instead of getting cur_histogram as
42 """record the ending histogram for the tab switching metric.""" 106 # variables modified inside inner function cannot be retrieved. However,
43 last_histogram = self._GetTabSwitchHistogram(tab) 107 # inner function can see external scope's variables.
108 prev_histogram = histogram_util.GetHistogram(
109 histogram_type, histogram_name, tab_to_switch)
110
111 last_histogram = prev_histogram
44 total_diff_histogram = histogram_util.SubtractHistogram(last_histogram, 112 total_diff_histogram = histogram_util.SubtractHistogram(last_histogram,
45 self._first_histogram) 113 first_histogram)
46
47 display_name = 'MPArch_RWH_TabSwitchPaintDuration'
48 results.AddSummaryValue( 114 results.AddSummaryValue(
49 histogram.HistogramValue(None, display_name, 'ms', 115 histogram.HistogramValue(None, display_name, 'ms',
50 raw_value_json=total_diff_histogram, 116 raw_value_json=total_diff_histogram,
51 important=False)) 117 important=False))
52 118
53 keychain_metric.KeychainMetric().AddResults(tab, results) 119 keychain_metric.KeychainMetric().AddResults(tab, results)
120
121 def DidRunPage(self, platform):
122 del platform # unused
123 self._power_metric.Close()
OLDNEW
« no previous file with comments | « tools/perf/benchmarks/tab_switching.py ('k') | tools/perf/measurements/tab_switching_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698