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_sweep',
24 'oilpan_conservative_mark',
25 'oilpan_conservative_sweep',
28 def _AddTracingResults(events
, results
):
31 for name
in _NAMES_TO_DUMP
:
40 duration
= event
.thread_duration
or event
.duration
41 if event
.name
== 'ThreadHeap::coalesce':
42 values
['oilpan_coalesce'].append(duration
)
44 if event
.name
== 'Heap::collectGarbage':
45 if not gc_type
is None and not forced
:
46 values
['oilpan_%s_mark' % gc_type
].append(mark_time
)
47 values
['oilpan_%s_sweep' % gc_type
].append(sweep_time
)
49 gc_type
= 'precise' if event
.args
['precise'] else 'conservative'
50 forced
= event
.args
['forced']
54 if event
.name
== 'ThreadState::performPendingSweep':
55 sweep_time
+= duration
58 if not gc_type
is None and not forced
:
59 values
['oilpan_%s_mark' % gc_type
].append(mark_time
)
60 values
['oilpan_%s_sweep' % gc_type
].append(sweep_time
)
63 page
= results
.current_page
65 for name
in _NAMES_TO_DUMP
:
67 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
68 page
, name
, unit
, values
[name
]))
69 results
.AddValue(scalar
.ScalarValue(
70 page
, name
+ '_max', unit
, max(values
[name
])))
71 results
.AddValue(scalar
.ScalarValue(
72 page
, name
+ '_total', unit
, sum(values
[name
])))
74 for do_type
in ['mark', 'sweep']:
76 for gc_type
in ['precise', 'conservative']:
77 work_time
+= sum(values
['oilpan_%s_%s' % (gc_type
, do_type
)])
78 key
= 'oilpan_%s' % do_type
79 results
.AddValue(scalar
.ScalarValue(page
, key
, unit
, work_time
))
83 gc_time
+= sum(values
[key
])
84 results
.AddValue(scalar
.ScalarValue(page
, 'oilpan_gc', unit
, gc_time
))
87 class _OilpanGCTimesBase(page_test
.PageTest
):
88 def __init__(self
, action_name
= ''):
89 super(_OilpanGCTimesBase
, self
).__init
__(action_name
)
90 self
._timeline
_model
= None
92 def WillNavigateToPage(self
, page
, tab
):
93 # FIXME: Remove webkit.console when blink.console lands in chromium and
94 # the ref builds are updated. crbug.com/386847
95 categories
= ['webkit.console', 'blink.console', 'blink_gc']
96 category_filter
= tracing_category_filter
.TracingCategoryFilter()
98 category_filter
.AddIncludedCategory(c
)
99 options
= tracing_options
.TracingOptions()
100 options
.enable_chrome_trace
= True
101 tab
.browser
.platform
.tracing_controller
.Start(options
, category_filter
,
104 def DidRunActions(self
, page
, tab
):
105 timeline_data
= tab
.browser
.platform
.tracing_controller
.Stop()
106 self
._timeline
_model
= TimelineModel(timeline_data
)
108 def ValidateAndMeasurePage(self
, page
, tab
, results
):
109 threads
= self
._timeline
_model
.GetAllThreads()
110 for thread
in threads
:
111 if thread
.name
== _CR_RENDERER_MAIN
:
112 _AddTracingResults(thread
.all_slices
, results
)
114 def CleanUpAfterPage(self
, page
, tab
):
115 if tab
.browser
.platform
.tracing_controller
.is_tracing_running
:
116 tab
.browser
.platform
.tracing_controller
.Stop()
119 class OilpanGCTimesForSmoothness(_OilpanGCTimesBase
):
121 super(OilpanGCTimesForSmoothness
, self
).__init
__('RunPageInteractions')
122 self
._interaction
= None
124 def WillRunActions(self
, page
, tab
):
125 runner
= action_runner
.ActionRunner(tab
)
126 self
._interaction
= runner
.BeginInteraction(_RUN_SMOOTH_ACTIONS
,
129 def DidRunActions(self
, page
, tab
):
130 self
._interaction
.End()
131 super(OilpanGCTimesForSmoothness
, self
).DidRunActions(page
, tab
)
134 class OilpanGCTimesForBlinkPerf(_OilpanGCTimesBase
):
136 super(OilpanGCTimesForBlinkPerf
, self
).__init
__()
137 with
open(os
.path
.join(os
.path
.dirname(__file__
), '..', 'benchmarks',
138 'blink_perf.js'), 'r') as f
:
139 self
._blink
_perf
_js
= f
.read()
141 def WillNavigateToPage(self
, page
, tab
):
142 page
.script_to_evaluate_on_commit
= self
._blink
_perf
_js
143 super(OilpanGCTimesForBlinkPerf
, self
).WillNavigateToPage(page
, tab
)
145 def DidRunActions(self
, page
, tab
):
146 tab
.WaitForJavaScriptExpression('testRunner.isDone', 600)
147 super(OilpanGCTimesForBlinkPerf
, self
).DidRunActions(page
, tab
)
150 class OilpanGCTimesForInternals(_OilpanGCTimesBase
):
152 super(OilpanGCTimesForInternals
, self
).__init
__()
155 def CustomizeBrowserOptions(cls
, options
):
156 # 'expose-internals-for-testing' can be enabled on content shell.
157 assert 'content-shell' in options
.browser_type
158 options
.AppendExtraBrowserArgs('--expose-internals-for-testing')