Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: tools/perf/measurements/tab_switching.py

Issue 2706483003: Add Multi-tab System Health Story (Closed)
Patch Set: Refactoring Benchmark TabSwitching Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/perf/benchmarks/tab_switching.py ('k') | tools/perf/measurements/tab_switching_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/measurements/tab_switching.py
diff --git a/tools/perf/measurements/tab_switching.py b/tools/perf/measurements/tab_switching.py
index dd64dfa0d2f583d17afc72b67146ef3b9351c045..5a6e1c3fea85232aba45ed17a1db5f4833197328 100644
--- a/tools/perf/measurements/tab_switching.py
+++ b/tools/perf/measurements/tab_switching.py
@@ -10,10 +10,8 @@ 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
from telemetry.page import legacy_page_test
from telemetry.value import histogram
from telemetry.value import histogram_util
@@ -21,6 +19,7 @@ from telemetry.value import histogram_util
from metrics import keychain_metric
from metrics import power
+
# TODO: Revisit this test once multitab support is finalized.
@@ -33,6 +32,7 @@ class TabSwitching(legacy_page_test.LegacyPageTest):
super(TabSwitching, self).__init__()
self.first_page_in_storyset = True
self._power_metric = None
+ self._first_histogram = None
def CustomizeBrowserOptions(self, options):
keychain_metric.KeychainMetric.CustomizeBrowserOptions(options)
@@ -45,76 +45,35 @@ class TabSwitching(legacy_page_test.LegacyPageTest):
power.PowerMetric.CustomizeBrowserOptions(options)
def WillStartBrowser(self, platform):
- self.first_page_in_storyset = True
self._power_metric = power.PowerMetric(platform, TabSwitching.SAMPLE_TIME)
- def TabForPage(self, page, browser):
- del page # unused
- if self.first_page_in_storyset:
- # The initial browser window contains a single tab, navigate that tab
- # rather than creating a new one.
- self.first_page_in_storyset = False
- return browser.tabs[0]
-
- return browser.tabs.New()
+ @classmethod
+ def _GetTabSwitchHistogram(cls, tab_to_switch):
+ histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
+ histogram_type = histogram_util.BROWSER_HISTOGRAM
+ return histogram_util.GetHistogram(
+ histogram_type, histogram_name, tab_to_switch)
- def StopBrowserAfterPage(self, browser, page):
- # Restart the browser after the last page in the pageset.
- return len(browser.tabs) >= len(page.story_set.stories)
+ def DidNavigateToPage(self, page, tab):
+ """record the starting histogram"""
+ self._first_histogram = self._GetTabSwitchHistogram(tab)
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."""
- 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 browser.platform.CanMonitorPower():
+ """record the ending histogram for the tab switching metric."""
+ if tab.browser.platform.CanMonitorPower():
self._power_metric.Start(page, tab)
time.sleep(TabSwitching.SAMPLE_TIME)
self._power_metric.Stop(page, tab)
self._power_metric.AddResults(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)
- prev_histogram = first_histogram
-
- for tab_to_switch in browser.tabs:
- tab_to_switch.Activate()
- def _IsDone():
- # pylint: disable=W0640
- cur_histogram = histogram_util.GetHistogram(
- histogram_type, histogram_name, tab_to_switch)
- diff_histogram = histogram_util.SubtractHistogram(
- cur_histogram, prev_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_to_switch)
-
- last_histogram = prev_histogram
+ last_histogram = self._GetTabSwitchHistogram(tab)
total_diff_histogram = histogram_util.SubtractHistogram(last_histogram,
- first_histogram)
+ self._first_histogram)
+ display_name = 'MPArch_RWH_TabSwitchPaintDuration'
results.AddSummaryValue(
histogram.HistogramValue(None, display_name, 'ms',
- raw_value_json=total_diff_histogram,
- important=False))
+ raw_value_json=total_diff_histogram,
+ important=False))
keychain_metric.KeychainMetric().AddResults(tab, results)
« no previous file with comments | « tools/perf/benchmarks/tab_switching.py ('k') | tools/perf/measurements/tab_switching_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698