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 """ | 11 """ |
11 | 12 |
12 import time | 13 import time |
13 | 14 |
14 from metrics import cpu | |
15 from metrics import histogram_util | 15 from metrics import histogram_util |
| 16 from metrics import power |
16 from telemetry.core import util | 17 from telemetry.core import util |
17 from telemetry.page import page_measurement | 18 from telemetry.page import page_measurement |
18 | 19 |
19 # TODO: Revisit this test once multitab support is finalized. | 20 # TODO: Revisit this test once multitab support is finalized. |
20 | 21 |
21 class TabSwitching(page_measurement.PageMeasurement): | 22 class TabSwitching(page_measurement.PageMeasurement): |
22 def __init__(self): | 23 def __init__(self): |
23 super(TabSwitching, self).__init__() | 24 super(TabSwitching, self).__init__() |
24 self._cpu_metric = None | 25 self._first_page_in_pageset = True |
| 26 self._power_metric = power.PowerMetric() |
25 | 27 |
26 def CustomizeBrowserOptions(self, options): | 28 def CustomizeBrowserOptions(self, options): |
27 options.AppendExtraBrowserArgs([ | 29 options.AppendExtraBrowserArgs([ |
28 '--enable-stats-collection-bindings' | 30 '--enable-stats-collection-bindings' |
29 ]) | 31 ]) |
| 32 power.PowerMetric.CustomizeBrowserOptions(options) |
| 33 |
| 34 def DidStartBrowser(self, browser): |
| 35 self._first_page_in_pageset = True |
30 | 36 |
31 def TabForPage(self, page, browser): | 37 def TabForPage(self, page, browser): |
| 38 if self._first_page_in_pageset: |
| 39 # The initial browser window contains a single tab, navigate that tab |
| 40 # rather than creating a new one. |
| 41 self._first_page_in_pageset = False |
| 42 return browser.tabs[0] |
| 43 |
32 return browser.tabs.New() | 44 return browser.tabs.New() |
33 | 45 |
34 def DidStartBrowser(self, browser): | 46 def StopBrowserAfterPage(self, browser, page): |
35 self._cpu_metric = cpu.CpuMetric(browser) | 47 # Restart the browser after the last page in the pageset. |
| 48 return len(browser.tabs) >= len(page.page_set.pages) |
36 | 49 |
37 def MeasurePage(self, page, tab, results): | 50 def MeasurePage(self, page, tab, results): |
38 """On the last tab, cycle through each tab that was opened and then record | 51 """On the last tab, cycle through each tab that was opened and then record |
39 a single histogram for the tab switching metric.""" | 52 a single histogram for the tab switching metric.""" |
40 if len(tab.browser.tabs) != len(page.page_set.pages): | 53 if len(tab.browser.tabs) != len(page.page_set.pages): |
41 return | 54 return |
42 self._cpu_metric.Start(page, tab) | 55 |
43 time.sleep(.5) | 56 # Measure power usage of tabs after quiescence. |
44 self._cpu_metric.Stop(page, tab) | 57 util.WaitFor(tab.HasReachedQuiescence, 60) |
45 # Calculate the idle cpu load before any actions are done. | 58 |
46 self._cpu_metric.AddResults(tab, results, | 59 self._power_metric.Start(page, tab) |
47 'idle_cpu_utilization') | 60 time.sleep(5) |
| 61 self._power_metric.Stop(page, tab) |
| 62 self._power_metric.AddResults(tab, results,) |
48 | 63 |
49 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' | 64 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' |
50 histogram_type = histogram_util.BROWSER_HISTOGRAM | 65 histogram_type = histogram_util.BROWSER_HISTOGRAM |
51 display_name = 'MPArch_RWH_TabSwitchPaintDuration' | 66 display_name = 'MPArch_RWH_TabSwitchPaintDuration' |
52 first_histogram = histogram_util.GetHistogram( | 67 first_histogram = histogram_util.GetHistogram( |
53 histogram_type, histogram_name, tab) | 68 histogram_type, histogram_name, tab) |
54 prev_histogram = first_histogram | 69 prev_histogram = first_histogram |
55 | 70 |
56 for i in xrange(len(tab.browser.tabs)): | 71 for i in xrange(len(tab.browser.tabs)): |
57 t = tab.browser.tabs[i] | 72 t = tab.browser.tabs[i] |
58 t.Activate() | 73 t.Activate() |
59 def _IsDone(): | 74 def _IsDone(): |
60 cur_histogram = histogram_util.GetHistogram( | 75 cur_histogram = histogram_util.GetHistogram( |
61 histogram_type, histogram_name, tab) | 76 histogram_type, histogram_name, tab) |
62 diff_histogram = histogram_util.SubtractHistogram( | 77 diff_histogram = histogram_util.SubtractHistogram( |
63 cur_histogram, prev_histogram) | 78 cur_histogram, prev_histogram) |
64 return diff_histogram | 79 return diff_histogram |
65 util.WaitFor(_IsDone, 30) | 80 util.WaitFor(_IsDone, 30) |
66 prev_histogram = histogram_util.GetHistogram( | 81 prev_histogram = histogram_util.GetHistogram( |
67 histogram_type, histogram_name, tab) | 82 histogram_type, histogram_name, tab) |
68 | 83 |
69 last_histogram = histogram_util.GetHistogram( | 84 last_histogram = histogram_util.GetHistogram( |
70 histogram_type, histogram_name, tab) | 85 histogram_type, histogram_name, tab) |
71 diff_histogram = histogram_util.SubtractHistogram(last_histogram, | 86 diff_histogram = histogram_util.SubtractHistogram(last_histogram, |
72 first_histogram) | 87 first_histogram) |
73 | 88 |
74 results.AddSummary(display_name, '', diff_histogram, | 89 results.AddSummary(display_name, '', diff_histogram, |
75 data_type='unimportant-histogram') | 90 data_type='unimportant-histogram') |
OLD | NEW |