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.
5 from measurements
import oilpan_gc_times
7 from telemetry
.results
import page_test_results
8 from telemetry
.timeline
import model
9 from telemetry
.timeline
import slice as slice_data
10 from telemetry
.timeline
.event
import TimelineEvent
11 from telemetry
.unittest_util
import options_for_unittests
12 from telemetry
.unittest_util
import page_test_test_case
13 from telemetry
.page
import page
as page_module
16 class TestOilpanGCTimesPage(page_module
.Page
):
17 def __init__(self
, page_set
):
18 super(TestOilpanGCTimesPage
, self
).__init
__(
19 'file://blank.html', page_set
, page_set
.base_dir
)
21 def RunPageInteractions(self
, action_runner
):
22 interaction
= action_runner
.BeginGestureInteraction('ScrollAction')
23 action_runner
.ScrollPage()
27 class OilpanGCTimesTestData(object):
28 def __init__(self
, thread_name
):
29 self
._model
= model
.TimelineModel()
30 self
._renderer
_process
= self
._model
.GetOrCreateProcess(1)
31 self
._renderer
_thread
= self
._renderer
_process
.GetOrCreateThread(2)
32 self
._renderer
_thread
.name
= thread_name
33 self
._results
= page_test_results
.PageTestResults()
39 def AddSlice(self
, name
, timestamp
, duration
, args
):
40 new_slice
= slice_data
.Slice(
49 self
._renderer
_thread
.all_slices
.append(new_slice
)
52 def ClearResults(self
):
53 self
._results
= page_test_results
.PageTestResults()
56 class OilpanGCTimesTest(page_test_test_case
.PageTestTestCase
):
57 """Smoke test for Oilpan GC pause time measurements.
59 Runs OilpanGCTimes measurement on some simple pages and verifies
60 that all metrics were added to the results. The test is purely functional,
61 i.e. it only checks if the metrics are present and non-zero.
63 _KEY_MARK
= 'Heap::collectGarbage'
64 _KEY_LAZY_SWEEP
= 'ThreadHeap::lazySweepPages'
65 _KEY_COMPLETE_SWEEP
= 'ThreadState::completeSweep'
66 _KEY_COALESCE
= 'ThreadHeap::coalesce'
69 self
._options
= options_for_unittests
.GetCopy()
71 def testForParsingOldFormat(self
):
72 def getMetric(results
, name
):
73 metrics
= results
.FindAllPageSpecificValuesNamed(name
)
74 self
.assertEquals(1, len(metrics
))
75 return metrics
[0].GetBuildbotValue()
77 data
= self
._GenerateDataForParsingOldFormat
()
79 measurement
= oilpan_gc_times
._OilpanGCTimesBase
()
80 measurement
._renderer
_process
= data
._renderer
_process
81 measurement
._timeline
_model
= data
._model
82 measurement
.ValidateAndMeasurePage(None, None, data
.results
)
84 results
= data
.results
85 self
.assertEquals(7, len(getMetric(results
, 'oilpan_coalesce')))
86 self
.assertEquals(3, len(getMetric(results
, 'oilpan_precise_mark')))
87 self
.assertEquals(3, len(getMetric(results
, 'oilpan_precise_lazy_sweep')))
88 self
.assertEquals(3, len(getMetric(results
,
89 'oilpan_precise_complete_sweep')))
90 self
.assertEquals(1, len(getMetric(results
, 'oilpan_conservative_mark')))
91 self
.assertEquals(1, len(getMetric(results
,
92 'oilpan_conservative_lazy_sweep')))
93 self
.assertEquals(1, len(getMetric(results
,
94 'oilpan_conservative_complete_sweep')))
95 self
.assertEquals(2, len(getMetric(results
, 'oilpan_forced_mark')))
96 self
.assertEquals(2, len(getMetric(results
, 'oilpan_forced_lazy_sweep')))
97 self
.assertEquals(2, len(getMetric(results
,
98 'oilpan_forced_complete_sweep')))
100 def testForParsing(self
):
101 def getMetric(results
, name
):
102 metrics
= results
.FindAllPageSpecificValuesNamed(name
)
103 self
.assertEquals(1, len(metrics
))
104 return metrics
[0].GetBuildbotValue()
106 data
= self
._GenerateDataForParsing
()
108 measurement
= oilpan_gc_times
._OilpanGCTimesBase
()
109 measurement
._renderer
_process
= data
._renderer
_process
110 measurement
._timeline
_model
= data
._model
111 measurement
.ValidateAndMeasurePage(None, None, data
.results
)
113 results
= data
.results
114 self
.assertEquals(7, len(getMetric(results
, 'oilpan_coalesce')))
115 self
.assertEquals(2, len(getMetric(results
, 'oilpan_precise_mark')))
116 self
.assertEquals(2, len(getMetric(results
, 'oilpan_precise_lazy_sweep')))
117 self
.assertEquals(2, len(getMetric(results
,
118 'oilpan_precise_complete_sweep')))
119 self
.assertEquals(2, len(getMetric(results
, 'oilpan_conservative_mark')))
120 self
.assertEquals(2, len(getMetric(results
,
121 'oilpan_conservative_lazy_sweep')))
122 self
.assertEquals(2, len(getMetric(results
,
123 'oilpan_conservative_complete_sweep')))
124 self
.assertEquals(1, len(getMetric(results
, 'oilpan_forced_mark')))
125 self
.assertEquals(1, len(getMetric(results
, 'oilpan_forced_lazy_sweep')))
126 self
.assertEquals(1, len(getMetric(results
,
127 'oilpan_forced_complete_sweep')))
128 self
.assertEquals(1, len(getMetric(results
, 'oilpan_idle_mark')))
129 self
.assertEquals(1, len(getMetric(results
, 'oilpan_idle_lazy_sweep')))
130 self
.assertEquals(1, len(getMetric(results
,
131 'oilpan_idle_complete_sweep')))
133 def testForSmoothness(self
):
134 ps
= self
.CreatePageSetFromFileInUnittestDataDir('create_many_objects.html')
135 measurement
= oilpan_gc_times
.OilpanGCTimesForSmoothness()
136 results
= self
.RunMeasurement(measurement
, ps
, options
=self
._options
)
137 self
.assertEquals(0, len(results
.failures
))
139 precise
= results
.FindAllPageSpecificValuesNamed('oilpan_precise_mark')
140 conservative
= results
.FindAllPageSpecificValuesNamed(
141 'oilpan_conservative_mark')
142 self
.assertLess(0, len(precise
) + len(conservative
))
144 def testForBlinkPerf(self
):
145 ps
= self
.CreatePageSetFromFileInUnittestDataDir('create_many_objects.html')
146 measurement
= oilpan_gc_times
.OilpanGCTimesForBlinkPerf()
147 results
= self
.RunMeasurement(measurement
, ps
, options
=self
._options
)
148 self
.assertEquals(0, len(results
.failures
))
150 precise
= results
.FindAllPageSpecificValuesNamed('oilpan_precise_mark')
151 conservative
= results
.FindAllPageSpecificValuesNamed(
152 'oilpan_conservative_mark')
153 self
.assertLess(0, len(precise
) + len(conservative
))
155 def _GenerateDataForEmptyPageSet(self
):
156 page_set
= self
.CreateEmptyPageSet()
157 page
= TestOilpanGCTimesPage(page_set
)
158 page_set
.AddUserStory(page
)
160 data
= OilpanGCTimesTestData('CrRendererMain')
161 # Pretend we are about to run the tests to silence lower level asserts.
162 data
.results
.WillRunPage(page
)
166 def _GenerateDataForParsingOldFormat(self
):
167 data
= self
._GenerateDataForEmptyPageSet
()
168 data
.AddSlice(self
._KEY
_MARK
, 1, 1, {'precise': True, 'forced': False})
169 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 2, 2, {})
170 data
.AddSlice(self
._KEY
_COALESCE
, 4, 3, {})
171 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 7, 4, {})
172 data
.AddSlice(self
._KEY
_COALESCE
, 11, 5, {})
173 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 16, 6, {})
174 data
.AddSlice(self
._KEY
_MARK
, 22, 7, {'precise': True, 'forced': False})
175 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 29, 8, {})
176 data
.AddSlice(self
._KEY
_COALESCE
, 37, 9, {})
177 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 46, 10, {})
178 data
.AddSlice(self
._KEY
_MARK
, 56, 11, {'precise': False, 'forced': False})
179 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 67, 12, {})
180 data
.AddSlice(self
._KEY
_COALESCE
, 79, 13, {})
181 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 92, 14, {})
182 data
.AddSlice(self
._KEY
_MARK
, 106, 15, {'precise': True, 'forced': False})
183 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 121, 16, {})
184 data
.AddSlice(self
._KEY
_COALESCE
, 137, 17, {})
185 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 154, 18, {})
186 data
.AddSlice(self
._KEY
_MARK
, 172, 19, {'precise': False, 'forced': True})
187 data
.AddSlice(self
._KEY
_COALESCE
, 191, 20, {})
188 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 211, 21, {})
189 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 232, 22, {})
190 data
.AddSlice(self
._KEY
_MARK
, 254, 23, {'precise': True, 'forced': True})
191 data
.AddSlice(self
._KEY
_COALESCE
, 277, 24, {})
192 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 301, 25, {})
193 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 326, 26, {})
196 def _GenerateDataForParsing(self
):
197 data
= self
._GenerateDataForEmptyPageSet
()
198 data
.AddSlice(self
._KEY
_MARK
, 1, 1,
199 {'lazySweeping': True, 'gcReason': 'ConservativeGC'})
200 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 2, 2, {})
201 data
.AddSlice(self
._KEY
_COALESCE
, 4, 3, {})
202 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 7, 4, {})
203 data
.AddSlice(self
._KEY
_COALESCE
, 11, 5, {})
204 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 16, 6, {})
205 data
.AddSlice(self
._KEY
_MARK
, 22, 7,
206 {'lazySweeping': True, 'gcReason': 'PreciseGC'})
207 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 29, 8, {})
208 data
.AddSlice(self
._KEY
_COALESCE
, 37, 9, {})
209 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 46, 10, {})
210 data
.AddSlice(self
._KEY
_MARK
, 56, 11,
211 {'lazySweeping': False, 'gcReason': 'ConservativeGC'})
212 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 67, 12, {})
213 data
.AddSlice(self
._KEY
_COALESCE
, 79, 13, {})
214 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 92, 14, {})
215 data
.AddSlice(self
._KEY
_MARK
, 106, 15,
216 {'lazySweeping': False, 'gcReason': 'PreciseGC'})
217 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 121, 16, {})
218 data
.AddSlice(self
._KEY
_COALESCE
, 137, 17, {})
219 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 154, 18, {})
220 data
.AddSlice(self
._KEY
_MARK
, 172, 19,
221 {'lazySweeping': False, 'gcReason': 'ForcedGCForTesting'})
222 data
.AddSlice(self
._KEY
_COALESCE
, 191, 20, {})
223 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 211, 21, {})
224 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 232, 22, {})
225 data
.AddSlice(self
._KEY
_MARK
, 254, 23,
226 {'lazySweeping': False, 'gcReason': 'IdleGC'})
227 data
.AddSlice(self
._KEY
_COALESCE
, 277, 24, {})
228 data
.AddSlice(self
._KEY
_LAZY
_SWEEP
, 301, 25, {})
229 data
.AddSlice(self
._KEY
_COMPLETE
_SWEEP
, 326, 26, {})