| Index: tools/perf/measurements/tab_switching.py
|
| diff --git a/tools/perf/measurements/tab_switching.py b/tools/perf/measurements/tab_switching.py
|
| index a4f7ac017a91e3f7c29b686fda6eda86ea9e8ea6..9ab234f3e67d89d845c12d789313695f97edf75c 100644
|
| --- a/tools/perf/measurements/tab_switching.py
|
| +++ b/tools/perf/measurements/tab_switching.py
|
| @@ -10,6 +10,7 @@ between when a tab was first requested to be shown, and when it was painted.
|
| Power usage is also measured.
|
| """
|
|
|
| +import json
|
| import time
|
|
|
| from telemetry.core import util
|
| @@ -62,13 +63,17 @@ class TabSwitching(page_test.PageTest):
|
| def ValidateAndMeasurePage(self, page, tab, results):
|
| """On the last tab, cycle through each tab that was opened and then record
|
| a single histogram for the tab switching metric."""
|
| - if len(tab.browser.tabs) != len(page.story_set.stories):
|
| + browser = tab.browser
|
| + if len(browser.tabs) != len(page.story_set.stories):
|
| return
|
|
|
| + if browser.tabs < 2:
|
| + raise Exception('Should have at least two tabs for tab switching')
|
| +
|
| # Measure power usage of tabs after quiescence.
|
| util.WaitFor(tab.HasReachedQuiescence, 60)
|
|
|
| - if tab.browser.platform.CanMonitorPower():
|
| + if browser.platform.CanMonitorPower():
|
| self._power_metric.Start(page, tab)
|
| time.sleep(TabSwitching.SAMPLE_TIME)
|
| self._power_metric.Stop(page, tab)
|
| @@ -81,26 +86,31 @@ class TabSwitching(page_test.PageTest):
|
| histogram_type, histogram_name, tab)
|
| prev_histogram = first_histogram
|
|
|
| - for t in tab.browser.tabs:
|
| - t.Activate()
|
| + for tab_to_switch in browser.tabs:
|
| + tab_to_switch.Activate()
|
| def _IsDone():
|
| cur_histogram = histogram_util.GetHistogram(
|
| - histogram_type, histogram_name, tab)
|
| + histogram_type, histogram_name, tab_to_switch)
|
| diff_histogram = histogram_util.SubtractHistogram(
|
| cur_histogram, prev_histogram)
|
| - return diff_histogram
|
| + # TODO(deanliao): Add SubtractHistogramRawValue to process histogram
|
| + # object instead of JSON string.
|
| + diff_histogram_count = json.loads(diff_histogram).get('count', 0)
|
| + return diff_histogram_count > 0
|
| util.WaitFor(_IsDone, 30)
|
| - prev_histogram = histogram_util.GetHistogram(
|
| - histogram_type, histogram_name, tab)
|
|
|
| - last_histogram = histogram_util.GetHistogram(
|
| - histogram_type, histogram_name, tab)
|
| - diff_histogram = histogram_util.SubtractHistogram(last_histogram,
|
| - first_histogram)
|
| + # We need to get histogram again instead of getting cur_histogram as
|
| + # variables modified inside inner function cannot be retrieved. However,
|
| + # inner function can see external scope's variables.
|
| + prev_histogram = histogram_util.GetHistogram(
|
| + histogram_type, histogram_name, tab_to_switch)
|
|
|
| + last_histogram = prev_histogram
|
| + total_diff_histogram = histogram_util.SubtractHistogram(last_histogram,
|
| + first_histogram)
|
| results.AddSummaryValue(
|
| histogram.HistogramValue(None, display_name, 'ms',
|
| - raw_value_json=diff_histogram,
|
| + raw_value_json=total_diff_histogram,
|
| important=False))
|
|
|
| keychain_metric.KeychainMetric().AddResults(tab, results)
|
|
|