1 # Copyright 2015 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
.core
.platform
import tracing_category_filter
6 from telemetry
.core
.platform
import tracing_options
7 from telemetry
.page
import page_test
8 from telemetry
.timeline
import model
9 from telemetry
.value
import scalar
12 class DrawProperties(page_test
.PageTest
):
14 super(DrawProperties
, self
).__init
__(
15 action_name_to_run
='RunPageInteractions')
17 def CustomizeBrowserOptions(self
, options
):
18 options
.AppendExtraBrowserArgs([
19 '--enable-property-tree-verification',
20 '--enable-prefer-compositing-to-lcd-text',
23 def WillNavigateToPage(self
, page
, tab
):
24 options
= tracing_options
.TracingOptions()
25 options
.enable_chrome_trace
= True
26 category_filter
= tracing_category_filter
.TracingCategoryFilter(
27 'disabled-by-default-cc.debug.cdp-perf')
28 tab
.browser
.platform
.tracing_controller
.Start(options
, category_filter
)
30 def ComputeAverageAndSumOfDurations(self
, timeline_model
, name
):
31 events
= timeline_model
.GetAllEventsOfName(name
)
32 event_durations
= [d
.duration
for d
in events
]
33 assert event_durations
, 'Failed to find durations'
35 duration_sum
= sum(event_durations
)
36 duration_count
= len(event_durations
)
37 duration_avg
= duration_sum
/ duration_count
38 return (duration_avg
, duration_sum
)
40 def ValidateAndMeasurePage(self
, page
, tab
, results
):
41 timeline_data
= tab
.browser
.platform
.tracing_controller
.Stop()
42 timeline_model
= model
.TimelineModel(timeline_data
)
44 (cdp_avg
, cdp_sum
) = self
.ComputeAverageAndSumOfDurations(
46 "LayerTreeHostCommon::CalculateDrawProperties");
48 (pt_avg
, pt_sum
) = self
.ComputeAverageAndSumOfDurations(
50 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees");
52 reduction
= 100.0 * (1.0 - (pt_sum
/ cdp_sum
))
54 results
.AddValue(scalar
.ScalarValue(
55 results
.current_page
, 'CDP_reduction', ' %', reduction
,
56 description
='Reduction in CDP cost with property trees'))
58 results
.AddValue(scalar
.ScalarValue(
59 results
.current_page
, 'CDP_avg_cost', 'ms', cdp_avg
,
60 description
='Average time spent in CDP'))
62 results
.AddValue(scalar
.ScalarValue(
63 results
.current_page
, 'PT_avg_cost', 'ms', pt_avg
,
64 description
='Average time spent processing property trees'))
66 def CleanUpAfterPage(self
, page
, tab
):
67 tracing_controller
= tab
.browser
.platform
.tracing_controller
68 if tracing_controller
.is_tracing_running
:
69 tracing_controller
.Stop()