From fbd947210ecfb42637eca91ceef059f40eea9c0d Mon Sep 17 00:00:00 2001 From: nednguyen Date: Thu, 16 Apr 2015 16:58:56 -0700 Subject: [PATCH] Move all the page actions from repaint measurements to repaint pages. This is due to 2 reasons: + Page specific logic should belong to page, not page test. + Simplify the repaint measurement control code, which make it easier to port repaint to TimelineBasedMeasurement. Trybot link for repaint.gpu_rasterization.key_mobile_sites_repaint: https://codereview.chromium.org/1098543002 BUG=444703, 455391 Review URL: https://codereview.chromium.org/1089223003 Cr-Commit-Position: refs/heads/master@{#325558} --- tools/perf/benchmarks/repaint.py | 10 +++-- tools/perf/measurements/repaint.py | 40 +------------------ tools/perf/measurements/repaint_unittest.py | 4 +- tools/perf/page_sets/key_mobile_sites_repaint.py | 51 ++++++++++++++---------- tools/perf/page_sets/repaint_helpers.py | 46 +++++++++++++++++++++ tools/perf/page_sets/top_25_repaint.py | 24 +++++++---- 6 files changed, 102 insertions(+), 73 deletions(-) create mode 100644 tools/perf/page_sets/repaint_helpers.py diff --git a/tools/perf/benchmarks/repaint.py b/tools/perf/benchmarks/repaint.py index cce589d84a4f..7cebc5da9100 100644 --- a/tools/perf/benchmarks/repaint.py +++ b/tools/perf/benchmarks/repaint.py @@ -27,16 +27,18 @@ class _Repaint(benchmark.Benchmark): def Name(cls): return 'repaint' + def CreateUserStorySet(self, options): + return page_sets.KeyMobileSitesRepaintPageSet( + options.mode, options.width, options.height) + def CreatePageTest(self, options): - return repaint_measurement.Repaint(options.mode, options.width, - options.height) + return repaint_measurement.Repaint() @benchmark.Enabled('android') class RepaintKeyMobileSites(_Repaint): """Measures repaint performance on the key mobile sites. http://www.chromium.org/developers/design-documents/rendering-benchmarks""" - page_set = page_sets.KeyMobileSitesRepaintPageSet @classmethod def Name(cls): @@ -50,9 +52,9 @@ class RepaintGpuRasterizationKeyMobileSites(_Repaint): http://www.chromium.org/developers/design-documents/rendering-benchmarks""" tag = 'gpu_rasterization' - page_set = page_sets.KeyMobileSitesRepaintPageSet def CustomizeBrowserOptions(self, options): silk_flags.CustomizeBrowserOptionsForGpuRasterization(options) + @classmethod def Name(cls): return 'repaint.gpu_rasterization.key_mobile_sites_repaint' diff --git a/tools/perf/measurements/repaint.py b/tools/perf/measurements/repaint.py index 14bb032b1c11..ec4e5f1ba012 100644 --- a/tools/perf/measurements/repaint.py +++ b/tools/perf/measurements/repaint.py @@ -8,13 +8,9 @@ from measurements import smoothness_controller class Repaint(page_test.PageTest): - def __init__(self, mode='viewport', width=None, height=None): + def __init__(self): super(Repaint, self).__init__() self._smoothness_controller = None - self._micro_benchmark_id = None - self._mode = mode - self._width = width - self._height = height def CustomizeBrowserOptions(self, options): options.AppendExtraBrowserArgs([ @@ -29,42 +25,8 @@ class Repaint(page_test.PageTest): auto_issuing_marker=False) self._smoothness_controller.SetUp(page, tab) self._smoothness_controller.Start(tab) - # Rasterize only what's visible. - tab.ExecuteJavaScript( - 'chrome.gpuBenchmarking.setRasterizeOnlyVisibleContent();') - - args = {} - args['mode'] = self._mode - if self._width: - args['width'] = self._width - if self._height: - args['height'] = self._height - - # Enque benchmark - tab.ExecuteJavaScript(""" - window.benchmark_results = {}; - window.benchmark_results.id = - chrome.gpuBenchmarking.runMicroBenchmark( - "invalidation_benchmark", - function(value) {}, - """ + str(args) + """ - ); - """) - - self._micro_benchmark_id = tab.EvaluateJavaScript( - 'window.benchmark_results.id') - if (not self._micro_benchmark_id): - raise page_test.MeasurementFailure( - 'Failed to schedule invalidation_benchmark.') def DidRunActions(self, page, tab): - tab.ExecuteJavaScript(""" - window.benchmark_results.message_handled = - chrome.gpuBenchmarking.sendMessageToMicroBenchmark( - """ + str(self._micro_benchmark_id) + """, { - "notify_done": true - }); - """) self._smoothness_controller.Stop(tab) def ValidateAndMeasurePage(self, page, tab, results): diff --git a/tools/perf/measurements/repaint_unittest.py b/tools/perf/measurements/repaint_unittest.py index 145d65b2caa9..535c758214c2 100644 --- a/tools/perf/measurements/repaint_unittest.py +++ b/tools/perf/measurements/repaint_unittest.py @@ -9,6 +9,7 @@ from telemetry.unittest_util import options_for_unittests from telemetry.unittest_util import page_test_test_case from measurements import repaint +from page_sets import repaint_helpers class TestRepaintPage(page_module.Page): @@ -17,8 +18,7 @@ class TestRepaintPage(page_module.Page): page_set, base_dir) def RunPageInteractions(self, action_runner): - with action_runner.CreateInteraction('Repaint'): - action_runner.RepaintContinuously(seconds=2) + repaint_helpers.Repaint(action_runner) class RepaintUnitTest(page_test_test_case.PageTestTestCase): diff --git a/tools/perf/page_sets/key_mobile_sites_repaint.py b/tools/perf/page_sets/key_mobile_sites_repaint.py index 6cb996318c61..44b507d810fe 100644 --- a/tools/perf/page_sets/key_mobile_sites_repaint.py +++ b/tools/perf/page_sets/key_mobile_sites_repaint.py @@ -5,39 +5,42 @@ from telemetry.page import page as page_module from telemetry.page import page_set as page_set_module from page_sets import key_mobile_sites_pages +from page_sets import repaint_helpers -def _RepaintContinously(action_runner): - with action_runner.CreateInteraction('Repaint'): - action_runner.RepaintContinuously(seconds=5) - -def _CreatePageClassWithRepaintInteractions(page_cls): +def _CreatePageClassWithRepaintInteractions(page_cls, mode, height, width): class DerivedRepaintPage(page_cls): # pylint: disable=W0232 def RunPageInteractions(self, action_runner): - _RepaintContinously(action_runner) + repaint_helpers.Repaint( + action_runner, mode=mode, width=width, height=height) + return DerivedRepaintPage class KeyMobileSitesRepaintPage(page_module.Page): - def __init__(self, url, page_set, name='', labels=None): + def __init__(self, url, page_set, mode, height, width, name='', labels=None): super(KeyMobileSitesRepaintPage, self).__init__( url=url, page_set=page_set, name=name, credentials_path='data/credentials.json', labels=labels) self.user_agent_type = 'mobile' self.archive_data_file = 'data/key_mobile_sites_repaint.json' + self._mode = mode + self._width = width + self._height = height def RunPageInteractions(self, action_runner): - _RepaintContinously(action_runner) + repaint_helpers.Repaint( + action_runner, mode=self._mode, width=self._width, height=self._height) class KeyMobileSitesRepaintPageSet(page_set_module.PageSet): """ Key mobile sites with repaint interactions. """ - def __init__(self): + def __init__(self, mode='viewport', width=None, height=None): super(KeyMobileSitesRepaintPageSet, self).__init__( user_agent_type='mobile', archive_data_file='data/key_mobile_sites_repaint.json', @@ -66,37 +69,39 @@ class KeyMobileSitesRepaintPageSet(page_set_module.PageSet): ] for page_class in predefined_page_classes: self.AddUserStory( - _CreatePageClassWithRepaintInteractions(page_class)(self)) + _CreatePageClassWithRepaintInteractions( + page_class, mode=mode, height=height, width=width)(self)) # Add pages with custom labels. # Why: Top news site. self.AddUserStory(KeyMobileSitesRepaintPage( - url='http://nytimes.com/', page_set=self, labels=['fastpath'])) + url='http://nytimes.com/', page_set=self, labels=['fastpath'], + mode=mode, height=height, width=width)) # Why: Image-heavy site. self.AddUserStory(KeyMobileSitesRepaintPage( - url='http://cuteoverload.com', page_set=self, labels=['fastpath'])) + url='http://cuteoverload.com', page_set=self, labels=['fastpath'], + mode=mode, height=height, width=width)) # Why: #11 (Alexa global), google property; some blogger layouts # have infinite scroll but more interesting. self.AddUserStory(KeyMobileSitesRepaintPage( url='http://googlewebmastercentral.blogspot.com/', - page_set=self, name='Blogger')) + page_set=self, name='Blogger', mode=mode, height=height, width=width)) # Why: #18 (Alexa global), Picked an interesting post """ self.AddUserStory(KeyMobileSitesRepaintPage( # pylint: disable=line-too-long url='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/', page_set=self, - name='Wordpress')) + name='Wordpress', mode=mode, height=height, width=width)) # Why: #6 (Alexa) most visited worldwide, picked an interesting page self.AddUserStory(KeyMobileSitesRepaintPage( url='http://en.wikipedia.org/wiki/Wikipedia', page_set=self, - name='Wikipedia (1 tab)')) - + name='Wikipedia (1 tab)', mode=mode, height=height, width=width)) # Why: #8 (Alexa global), picked an interesting page # Forbidden (Rate Limit Exceeded) @@ -107,7 +112,7 @@ class KeyMobileSitesRepaintPageSet(page_set_module.PageSet): self.AddUserStory(KeyMobileSitesRepaintPage( url='http://pinterest.com', page_set=self, - name='Pinterest')) + name='Pinterest', mode=mode, height=height, width=width)) # Why: #1 sports. # Fails often; crbug.com/249722' @@ -119,17 +124,20 @@ class KeyMobileSitesRepaintPageSet(page_set_module.PageSet): # url='http://forecast.io', page_set=self)) # Why: crbug.com/169827 self.AddUserStory(KeyMobileSitesRepaintPage( - url='http://slashdot.org/', page_set=self, labels=['fastpath'])) + url='http://slashdot.org/', page_set=self, labels=['fastpath'], + mode=mode, width=width, height=height)) # Why: #5 Alexa news """ self.AddUserStory(KeyMobileSitesRepaintPage( url='http://www.reddit.com/r/programming/comments/1g96ve', - page_set=self, labels=['fastpath'])) + page_set=self, labels=['fastpath'], + mode=mode, width=width, height=height)) # Why: Problematic use of fixed position elements """ self.AddUserStory(KeyMobileSitesRepaintPage( - url='http://www.boingboing.net', page_set=self, labels=['fastpath'])) + url='http://www.boingboing.net', page_set=self, labels=['fastpath'], + mode=mode, width=width, height=height)) # Add simple pages with no custom navigation logic or labels. urls_list = [ @@ -183,4 +191,5 @@ class KeyMobileSitesRepaintPageSet(page_set_module.PageSet): ] for url in urls_list: - self.AddUserStory(KeyMobileSitesRepaintPage(url, self)) + self.AddUserStory(KeyMobileSitesRepaintPage( + url, self, mode=mode, height=height, width=width)) diff --git a/tools/perf/page_sets/repaint_helpers.py b/tools/perf/page_sets/repaint_helpers.py new file mode 100644 index 000000000000..66442fa5a4e7 --- /dev/null +++ b/tools/perf/page_sets/repaint_helpers.py @@ -0,0 +1,46 @@ +# Copyright 2014 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. + +from telemetry.page import page_test + + +def Repaint(action_runner, mode='viewport', width=None, height=None): + # Rasterize only what's visible. + action_runner.ExecuteJavaScript( + 'chrome.gpuBenchmarking.setRasterizeOnlyVisibleContent();') + + args = {} + args['mode'] = mode + if width: + args['width'] = width + if height: + args['height'] = height + + # Enque benchmark + action_runner.ExecuteJavaScript(""" + window.benchmark_results = {}; + window.benchmark_results.id = + chrome.gpuBenchmarking.runMicroBenchmark( + "invalidation_benchmark", + function(value) {}, + """ + str(args) + """ + ); + """) + + micro_benchmark_id = action_runner.EvaluateJavaScript( + 'window.benchmark_results.id') + if (not micro_benchmark_id): + raise page_test.MeasurementFailure( + 'Failed to schedule invalidation_benchmark.') + + with action_runner.CreateInteraction('Repaint'): + action_runner.RepaintContinuously(seconds=5) + + action_runner.ExecuteJavaScript(""" + window.benchmark_results.message_handled = + chrome.gpuBenchmarking.sendMessageToMicroBenchmark( + """ + str(micro_benchmark_id) + """, { + "notify_done": true + }); + """) diff --git a/tools/perf/page_sets/top_25_repaint.py b/tools/perf/page_sets/top_25_repaint.py index 24a36d6aec36..d3f2b9bcdb92 100644 --- a/tools/perf/page_sets/top_25_repaint.py +++ b/tools/perf/page_sets/top_25_repaint.py @@ -5,27 +5,35 @@ from telemetry.page import page as page_module from telemetry.page import page_set as page_set_module from page_sets import top_pages +from page_sets import repaint_helpers class TopRepaintPage(page_module.Page): - def __init__(self, url, page_set, name='', credentials=None): + def __init__(self, url, page_set, mode, width, height, name='', + credentials=None): super(TopRepaintPage, self).__init__( url=url, page_set=page_set, name=name, credentials_path='data/credentials.json') self.user_agent_type = 'desktop' self.archive_data_file = 'data/top_25_repaint.json' self.credentials = credentials + self._mode = mode + self._width = width + self._height = height def RunPageInteractions(self, action_runner): - action_runner.RepaintContinuously(seconds=5) + repaint_helpers.Repaint( + action_runner, mode=self._mode, width=self._width, height=self._height) -def _CreatePageClassWithRepaintInteractions(page_cls): +def _CreatePageClassWithRepaintInteractions(page_cls, mode, width, height): class DerivedRepaintPage(page_cls): # pylint: disable=W0232 def RunPageInteractions(self, action_runner): - action_runner.RepaintContinuously(seconds=5) + repaint_helpers.Repaint( + action_runner, mode=mode, width=width, height=height) + return DerivedRepaintPage @@ -33,7 +41,7 @@ class Top25RepaintPageSet(page_set_module.PageSet): """ Pages hand-picked for 2012 CrOS scrolling tuning efforts. """ - def __init__(self): + def __init__(self, mode='viewport', width=None, height=None): super(Top25RepaintPageSet, self).__init__( user_agent_type='desktop', archive_data_file='data/top_25_repaint.json', @@ -60,7 +68,8 @@ class Top25RepaintPageSet(page_set_module.PageSet): ] for cl in top_page_classes: - self.AddUserStory(_CreatePageClassWithRepaintInteractions(cl)(self)) + self.AddUserStory(_CreatePageClassWithRepaintInteractions( + cl, mode=mode, width=width, height=height)(self)) other_urls = [ # Why: #1 news worldwide (Alexa global) @@ -83,4 +92,5 @@ class Top25RepaintPageSet(page_set_module.PageSet): ] for url in other_urls: - self.AddUserStory(TopRepaintPage(url, self)) + self.AddUserStory( + TopRepaintPage(url, self, mode=mode, height=height, width=width)) -- 2.11.4.GIT