Chromium Code Reviews| 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: | |
|
tonyg
2014/03/05 15:50:26
Nothing for this CL, but just lamenting that we re
| |
| 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): | |
| 35 self._cpu_metric = cpu.CpuMetric(browser) | |
| 36 | |
| 37 def MeasurePage(self, page, tab, results): | 46 def MeasurePage(self, page, tab, results): |
| 38 """On the last tab, cycle through each tab that was opened and then record | 47 """On the last tab, cycle through each tab that was opened and then record |
| 39 a single histogram for the tab switching metric.""" | 48 a single histogram for the tab switching metric.""" |
| 40 if len(tab.browser.tabs) != len(page.page_set.pages): | 49 if len(tab.browser.tabs) != len(page.page_set.pages): |
| 41 return | 50 return |
| 42 self._cpu_metric.Start(page, tab) | 51 |
| 43 time.sleep(.5) | 52 # Measure power usage of tabs after quiescence. |
| 44 self._cpu_metric.Stop(page, tab) | 53 util.WaitFor(tab.HasReachedQuiescence, 60) |
| 45 # Calculate the idle cpu load before any actions are done. | 54 |
| 46 self._cpu_metric.AddResults(tab, results, | 55 self._power_metric.Start(page, tab) |
| 47 'idle_cpu_utilization') | 56 time.sleep(5) |
| 57 self._power_metric.Stop(page, tab) | |
| 58 self._power_metric.AddResults(tab, results,) | |
| 48 | 59 |
| 49 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' | 60 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' |
| 50 histogram_type = histogram_util.BROWSER_HISTOGRAM | 61 histogram_type = histogram_util.BROWSER_HISTOGRAM |
| 51 display_name = 'MPArch_RWH_TabSwitchPaintDuration' | 62 display_name = 'MPArch_RWH_TabSwitchPaintDuration' |
| 52 first_histogram = histogram_util.GetHistogram( | 63 first_histogram = histogram_util.GetHistogram( |
| 53 histogram_type, histogram_name, tab) | 64 histogram_type, histogram_name, tab) |
| 54 prev_histogram = first_histogram | 65 prev_histogram = first_histogram |
| 55 | 66 |
| 56 for i in xrange(len(tab.browser.tabs)): | 67 for i in xrange(len(tab.browser.tabs)): |
| 57 t = tab.browser.tabs[i] | 68 t = tab.browser.tabs[i] |
| 58 t.Activate() | 69 t.Activate() |
| 59 def _IsDone(): | 70 def _IsDone(): |
| 60 cur_histogram = histogram_util.GetHistogram( | 71 cur_histogram = histogram_util.GetHistogram( |
| 61 histogram_type, histogram_name, tab) | 72 histogram_type, histogram_name, tab) |
| 62 diff_histogram = histogram_util.SubtractHistogram( | 73 diff_histogram = histogram_util.SubtractHistogram( |
| 63 cur_histogram, prev_histogram) | 74 cur_histogram, prev_histogram) |
| 64 return diff_histogram | 75 return diff_histogram |
| 65 util.WaitFor(_IsDone, 30) | 76 util.WaitFor(_IsDone, 30) |
| 66 prev_histogram = histogram_util.GetHistogram( | 77 prev_histogram = histogram_util.GetHistogram( |
| 67 histogram_type, histogram_name, tab) | 78 histogram_type, histogram_name, tab) |
| 68 | 79 |
| 69 last_histogram = histogram_util.GetHistogram( | 80 last_histogram = histogram_util.GetHistogram( |
| 70 histogram_type, histogram_name, tab) | 81 histogram_type, histogram_name, tab) |
| 71 diff_histogram = histogram_util.SubtractHistogram(last_histogram, | 82 diff_histogram = histogram_util.SubtractHistogram(last_histogram, |
| 72 first_histogram) | 83 first_histogram) |
| 73 | 84 |
| 74 results.AddSummary(display_name, '', diff_histogram, | 85 results.AddSummary(display_name, '', diff_histogram, |
| 75 data_type='unimportant-histogram') | 86 data_type='unimportant-histogram') |
| OLD | NEW |