| Index: tools/perf/measurements/tab_switching.py
|
| diff --git a/tools/perf/measurements/tab_switching.py b/tools/perf/measurements/tab_switching.py
|
| index d4110e17251a6b834de81b0acd198d631a5224bb..32243b4cdef424fa5f1dc48f609eabb19a3a1b4f 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
|
| @@ -59,49 +60,57 @@ class TabSwitching(page_test.PageTest):
|
| # Restart the browser after the last page in the pageset.
|
| return len(browser.tabs) >= len(page.page_set.pages)
|
|
|
| - def ValidateAndMeasurePage(self, page, tab, results):
|
| + def ValidateAndMeasurePage(self, page, last_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.page_set.pages):
|
| + browser = last_tab.browser
|
| + if len(browser.tabs) != len(page.page_set.pages):
|
| return
|
|
|
| # Measure power usage of tabs after quiescence.
|
| - util.WaitFor(tab.HasReachedQuiescence, 60)
|
| + util.WaitFor(last_tab.HasReachedQuiescence, 60)
|
|
|
| - if tab.browser.platform.CanMonitorPower():
|
| - self._power_metric.Start(page, tab)
|
| + if browser.platform.CanMonitorPower():
|
| + self._power_metric.Start(page, last_tab)
|
| time.sleep(TabSwitching.SAMPLE_TIME)
|
| - self._power_metric.Stop(page, tab)
|
| - self._power_metric.AddResults(tab, results,)
|
| + self._power_metric.Stop(page, last_tab)
|
| + self._power_metric.AddResults(last_tab, results,)
|
|
|
| histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
|
| histogram_type = histogram_util.BROWSER_HISTOGRAM
|
| display_name = 'MPArch_RWH_TabSwitchPaintDuration'
|
| first_histogram = histogram_util.GetHistogram(
|
| - histogram_type, histogram_name, tab)
|
| + histogram_type, histogram_name, last_tab)
|
| prev_histogram = first_histogram
|
|
|
| - for i in xrange(len(tab.browser.tabs)):
|
| - t = tab.browser.tabs[i]
|
| - t.Activate()
|
| + for i in xrange(len(browser.tabs)):
|
| + # Note that browser.tabs iterable does not return tab object but tab id.
|
| + # (http://crbug.com/473202)
|
| + tab = browser.tabs[i]
|
| + tab.Activate()
|
| def _IsDone():
|
| cur_histogram = histogram_util.GetHistogram(
|
| histogram_type, histogram_name, tab)
|
| 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)
|
| +
|
| + # 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)
|
|
|
| - last_histogram = histogram_util.GetHistogram(
|
| - histogram_type, histogram_name, tab)
|
| - diff_histogram = histogram_util.SubtractHistogram(last_histogram,
|
| - first_histogram)
|
| -
|
| + 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)
|
| + keychain_metric.KeychainMetric().AddResults(last_tab, results)
|
|
|