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 """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 optparse | |
aiolos (Not reviewing)
2015/04/03 18:16:39
argparse should be used instead of optparse.
| |
13 import time | 14 import time |
14 | 15 |
15 from metrics import power | 16 from metrics import power |
16 from telemetry.core import util | 17 from telemetry.core import util |
17 from telemetry.page import page_test | 18 from telemetry.page import page_test |
18 from telemetry.value import histogram | 19 from telemetry.value import histogram |
19 from telemetry.value import histogram_util | 20 from telemetry.value import histogram_util |
20 | 21 |
21 # TODO: Revisit this test once multitab support is finalized. | 22 # TODO: Revisit this test once multitab support is finalized. |
22 | 23 |
23 class TabSwitching(page_test.PageTest): | 24 class TabSwitching(page_test.PageTest): |
24 | 25 |
25 # Amount of time to measure, in seconds. | 26 # Amount of time to measure, in seconds. |
26 SAMPLE_TIME = 30 | 27 SAMPLE_TIME = 30 |
27 | 28 |
28 def __init__(self): | 29 def __init__(self): |
29 super(TabSwitching, self).__init__() | 30 super(TabSwitching, self).__init__() |
30 self._first_page_in_pageset = True | 31 self._first_page_in_pageset = True |
31 self._power_metric = None | 32 self._power_metric = None |
32 | 33 |
34 @classmethod | |
35 def AddCommandLineArgs(cls, parser): | |
aiolos (Not reviewing)
2015/04/03 18:16:39
This shouldn't be specified via commandline arg.
| |
36 group = optparse.OptionGroup(parser, 'Tab switching options') | |
37 group.add_option('--cycle-count', | |
38 dest='cycle_count', | |
39 default=1, | |
40 type='int', | |
41 help='Number of times the tab set is cycled through.') | |
42 # Use a high polling frequency throughout the test when checking for | |
43 # completion of a tab switch. We may have to change this when running | |
44 # in a VM instrumented to get memory access statistics, because of the | |
45 # huge slowdown factor. | |
46 group.add_option('--poll-interval', | |
47 dest='poll_interval', | |
48 default=0.1, | |
49 type='float', | |
50 help='Poll interval when checking for completion ' | |
51 'of a tab switch.') | |
52 parser.add_option_group(group) | |
53 | |
33 def CustomizeBrowserOptions(self, options): | 54 def CustomizeBrowserOptions(self, options): |
34 options.AppendExtraBrowserArgs([ | 55 options.AppendExtraBrowserArgs([ |
35 '--enable-stats-collection-bindings' | 56 '--enable-stats-collection-bindings' |
36 ]) | 57 ]) |
37 # Enable background networking so we can test its impact on power usage. | 58 # Enable background networking so we can test its impact on power usage. |
38 options.disable_background_networking = False | 59 options.disable_background_networking = False |
39 power.PowerMetric.CustomizeBrowserOptions(options) | 60 power.PowerMetric.CustomizeBrowserOptions(options) |
40 | 61 |
41 def WillStartBrowser(self, platform): | 62 def WillStartBrowser(self, platform): |
42 self._first_page_in_pageset = True | 63 self._first_page_in_pageset = True |
(...skipping 27 matching lines...) Expand all Loading... | |
70 self._power_metric.Stop(page, tab) | 91 self._power_metric.Stop(page, tab) |
71 self._power_metric.AddResults(tab, results,) | 92 self._power_metric.AddResults(tab, results,) |
72 | 93 |
73 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' | 94 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' |
74 histogram_type = histogram_util.BROWSER_HISTOGRAM | 95 histogram_type = histogram_util.BROWSER_HISTOGRAM |
75 display_name = 'MPArch_RWH_TabSwitchPaintDuration' | 96 display_name = 'MPArch_RWH_TabSwitchPaintDuration' |
76 first_histogram = histogram_util.GetHistogram( | 97 first_histogram = histogram_util.GetHistogram( |
77 histogram_type, histogram_name, tab) | 98 histogram_type, histogram_name, tab) |
78 prev_histogram = first_histogram | 99 prev_histogram = first_histogram |
79 | 100 |
80 for i in xrange(len(tab.browser.tabs)): | 101 for _ in xrange(self.options.cycle_count): |
81 t = tab.browser.tabs[i] | 102 for i in xrange(len(tab.browser.tabs)): |
82 t.Activate() | 103 t = tab.browser.tabs[i] |
83 def _IsDone(): | 104 t.Activate() |
84 cur_histogram = histogram_util.GetHistogram( | 105 def _IsDone(): |
106 cur_histogram = histogram_util.GetHistogram( | |
107 histogram_type, histogram_name, tab) | |
108 diff_histogram = histogram_util.SubtractHistogram( | |
109 cur_histogram, prev_histogram) | |
110 return diff_histogram.count != 0 | |
111 # Use a fixed poll interval when detecting the completion of a | |
112 # tab switch to reduce variance as the system gets slow, for | |
113 # instance because of swapping. | |
114 util.WaitFor( | |
115 _IsDone, 30, fixed_poll_interval=self.options.poll_interval) | |
116 prev_histogram = histogram_util.GetHistogram( | |
85 histogram_type, histogram_name, tab) | 117 histogram_type, histogram_name, tab) |
86 diff_histogram = histogram_util.SubtractHistogram( | |
87 cur_histogram, prev_histogram) | |
88 return diff_histogram | |
89 util.WaitFor(_IsDone, 30) | |
90 prev_histogram = histogram_util.GetHistogram( | |
91 histogram_type, histogram_name, tab) | |
92 | 118 |
93 last_histogram = histogram_util.GetHistogram( | 119 last_histogram = histogram_util.GetHistogram( |
94 histogram_type, histogram_name, tab) | 120 histogram_type, histogram_name, tab) |
95 diff_histogram = histogram_util.SubtractHistogram(last_histogram, | 121 diff_histogram = histogram_util.SubtractHistogram(last_histogram, |
96 first_histogram) | 122 first_histogram) |
97 | 123 |
98 results.AddSummaryValue( | 124 results.AddSummaryValue( |
99 histogram.HistogramValue(None, display_name, 'ms', | 125 histogram.HistogramValue(None, display_name, 'ms', |
100 raw_value_json=diff_histogram, | 126 raw_value_json=diff_histogram, |
101 important=False)) | 127 important=False)) |
OLD | NEW |