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 """ | 10 """ |
11 | 11 |
12 from metrics import histogram_util | 12 from metrics import histogram |
13 from telemetry.core import util | 13 from telemetry.core import util |
14 from telemetry.page import page_measurement | 14 from telemetry.page import page_measurement |
15 from telemetry.page import page_runner | 15 from telemetry.page import page_runner |
16 | 16 |
17 # TODO: Revisit this test once multitab support is finalized. | 17 # TODO: Revisit this test once multitab support is finalized. |
18 | 18 |
19 class TabSwitching(page_measurement.PageMeasurement): | 19 class TabSwitching(page_measurement.PageMeasurement): |
20 def CustomizeBrowserOptions(self, options): | 20 def CustomizeBrowserOptions(self, options): |
21 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') | 21 options.AppendExtraBrowserArg('--enable-stats-collection-bindings') |
22 options.AppendExtraBrowserArg('--dom-automation') | 22 options.AppendExtraBrowserArg('--dom-automation') |
23 | 23 |
24 def CanRunForPage(self, page): | 24 def CanRunForPage(self, page): |
25 return not page.page_set.pages.index(page) | 25 return not page.page_set.pages.index(page) |
26 | 26 |
27 def DidNavigateToPage(self, page, tab): | 27 def DidNavigateToPage(self, page, tab): |
28 for i in xrange(1, len(page.page_set.pages)): | 28 for i in xrange(1, len(page.page_set.pages)): |
29 t = tab.browser.tabs.New() | 29 t = tab.browser.tabs.New() |
30 | 30 |
31 page_state = page_runner.PageState() | 31 page_state = page_runner.PageState() |
32 page_state.PreparePage(page.page_set.pages[i], t) | 32 page_state.PreparePage(page.page_set.pages[i], t) |
33 | 33 |
34 def MeasurePage(self, _, tab, results): | 34 def MeasurePage(self, _, tab, results): |
35 """Although this is called MeasurePage, we're actually using this function | 35 """Although this is called MeasurePage, we're actually using this function |
36 to cycle through each tab that was opened via DidNavigateToPage and | 36 to cycle through each tab that was opened via DidNavigateToPage and |
37 thenrecord a single histogram for the tab switching metric. | 37 thenrecord a single histogram for the tab switching metric. |
38 """ | 38 """ |
39 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' | 39 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' |
40 histogram_type = 'getBrowserHistogram' | 40 histogram_type = histogram.BROWSER_HISTOGRAM |
41 first_histogram = histogram_util.GetHistogramFromDomAutomation( | 41 first_histogram = histogram.GetHistogramData(histogram_type, |
42 histogram_type, histogram_name, tab) | 42 histogram_name, tab) |
43 prev_histogram = first_histogram | 43 prev_histogram = first_histogram |
44 | 44 |
45 for i in xrange(len(tab.browser.tabs)): | 45 for i in xrange(len(tab.browser.tabs)): |
46 t = tab.browser.tabs[i] | 46 t = tab.browser.tabs[i] |
47 t.Activate() | 47 t.Activate() |
48 def _IsDone(): | 48 def _IsDone(): |
49 cur_histogram = histogram_util.GetHistogramFromDomAutomation( | 49 cur_histogram = histogram.GetHistogramData( |
50 histogram_type, histogram_name, tab) | 50 histogram_type,histogram_name, tab) |
51 diff_histogram = histogram_util.SubtractHistogram( | 51 diff_histogram = histogram.SubtractHistogram( |
52 cur_histogram, prev_histogram) | 52 cur_histogram, prev_histogram) |
53 return diff_histogram | 53 return diff_histogram |
54 util.WaitFor(_IsDone, 30) | 54 util.WaitFor(_IsDone, 30) |
55 prev_histogram = histogram_util.GetHistogramFromDomAutomation( | 55 prev_histogram = histogram.GetHistogramData( |
56 histogram_type, histogram_name, tab) | 56 histogram_type, histogram_name, tab) |
57 | 57 |
58 last_histogram = histogram_util.GetHistogramFromDomAutomation( | 58 last_histogram = histogram.GetHistogramData( |
59 histogram_type, histogram_name, tab) | 59 histogram_type, histogram_name, tab) |
60 diff_histogram = histogram_util.SubtractHistogram(last_histogram, | 60 diff_histogram = histogram.SubtractHistogram(last_histogram, |
61 first_histogram) | 61 first_histogram) |
62 | 62 |
63 results.AddSummary(histogram_name, '', diff_histogram, | 63 results.AddSummary(histogram_name, '', diff_histogram, |
64 data_type='unimportant-histogram') | 64 data_type='unimportant-histogram') |
OLD | NEW |