Commit 43487fc8 authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

tab_switching: Switch over to the new tbm metric.

Switch the tab_switching benchmark to use the new TBMv2 metric for
measuring tab-switching latency.

BUG=802104

Change-Id: I7ab9610811b842feacf3a28845a2b267de4bfd20
Reviewed-on: https://chromium-review.googlesource.com/886003Reviewed-by: default avatarNed Nguyen <nednguyen@google.com>
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531912}
parent cdb51726
......@@ -6,10 +6,11 @@ import os
from core import perf_benchmark
from measurements import tab_switching
from page_sets.system_health import multi_tab_stories
from telemetry import benchmark
from telemetry import story
from telemetry.timeline import chrome_trace_category_filter
from telemetry.web_perf import timeline_based_measurement
@benchmark.Owner(emails=['vovoy@chromium.org'],
......@@ -22,7 +23,6 @@ class TabSwitchingTypical25(perf_benchmark.PerfBenchmark):
tabs, waits for them to load, and then switches to each tab and records the
metric. The pages were chosen from Alexa top ranking sites.
"""
test = tab_switching.TabSwitching
SUPPORTED_PLATFORMS = [story.expectations.ALL_DESKTOP]
@classmethod
......@@ -39,6 +39,13 @@ class TabSwitchingTypical25(perf_benchmark.PerfBenchmark):
story_set, False, options.tabset_repeat))
return story_set
def CreateCoreTimelineBasedMeasurementOptions(self):
category_filter = chrome_trace_category_filter.ChromeTraceCategoryFilter()
category_filter.AddIncludedCategory('latency')
options = timeline_based_measurement.Options(category_filter)
options.SetTimelineBasedMetrics(['tabsMetric'])
return options
@classmethod
def Name(cls):
return 'tab_switching.typical_25'
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""The tab switching measurement.
This measurement opens pages in different tabs. After all the tabs have opened,
it cycles through each tab in sequence, and records a histogram of the time
between when a tab was first requested to be shown, and when it was painted.
Power usage is also measured.
"""
from telemetry.page import legacy_page_test
from telemetry.value import histogram
from telemetry.value import histogram_util
from metrics import keychain_metric
class TabSwitching(legacy_page_test.LegacyPageTest):
def __init__(self):
super(TabSwitching, self).__init__()
self._first_histogram = None
def CustomizeBrowserOptions(self, options):
keychain_metric.KeychainMetric.CustomizeBrowserOptions(options)
options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings'])
@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 DidNavigateToPage(self, page, tab):
"""record the starting histogram"""
self._first_histogram = self._GetTabSwitchHistogram(tab)
def ValidateAndMeasurePage(self, page, tab, results):
"""record the ending histogram for the tab switching metric."""
last_histogram = self._GetTabSwitchHistogram(tab)
total_diff_histogram = histogram_util.SubtractHistogram(last_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))
keychain_metric.KeychainMetric().AddResults(tab, results)
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import contextlib
from measurements import tab_switching
import mock
from page_sets.system_health import multi_tab_stories
from telemetry import decorators
from telemetry import story as story_module
from telemetry.internal.results import page_test_results
from telemetry.testing import page_test_test_case
from telemetry.testing import options_for_unittests
from telemetry.value import histogram
class BrowserForTest(object):
def __init__(self):
self.tabs = []
self.platform = mock.MagicMock()
self.platform.CanMonitorPower = mock.Mock(return_value=False)
def AddTab(self, tab):
tab.browser = self
self.tabs.append(tab)
class StorySetForTest(object):
def __init__(self):
self.stories = []
def AddStory(self, story):
story.story_set = self
self.stories.append(story)
INTEGRATION_TEST_TAB_COUNT = 3
class EmptyMultiTabStory(multi_tab_stories.MultiTabStory):
NAME = 'multitab:test:empty'
URL_LIST = ['about:blank'] * INTEGRATION_TEST_TAB_COUNT
URL = URL_LIST[0]
class TabSwitchingUnittest(page_test_test_case.PageTestTestCase):
@staticmethod
def MakeStoryForTest():
story = mock.MagicMock()
story.story_set = None
return story
@staticmethod
def MakeTabForTest():
tab = mock.MagicMock()
tab.browser = None
tab.HasReachedQuiescence = mock.Mock(return_value=True)
return tab
def testIsDone(self):
"""Tests ValidateAndMeasurePage, specifically _IsDone check."""
measure = tab_switching.TabSwitching()
# For sanity check: #tabs == #stories
story_set = StorySetForTest()
story_set.AddStory(self.MakeStoryForTest())
story_set.AddStory(self.MakeStoryForTest())
# Set up a browser with two tabs open
browser = BrowserForTest()
tab_0 = self.MakeTabForTest()
browser.AddTab(tab_0)
tab_1 = self.MakeTabForTest()
browser.AddTab(tab_1)
# Mock histogram result to test _IsDone really works.
expected_histogram = [
# DidNavigateToPage() calls GetHistogram() once
'{"count": 0, "buckets": []}',
# ValidateAndMeasurePage() calls GetHistogram() once
'{"count": 2, "buckets": [{"low": 1, "high": 2, "count": 1},'
'{"low": 2, "high": 3, "count": 1}]}',
]
mock_get_histogram = mock.MagicMock(side_effect=expected_histogram)
with contextlib.nested(
mock.patch('telemetry.value.histogram_util.GetHistogram',
mock_get_histogram),
mock.patch('metrics.keychain_metric.KeychainMetric')):
measure.DidNavigateToPage(story_set.stories[0], browser.tabs[-1])
measure.ValidateAndMeasurePage(story_set.stories[0], browser.tabs[-1],
page_test_results.PageTestResults())
self.assertEqual(len(expected_histogram),
len(mock_get_histogram.mock_calls))
# The last tab is passed to DidNavigateToPage() and
# ValidateAndMeasurePage()
expected_calls = [mock.call(mock.ANY, mock.ANY, t) for t in
[browser.tabs[-1]] * 2]
self.assertEqual(expected_calls, mock_get_histogram.mock_calls)
@decorators.Enabled('has tabs')
@decorators.Disabled('mac')
@decorators.Disabled('android')
def testTabSwitching(self):
"""IT of TabSwitching measurement and multi-tab story"""
ps = story_module.StorySet()
ps.AddStory(EmptyMultiTabStory(ps, False))
measurement = tab_switching.TabSwitching()
options = options_for_unittests.GetCopy()
results = self.RunMeasurement(measurement, ps, options=options)
self.assertEquals(len(results.failures), 0)
self.assertEquals(len(results.all_summary_values), 1)
summary = results.all_summary_values[0]
self.assertIsInstance(summary, histogram.HistogramValue)
self.assertEquals(summary.name, 'MPArch_RWH_TabSwitchPaintDuration')
histogram_count = sum([b.count for b in summary.buckets])
self.assertEquals(histogram_count, INTEGRATION_TEST_TAB_COUNT)
histogram_mean = summary.GetRepresentativeNumber()
self.assertGreater(histogram_mean, 0)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment