ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / tools / perf / measurements / tab_switching.py
blob64125aa66edc718a195451b95c7ed00e0218bf4e
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.
5 """The tab switching measurement.
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
9 between when a tab was first requested to be shown, and when it was painted.
10 Power usage is also measured.
11 """
13 import time
15 from metrics import keychain_metric
16 from metrics import power
17 from telemetry.core import util
18 from telemetry.page import page_test
19 from telemetry.value import histogram
20 from telemetry.value import histogram_util
22 # TODO: Revisit this test once multitab support is finalized.
24 class TabSwitching(page_test.PageTest):
26 # Amount of time to measure, in seconds.
27 SAMPLE_TIME = 30
29 def __init__(self):
30 super(TabSwitching, self).__init__(action_name_to_run='RunPageInteractions')
31 self._first_page_in_pageset = True
32 self._power_metric = None
34 def CustomizeBrowserOptions(self, options):
35 keychain_metric.KeychainMetric.CustomizeBrowserOptions(options)
37 options.AppendExtraBrowserArgs([
38 '--enable-stats-collection-bindings'
40 # Enable background networking so we can test its impact on power usage.
41 options.disable_background_networking = False
42 power.PowerMetric.CustomizeBrowserOptions(options)
44 def WillStartBrowser(self, platform):
45 self._first_page_in_pageset = True
46 self._power_metric = power.PowerMetric(platform, TabSwitching.SAMPLE_TIME)
48 def TabForPage(self, page, browser):
49 if self._first_page_in_pageset:
50 # The initial browser window contains a single tab, navigate that tab
51 # rather than creating a new one.
52 self._first_page_in_pageset = False
53 return browser.tabs[0]
55 return browser.tabs.New()
57 def StopBrowserAfterPage(self, browser, page):
58 # Restart the browser after the last page in the pageset.
59 return len(browser.tabs) >= len(page.page_set.pages)
61 def ValidateAndMeasurePage(self, page, tab, results):
62 """On the last tab, cycle through each tab that was opened and then record
63 a single histogram for the tab switching metric."""
64 if len(tab.browser.tabs) != len(page.page_set.pages):
65 return
67 # Measure power usage of tabs after quiescence.
68 util.WaitFor(tab.HasReachedQuiescence, 60)
70 if tab.browser.platform.CanMonitorPower():
71 self._power_metric.Start(page, tab)
72 time.sleep(TabSwitching.SAMPLE_TIME)
73 self._power_metric.Stop(page, tab)
74 self._power_metric.AddResults(tab, results,)
76 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
77 histogram_type = histogram_util.BROWSER_HISTOGRAM
78 display_name = 'MPArch_RWH_TabSwitchPaintDuration'
79 first_histogram = histogram_util.GetHistogram(
80 histogram_type, histogram_name, tab)
81 prev_histogram = first_histogram
83 for i in xrange(len(tab.browser.tabs)):
84 t = tab.browser.tabs[i]
85 t.Activate()
86 def _IsDone():
87 cur_histogram = histogram_util.GetHistogram(
88 histogram_type, histogram_name, tab)
89 diff_histogram = histogram_util.SubtractHistogram(
90 cur_histogram, prev_histogram)
91 return diff_histogram
92 util.WaitFor(_IsDone, 30)
93 prev_histogram = histogram_util.GetHistogram(
94 histogram_type, histogram_name, tab)
96 last_histogram = histogram_util.GetHistogram(
97 histogram_type, histogram_name, tab)
98 diff_histogram = histogram_util.SubtractHistogram(last_histogram,
99 first_histogram)
101 results.AddSummaryValue(
102 histogram.HistogramValue(None, display_name, 'ms',
103 raw_value_json=diff_histogram,
104 important=False))
106 keychain_metric.KeychainMetric().AddResults(tab, results)