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

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

Issue 1152763002: Fix tab_switching measurement bug. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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
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)
« no previous file with comments | « tools/perf/benchmarks/benchmark_smoke_unittest.py ('k') | tools/perf/measurements/tab_switching_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698