1 # Copyright 2014 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.
7 from measurements
import smoothness_controller
8 from measurements
import timeline_controller
9 from telemetry
.core
.platform
import tracing_category_filter
10 from telemetry
.core
.platform
import tracing_options
11 from telemetry
.page
import page_test
12 from telemetry
.page
.actions
import action_runner
13 from telemetry
.timeline
.model
import TimelineModel
14 from telemetry
.util
import statistics
15 from telemetry
.value
import list_of_scalar_values
16 from telemetry
.value
import scalar
17 from telemetry
.value
import trace
20 _CR_RENDERER_MAIN
= 'CrRendererMain'
21 _RUN_SMOOTH_ACTIONS
= 'RunSmoothAllActions'
22 _NAMES_TO_DUMP
= ['oilpan_precise_mark',
23 'oilpan_precise_lazy_sweep',
24 'oilpan_precise_complete_sweep',
25 'oilpan_conservative_mark',
26 'oilpan_conservative_lazy_sweep',
27 'oilpan_conservative_complete_sweep',
30 def _AddTracingResults(events
, results
):
33 for name
in _NAMES_TO_DUMP
:
41 complete_sweep_time
= 0
43 duration
= event
.thread_duration
or event
.duration
44 if event
.name
== 'ThreadHeap::coalesce':
45 values
['oilpan_coalesce'].append(duration
)
47 if event
.name
== 'Heap::collectGarbage':
48 if not gc_type
is None and not forced
:
49 values
['oilpan_%s_mark' % gc_type
].append(mark_time
)
50 values
['oilpan_%s_lazy_sweep' % gc_type
].append(lazy_sweep_time
)
51 values
['oilpan_%s_complete_sweep' % gc_type
].append(complete_sweep_time
)
53 gc_type
= 'precise' if event
.args
['precise'] else 'conservative'
54 forced
= event
.args
['forced']
57 complete_sweep_time
= 0
59 if event
.name
== 'ThreadHeap::lazySweepPages':
60 lazy_sweep_time
+= duration
62 if event
.name
== 'ThreadState::completeSweep':
63 complete_sweep_time
+= duration
66 if not gc_type
is None and not forced
:
67 values
['oilpan_%s_mark' % gc_type
].append(mark_time
)
68 values
['oilpan_%s_lazy_sweep' % gc_type
].append(lazy_sweep_time
)
69 values
['oilpan_%s_complete_sweep' % gc_type
].append(complete_sweep_time
)
72 page
= results
.current_page
74 for name
in _NAMES_TO_DUMP
:
76 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
77 page
, name
, unit
, values
[name
]))
78 results
.AddValue(scalar
.ScalarValue(
79 page
, name
+ '_max', unit
, max(values
[name
])))
80 results
.AddValue(scalar
.ScalarValue(
81 page
, name
+ '_total', unit
, sum(values
[name
])))
83 # Summarize marking time
85 for gc_type
in ['precise', 'conservative']:
86 total_mark_time
+= sum(values
['oilpan_%s_mark' % gc_type
])
88 scalar
.ScalarValue(page
, 'oilpan_mark', unit
, total_mark_time
))
90 # Summarize sweeping time
92 for do_type
in ['lazy_sweep', 'complete_sweep']:
94 for gc_type
in ['precise', 'conservative']:
95 sweep_time
+= sum(values
['oilpan_%s_%s' % (gc_type
, do_type
)])
96 key
= 'oilpan_%s' % do_type
97 results
.AddValue(scalar
.ScalarValue(page
, key
, unit
, sweep_time
))
98 total_sweep_time
+= sweep_time
100 scalar
.ScalarValue(page
, 'oilpan_sweep', unit
, total_sweep_time
))
104 gc_time
+= sum(values
[key
])
105 results
.AddValue(scalar
.ScalarValue(page
, 'oilpan_gc', unit
, gc_time
))
108 class _OilpanGCTimesBase(page_test
.PageTest
):
109 def __init__(self
, action_name
= ''):
110 super(_OilpanGCTimesBase
, self
).__init
__(action_name
)
111 self
._timeline
_model
= None
113 def WillNavigateToPage(self
, page
, tab
):
114 # FIXME: Remove webkit.console when blink.console lands in chromium and
115 # the ref builds are updated. crbug.com/386847
116 categories
= ['webkit.console', 'blink.console', 'blink_gc']
117 category_filter
= tracing_category_filter
.TracingCategoryFilter()
119 category_filter
.AddIncludedCategory(c
)
120 options
= tracing_options
.TracingOptions()
121 options
.enable_chrome_trace
= True
122 tab
.browser
.platform
.tracing_controller
.Start(options
, category_filter
,
125 def DidRunActions(self
, page
, tab
):
126 timeline_data
= tab
.browser
.platform
.tracing_controller
.Stop()
127 self
._timeline
_model
= TimelineModel(timeline_data
)
129 def ValidateAndMeasurePage(self
, page
, tab
, results
):
130 threads
= self
._timeline
_model
.GetAllThreads()
131 for thread
in threads
:
132 if thread
.name
== _CR_RENDERER_MAIN
:
133 _AddTracingResults(thread
.all_slices
, results
)
135 def CleanUpAfterPage(self
, page
, tab
):
136 if tab
.browser
.platform
.tracing_controller
.is_tracing_running
:
137 tab
.browser
.platform
.tracing_controller
.Stop()
140 class OilpanGCTimesForSmoothness(_OilpanGCTimesBase
):
142 super(OilpanGCTimesForSmoothness
, self
).__init
__('RunPageInteractions')
143 self
._interaction
= None
145 def WillRunActions(self
, page
, tab
):
146 runner
= action_runner
.ActionRunner(tab
)
147 self
._interaction
= runner
.BeginInteraction(_RUN_SMOOTH_ACTIONS
,
150 def DidRunActions(self
, page
, tab
):
151 self
._interaction
.End()
152 super(OilpanGCTimesForSmoothness
, self
).DidRunActions(page
, tab
)
155 class OilpanGCTimesForBlinkPerf(_OilpanGCTimesBase
):
157 super(OilpanGCTimesForBlinkPerf
, self
).__init
__()
158 with
open(os
.path
.join(os
.path
.dirname(__file__
), '..', 'benchmarks',
159 'blink_perf.js'), 'r') as f
:
160 self
._blink
_perf
_js
= f
.read()
162 def WillNavigateToPage(self
, page
, tab
):
163 page
.script_to_evaluate_on_commit
= self
._blink
_perf
_js
164 super(OilpanGCTimesForBlinkPerf
, self
).WillNavigateToPage(page
, tab
)
166 def DidRunActions(self
, page
, tab
):
167 tab
.WaitForJavaScriptExpression('testRunner.isDone', 600)
168 super(OilpanGCTimesForBlinkPerf
, self
).DidRunActions(page
, tab
)
171 class OilpanGCTimesForInternals(_OilpanGCTimesBase
):
173 super(OilpanGCTimesForInternals
, self
).__init
__()
176 def CustomizeBrowserOptions(cls
, options
):
177 # 'expose-internals-for-testing' can be enabled on content shell.
178 assert 'content-shell' in options
.browser_type
179 options
.AppendExtraBrowserArgs('--expose-internals-for-testing')