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 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
47 'webkit.console', 'blink.console', 'benchmark', 'trace_event_overhead']
48 category_filter
= tracing_category_filter
.TracingCategoryFilter(
49 ','.join(custom_categories
))
51 options
= timeline_based_measurement
.Options(category_filter
)
52 options
.SetTimelineBasedMetrics([smoothness
.SmoothnessMetric()])
53 self
._tbm
= timeline_based_measurement
.TimelineBasedMeasurement(
54 options
, self
._results
_wrapper
)
55 self
._tbm
.WillRunStoryForPageTest(
56 tracing_controller
, page
.GetSyntheticDelayCategories())
58 def ValidateAndMeasurePage(self
, _
, tab
, results
):
59 tracing_controller
= tab
.browser
.platform
.tracing_controller
60 self
._tbm
.MeasureForPageTest(tracing_controller
, results
)
62 def DidRunPage(self
, platform
):
64 self
._tbm
.DidRunStoryForPageTest(platform
.tracing_controller
)
67 class Repaint(Smoothness
):
68 def CustomizeBrowserOptions(self
, options
):
69 options
.AppendExtraBrowserArgs([
70 '--enable-impl-side-painting',
71 '--enable-threaded-compositing',
72 '--enable-gpu-benchmarking'
75 class SmoothnessWithRestart(Smoothness
):
77 super(SmoothnessWithRestart
, self
).__init
__(
78 needs_browser_restart_after_each_page
=True)