Don't add extra app list launcher page webviews.
[chromium-blink-merge.git] / tools / perf / measurements / v8_gc_times_unittest.py
blobc13089c0d05a851831ee6af9f36c530e9079d8d6
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 import wpr_modes
6 from telemetry.page import page as page_module
7 from telemetry.results import page_test_results
8 from telemetry.timeline import model as model_module
9 from telemetry.unittest_util import options_for_unittests
10 from telemetry.unittest_util import page_test_test_case
12 from measurements import v8_gc_times
15 class V8GCTimesTestPageHelper(object):
17 def __init__(self, page_set):
18 self._page_set = page_set
19 self._model = model_module.TimelineModel()
20 self._renderer_process = self._model.GetOrCreateProcess(1)
21 self._renderer_thread = self._renderer_process.GetOrCreateThread(2)
22 self._renderer_thread.name = 'CrRendererMain'
24 def AddEvent(self, category, name, thread_start, thread_duration,
25 args=None, wall_start=None, wall_duration=None):
26 wall_start = wall_start or thread_start
27 wall_duration = wall_duration or thread_duration
28 self._renderer_thread.BeginSlice(category, name, wall_start, thread_start,
29 args=args)
30 self._renderer_thread.EndSlice(wall_start + wall_duration,
31 thread_start + thread_duration)
33 class MockV8GCTimesPage(page_module.Page):
35 def __init__(self, page_set):
36 super(V8GCTimesTestPageHelper.MockV8GCTimesPage, self).__init__(
37 'file://blank.html', page_set, page_set.base_dir)
39 def MeasureFakePage(self):
40 # Create a fake page and add it to the page set.
41 results = page_test_results.PageTestResults()
42 page = V8GCTimesTestPageHelper.MockV8GCTimesPage(self._page_set)
43 self._page_set.AddUserStory(page)
45 # Pretend we're about to run the tests to silence lower level asserts.
46 results.WillRunPage(page)
48 v8_gc_times_metric = v8_gc_times.V8GCTimes()
49 v8_gc_times_metric._renderer_process = self._renderer_process
51 # Finalize the timeline import.
52 self._model.FinalizeImport()
54 # Measure the V8GCTimes metric and return the results
55 v8_gc_times_metric.ValidateAndMeasurePage(page, None, results)
56 results.DidRunPage(page)
57 return results
60 class V8GCTimesTests(page_test_test_case.PageTestTestCase):
62 def setUp(self):
63 self._options = options_for_unittests.GetCopy()
64 self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
66 def testWithNoTraceEvents(self):
67 test_page_helper = V8GCTimesTestPageHelper(
68 self.CreateEmptyPageSet())
70 results = test_page_helper.MeasureFakePage()
71 self._AssertResultsEqual(_GetEmptyResults(), _ActualValues(results))
73 def testWithNoGarbageCollectionEvents(self):
74 test_page_helper = V8GCTimesTestPageHelper(
75 self.CreateEmptyPageSet())
77 test_page_helper.AddEvent('toplevel', 'PostMessage',
78 thread_start=0, thread_duration=14, wall_start=5, wall_duration=35)
80 results = test_page_helper.MeasureFakePage()
81 expected = _GetEmptyResults()
82 expected['duration'] = ('ms', 35)
83 expected['cpu_time'] = ('ms', 14)
85 self._AssertResultsEqual(expected, _ActualValues(results))
87 def testWithGarbageCollectionEvents(self):
88 test_page_helper = V8GCTimesTestPageHelper(
89 self.CreateEmptyPageSet())
91 test_page_helper.AddEvent('toplevel', 'PostMessage',
92 thread_start=0, thread_duration=57, wall_start=5, wall_duration=68)
93 test_page_helper.AddEvent('v8', 'V8.GCScavenger', 5, 4)
94 test_page_helper.AddEvent('v8', 'V8.GCScavenger', 15, 3)
95 test_page_helper.AddEvent('v8', 'V8.GCIncrementalMarking', 23, 4)
96 test_page_helper.AddEvent('v8', 'V8.GCIncrementalMarking', 34, 2)
97 test_page_helper.AddEvent('v8', 'V8.GCCompactor', 42, 4)
98 test_page_helper.AddEvent('v8', 'V8.GCCompactor', 52, 5)
100 results = test_page_helper.MeasureFakePage()
101 expected = _GetEmptyResults()
102 expected['duration'] = ('ms', 68)
103 expected['cpu_time'] = ('ms', 57)
104 expected['v8_gc_incremental_marking'] = ('ms', 6.0)
105 expected['v8_gc_incremental_marking_outside_idle'] = ('ms', 6.0)
106 expected['v8_gc_scavenger'] = ('ms', 7.0)
107 expected['v8_gc_scavenger_outside_idle'] = ('ms', 7.0)
108 expected['v8_gc_mark_compactor'] = ('ms', 9.0)
109 expected['v8_gc_mark_compactor_outside_idle'] = ('ms', 9.0)
110 expected['v8_gc_total'] = ('ms', 22.0)
111 expected['v8_gc_total_outside_idle'] = ('ms', 22.0)
113 self._AssertResultsEqual(expected, _ActualValues(results))
115 def testWithIdleTaskGarbageCollectionEvents(self):
116 test_page_helper = V8GCTimesTestPageHelper(
117 self.CreateEmptyPageSet())
119 test_page_helper.AddEvent('toplevel', 'PostMessage',
120 thread_start=0, thread_duration=57, wall_start=5, wall_duration=68)
122 test_page_helper.AddEvent('v8', 'V8.GCScavenger', 5, 4)
123 test_page_helper.AddEvent('renderer.scheduler',
124 'SingleThreadIdleTaskRunner::RunTask', 15, 4, {'allotted_time_ms': 12})
125 test_page_helper.AddEvent('v8', 'V8.GCScavenger', 15, 3)
127 test_page_helper.AddEvent('v8', 'V8.GCIncrementalMarking', 23, 4)
128 test_page_helper.AddEvent('renderer.scheduler',
129 'SingleThreadIdleTaskRunner::RunTask', 34, 3, {'allotted_time_ms': 12})
130 test_page_helper.AddEvent('v8', 'V8.GCIncrementalMarking', 34, 2)
132 test_page_helper.AddEvent('v8', 'V8.GCCompactor', 42, 4)
133 test_page_helper.AddEvent('renderer.scheduler',
134 'SingleThreadIdleTaskRunner::RunTask', 52, 6, {'allotted_time_ms': 12})
135 test_page_helper.AddEvent('v8', 'V8.GCCompactor', 52, 5)
137 results = test_page_helper.MeasureFakePage()
138 expected = _GetEmptyResults()
139 expected['duration'] = ('ms', 68)
140 expected['cpu_time'] = ('ms', 57)
141 expected['v8_gc_incremental_marking'] = ('ms', 6.0)
142 expected['v8_gc_incremental_marking_outside_idle'] = ('ms', 4.0)
143 expected['v8_gc_incremental_marking_percentage_idle'] = \
144 ('idle%', 100 * 2 / 6.0)
145 expected['v8_gc_scavenger'] = ('ms', 7.0)
146 expected['v8_gc_scavenger_outside_idle'] = ('ms', 4.0)
147 expected['v8_gc_scavenger_percentage_idle'] = ('idle%', 100 * 3 / 7.0)
148 expected['v8_gc_mark_compactor'] = ('ms', 9.0)
149 expected['v8_gc_mark_compactor_outside_idle'] = ('ms', 4.0)
150 expected['v8_gc_mark_compactor_percentage_idle'] = ('idle%', 100 * 5 / 9.0)
151 expected['v8_gc_total'] = ('ms', 22.0)
152 expected['v8_gc_total_outside_idle'] = ('ms', 12.0)
153 expected['v8_gc_total_percentage_idle'] = ('idle%', 100 * 10 / 22.0)
155 self._AssertResultsEqual(expected, _ActualValues(results))
157 def testWithIdleTaskOverruns(self):
158 test_page_helper = V8GCTimesTestPageHelper(
159 self.CreateEmptyPageSet())
161 test_page_helper.AddEvent('toplevel', 'PostMessage',
162 thread_start=0, thread_duration=80, wall_start=5, wall_duration=92)
164 test_page_helper.AddEvent('renderer.scheduler',
165 'SingleThreadIdleTaskRunner::RunTask', 15, 15, {'allotted_time_ms': 8})
166 test_page_helper.AddEvent('v8', 'V8.GCScavenger', 15, 14)
168 test_page_helper.AddEvent('renderer.scheduler',
169 'SingleThreadIdleTaskRunner::RunTask', 34, 15, {'allotted_time_ms': 6})
170 test_page_helper.AddEvent('v8', 'V8.GCIncrementalMarking', 34, 14)
172 test_page_helper.AddEvent('renderer.scheduler',
173 'SingleThreadIdleTaskRunner::RunTask', 52, 23, {'allotted_time_ms': 9})
174 test_page_helper.AddEvent('v8', 'V8.GCCompactor', 52, 22)
176 results = test_page_helper.MeasureFakePage()
177 expected = _GetEmptyResults()
178 expected['duration'] = ('ms', 92)
179 expected['cpu_time'] = ('ms', 80)
180 expected['v8_gc_incremental_marking'] = ('ms', 14.0)
181 expected['v8_gc_incremental_marking_outside_idle'] = ('ms', 8.0)
182 expected['v8_gc_incremental_marking_idle_deadline_overrun'] = ('ms', 8.0)
183 expected['v8_gc_incremental_marking_percentage_idle'] = \
184 ('idle%', 100 * 6 / 14.0)
185 expected['v8_gc_scavenger'] = ('ms', 14.0)
186 expected['v8_gc_scavenger_outside_idle'] = ('ms', 6.0)
187 expected['v8_gc_scavenger_idle_deadline_overrun'] = ('ms', 6.0)
188 expected['v8_gc_scavenger_percentage_idle'] = ('idle%', 100 * 8 / 14.0)
189 expected['v8_gc_mark_compactor'] = ('ms', 22.0)
190 expected['v8_gc_mark_compactor_outside_idle'] = ('ms', 13.0)
191 expected['v8_gc_mark_compactor_idle_deadline_overrun'] = ('ms', 13.0)
192 expected['v8_gc_mark_compactor_percentage_idle'] = ('idle%', 100 * 9 / 22.0)
193 expected['v8_gc_total'] = ('ms', 50.0)
194 expected['v8_gc_total_outside_idle'] = ('ms', 27.0)
195 expected['v8_gc_total_idle_deadline_overrun'] = ('ms', 27.0)
196 expected['v8_gc_total_percentage_idle'] = ('idle%', 100 * 23 / 50.0)
198 self._AssertResultsEqual(expected, _ActualValues(results))
200 def testWithIdleTaskWallDurationOverruns(self):
201 test_page_helper = V8GCTimesTestPageHelper(
202 self.CreateEmptyPageSet())
204 test_page_helper.AddEvent('toplevel', 'PostMessage',
205 thread_start=0, thread_duration=80, wall_start=5, wall_duration=92)
207 test_page_helper.AddEvent('renderer.scheduler',
208 'SingleThreadIdleTaskRunner::RunTask', 15, 15, {'allotted_time_ms': 8})
209 test_page_helper.AddEvent('v8', 'V8.GCScavenger',
210 thread_start=15, thread_duration=4, wall_start=15, wall_duration=14)
212 results = test_page_helper.MeasureFakePage()
213 expected = _GetEmptyResults()
214 expected['duration'] = ('ms', 92)
215 expected['cpu_time'] = ('ms', 80)
216 expected['v8_gc_scavenger'] = ('ms', 4.0)
217 expected_outside_idle = 4.0 - (4.0 * 8 / 14)
218 expected['v8_gc_scavenger_outside_idle'] = ('ms', expected_outside_idle)
219 expected['v8_gc_scavenger_idle_deadline_overrun'] = ('ms', 6.0)
220 expected['v8_gc_scavenger_percentage_idle'] = \
221 ('idle%', 100 * (4.0 - expected_outside_idle) / 4.0)
222 expected['v8_gc_total'] = expected['v8_gc_scavenger']
223 expected['v8_gc_total_outside_idle'] = \
224 expected['v8_gc_scavenger_outside_idle']
225 expected['v8_gc_total_idle_deadline_overrun'] = \
226 expected['v8_gc_scavenger_idle_deadline_overrun']
227 expected['v8_gc_total_percentage_idle'] = \
228 expected['v8_gc_scavenger_percentage_idle']
230 self._AssertResultsEqual(expected, _ActualValues(results))
232 def _AssertResultsEqual(self, expected, actual):
233 for key in expected.iterkeys():
234 self.assertIn(key, actual.keys())
235 self.assertEqual(expected[key], actual[key],
236 'Result for [' + key + '] - expected ' + str(expected[key]) +
237 ' but got ' + str(actual[key]))
240 def _ActualValues(results):
241 return dict(list(
242 (v.name, (v.units, v.value))
243 for v in results.all_page_specific_values
247 def _GetEmptyResults():
248 return {'cpu_time': ('ms', 0.0),
249 'duration': ('ms', 0.0),
250 'v8_gc_incremental_marking': ('ms', 0.0),
251 'v8_gc_incremental_marking_idle_deadline_overrun': ('ms', 0.0),
252 'v8_gc_incremental_marking_outside_idle': ('ms', 0.0),
253 'v8_gc_incremental_marking_percentage_idle': ('idle%', 0.0),
254 'v8_gc_mark_compactor': ('ms', 0.0),
255 'v8_gc_mark_compactor_idle_deadline_overrun': ('ms', 0.0),
256 'v8_gc_mark_compactor_outside_idle': ('ms', 0.0),
257 'v8_gc_mark_compactor_percentage_idle': ('idle%', 0.0),
258 'v8_gc_scavenger': ('ms', 0.0),
259 'v8_gc_scavenger_idle_deadline_overrun': ('ms', 0.0),
260 'v8_gc_scavenger_outside_idle': ('ms', 0.0),
261 'v8_gc_scavenger_percentage_idle': ('idle%', 0.0),
262 'v8_gc_total': ('ms', 0.0),
263 'v8_gc_total_idle_deadline_overrun': ('ms', 0.0),
264 'v8_gc_total_outside_idle': ('ms', 0.0)}