Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / tools / perf / measurements / smoothness.py
blob550398c0a02e3683801a4e7a20f3c2bcde156de0
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry.page import page_test
6 from telemetry.timeline import tracing_category_filter
7 from telemetry.web_perf import timeline_based_measurement
10 class _CustomResultsWrapper(timeline_based_measurement.ResultsWrapperInterface):
11 def __init__(self):
12 super(_CustomResultsWrapper, self).__init__()
13 self._pages_to_tir_labels = {}
15 def _AssertNewValueHasSameInteractionLabel(self, new_value):
16 tir_label = self._pages_to_tir_labels.get(new_value.page)
17 if tir_label:
18 assert tir_label == self._tir_label, (
19 'Smoothness measurement do not support multiple interaction record '
20 'labels per page yet. See crbug.com/453109 for more information.')
21 else:
22 self._pages_to_tir_labels[new_value.page] = self._tir_label
24 def AddValue(self, value):
25 self._AssertNewValueHasSameInteractionLabel(value)
26 self._results.AddValue(value)
29 class Smoothness(page_test.PageTest):
30 def __init__(self, needs_browser_restart_after_each_page=False):
31 super(Smoothness, self).__init__(needs_browser_restart_after_each_page)
32 self._results_wrapper = _CustomResultsWrapper()
33 self._tbm = None
35 @classmethod
36 def CustomizeBrowserOptions(cls, options):
37 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
38 options.AppendExtraBrowserArgs('--touch-events=enabled')
39 options.AppendExtraBrowserArgs('--running-performance-benchmark')
40 options.AppendExtraBrowserArgs('--js-flags=--expose-gc')
42 def WillNavigateToPage(self, page, tab):
43 tracing_controller = tab.browser.platform.tracing_controller
44 # FIXME: Remove webkit.console when blink.console lands in chromium and
45 # the ref builds are updated. crbug.com/386847
46 custom_categories = [
47 'webkit.console', 'blink.console', 'benchmark', 'trace_event_overhead']
48 category_filter = tracing_category_filter.TracingCategoryFilter(
49 ','.join(custom_categories))
50 self._tbm = timeline_based_measurement.TimelineBasedMeasurement(
51 timeline_based_measurement.Options(category_filter),
52 self._results_wrapper)
53 self._tbm.WillRunStoryForPageTest(
54 tracing_controller, page.GetSyntheticDelayCategories())
56 def ValidateAndMeasurePage(self, _, tab, results):
57 tracing_controller = tab.browser.platform.tracing_controller
58 self._tbm.MeasureForPageTest(tracing_controller, results)
60 def DidRunPage(self, platform):
61 if self._tbm:
62 self._tbm.DidRunStoryForPageTest(platform.tracing_controller)
65 class Repaint(Smoothness):
66 def CustomizeBrowserOptions(self, options):
67 options.AppendExtraBrowserArgs([
68 '--enable-impl-side-painting',
69 '--enable-threaded-compositing',
70 '--enable-gpu-benchmarking'
73 class SmoothnessWithRestart(Smoothness):
74 def __init__(self):
75 super(SmoothnessWithRestart, self).__init__(
76 needs_browser_restart_after_each_page=True)