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
8 from telemetry
.web_perf
.metrics
import smoothness
11 class _CustomResultsWrapper(timeline_based_measurement
.ResultsWrapperInterface
):
13 super(_CustomResultsWrapper
, self
).__init
__()
14 self
._pages
_to
_tir
_labels
= {}
16 def _AssertNewValueHasSameInteractionLabel(self
, new_value
):
17 tir_label
= self
._pages
_to
_tir
_labels
.get(new_value
.page
)
19 assert tir_label
== self
._tir
_label
, (
20 'Smoothness measurement do not support multiple interaction record '
21 'labels per page yet. See crbug.com/453109 for more information.')
23 self
._pages
_to
_tir
_labels
[new_value
.page
] = self
._tir
_label
25 def AddValue(self
, value
):
26 self
._AssertNewValueHasSameInteractionLabel
(value
)
27 self
._results
.AddValue(value
)
30 class Smoothness(page_test
.PageTest
):
31 def __init__(self
, needs_browser_restart_after_each_page
=False):
32 super(Smoothness
, self
).__init
__(needs_browser_restart_after_each_page
)
33 self
._results
_wrapper
= _CustomResultsWrapper()
37 def CustomizeBrowserOptions(cls
, options
):
38 options
.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
39 options
.AppendExtraBrowserArgs('--touch-events=enabled')
40 options
.AppendExtraBrowserArgs('--running-performance-benchmark')
42 def WillNavigateToPage(self
, page
, tab
):
43 # Collect garbage from previous run several times to make the results more
45 for _
in xrange(0, 5):
47 tracing_controller
= tab
.browser
.platform
.tracing_controller
48 # FIXME: Remove webkit.console when blink.console lands in chromium and
49 # the ref builds are updated. crbug.com/386847
51 'webkit.console', 'blink.console', 'benchmark', 'trace_event_overhead']
52 category_filter
= tracing_category_filter
.TracingCategoryFilter(
53 ','.join(custom_categories
))
55 options
= timeline_based_measurement
.Options(category_filter
)
56 options
.SetTimelineBasedMetrics([smoothness
.SmoothnessMetric()])
57 self
._tbm
= timeline_based_measurement
.TimelineBasedMeasurement(
58 options
, self
._results
_wrapper
)
59 self
._tbm
.WillRunStoryForPageTest(
60 tracing_controller
, page
.GetSyntheticDelayCategories())
62 def ValidateAndMeasurePage(self
, _
, tab
, results
):
63 tracing_controller
= tab
.browser
.platform
.tracing_controller
64 self
._tbm
.MeasureForPageTest(tracing_controller
, results
)
66 def DidRunPage(self
, platform
):
68 self
._tbm
.DidRunStoryForPageTest(platform
.tracing_controller
)
71 class Repaint(Smoothness
):
72 def CustomizeBrowserOptions(self
, options
):
73 options
.AppendExtraBrowserArgs([
74 '--enable-impl-side-painting',
75 '--enable-threaded-compositing',
76 '--enable-gpu-benchmarking'
79 class SmoothnessWithRestart(Smoothness
):
81 super(SmoothnessWithRestart
, self
).__init
__(
82 needs_browser_restart_after_each_page
=True)