Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: tools/perf/metrics/smoothness_unittest.py

Issue 60103008: Revert "telemetry: Add GetRendererProcessFromTab to timeline model." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import random 5 import random
6 import unittest 6 import unittest
7 7
8 from metrics import smoothness 8 from metrics import smoothness
9 from metrics import statistics 9 from metrics import statistics
10 from metrics import rendering_stats 10 from metrics import rendering_stats
11 from telemetry.core.trace_result import TraceResult 11 from telemetry.core.backends.chrome.tracing_backend import RawTraceResultImpl
12 from telemetry.core.backends.chrome.tracing_backend import ChromeRawTraceResult 12 from telemetry.core.backends.chrome.trace_result import TraceResult
13 from telemetry.page import page 13 from telemetry.page import page
14 from telemetry.page.page_measurement_results import PageMeasurementResults 14 from telemetry.page.page_measurement_results import PageMeasurementResults
15 15
16 SYNTHETIC_GESTURE_MARKER = 'SyntheticGestureController::running' 16 SYNTHETIC_GESTURE_MARKER = 'SyntheticGestureController::running'
17 RENDERER_PROCESS_MARKER = 'RendererProcessMarker'
18 17
19 18
20 class MockTimer(object): 19 class MockTimer(object):
21 """A mock timer class which can generate random durations. 20 """A mock timer class which can generate random durations.
22 21
23 An instance of this class is used as a global timer to generate random 22 An instance of this class is used as a global timer to generate random
24 durations for stats and consistent timestamps for all mock trace events. 23 durations for stats and consistent timestamps for all mock trace events.
25 """ 24 """
26 def __init__(self): 25 def __init__(self):
27 self.microseconds = 0 26 self.microseconds = 0
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 trace_events = [] 99 trace_events = []
101 total_time_seconds = 0.0 100 total_time_seconds = 0.0
102 num_frames_sent = 0.0 101 num_frames_sent = 0.0
103 first_frame = True 102 first_frame = True
104 previous_frame_time = None 103 previous_frame_time = None
105 # This list represents time differences between frames in milliseconds. 104 # This list represents time differences between frames in milliseconds.
106 expected_frame_times = [] 105 expected_frame_times = []
107 106
108 # Append start trace events for the timeline marker and gesture marker, 107 # Append start trace events for the timeline marker and gesture marker,
109 # with some amount of time in between them. 108 # with some amount of time in between them.
110 trace_events.append({'name': RENDERER_PROCESS_MARKER, 109 trace_events.append({'name': rendering_stats.RENDER_PROCESS_MARKER,
111 'tts': mock_timer.microseconds, 110 'tts': mock_timer.microseconds,
112 'args': {}, 111 'args': {},
113 'pid': 20978, 112 'pid': 20978,
114 'ts': mock_timer.microseconds, 113 'ts': mock_timer.microseconds,
115 'cat': 'webkit', 114 'cat': 'webkit',
116 'tid': 11, 115 'tid': 11,
117 'ph': 'S', # Phase: start. 116 'ph': 'S', # Phase: start.
118 'id': '0x12345'}) 117 'id': '0x12345'})
119 mock_timer.Advance() 118 mock_timer.Advance()
120 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER, 119 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER,
(...skipping 30 matching lines...) Expand all
151 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER, 150 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER,
152 'tts': mock_timer.microseconds, 151 'tts': mock_timer.microseconds,
153 'args': {}, 152 'args': {},
154 'pid': 20978, 153 'pid': 20978,
155 'ts': mock_timer.microseconds, 154 'ts': mock_timer.microseconds,
156 'cat': 'webkit', 155 'cat': 'webkit',
157 'tid': 11, 156 'tid': 11,
158 'ph': 'F', # Phase: finish. 157 'ph': 'F', # Phase: finish.
159 'id': '0xabcde'}) 158 'id': '0xabcde'})
160 mock_timer.Advance() 159 mock_timer.Advance()
161 trace_events.append({'name': RENDERER_PROCESS_MARKER, 160 trace_events.append({'name': rendering_stats.RENDER_PROCESS_MARKER,
162 'tts': mock_timer.microseconds, 161 'tts': mock_timer.microseconds,
163 'args': {}, 162 'args': {},
164 'pid': 20978, 163 'pid': 20978,
165 'ts': mock_timer.microseconds, 164 'ts': mock_timer.microseconds,
166 'cat': 'webkit', 165 'cat': 'webkit',
167 'tid': 11, 166 'tid': 11,
168 'ph': 'F', 167 'ph': 'F',
169 'id': '0x12345'}) 168 'id': '0x12345'})
170 169
171 # Create a timeline object from the trace. 170 # Create a timeline object from the trace.
172 trace_result = TraceResult(ChromeRawTraceResult(trace_events)) 171 trace_impl = RawTraceResultImpl(trace_events)
172 trace_result = TraceResult(trace_impl)
173 timeline = trace_result.AsTimelineModel() 173 timeline = trace_result.AsTimelineModel()
174 174
175 # Find the timeline marker and gesture marker in the timeline, 175 # Find the timeline marker and gesture marker in the timeline,
176 # and create a RenderingStats object. 176 # and create a RenderingStats object.
177 renderer_process_markers = timeline.FindTimelineMarkers( 177 render_process_marker = timeline.FindTimelineMarkers(
178 RENDERER_PROCESS_MARKER) 178 rendering_stats.RENDER_PROCESS_MARKER)
179 self.assertEquals(len(renderer_process_markers), 1)
180 renderer_process = renderer_process_markers[0].start_thread.parent
181 timeline_markers = timeline.FindTimelineMarkers( 179 timeline_markers = timeline.FindTimelineMarkers(
182 SYNTHETIC_GESTURE_MARKER) 180 SYNTHETIC_GESTURE_MARKER)
183 stats = rendering_stats.RenderingStats(renderer_process, timeline_markers) 181 stats = rendering_stats.RenderingStats(
182 render_process_marker, timeline_markers)
184 183
185 # Make a results object and add results to it from the smoothness metric. 184 # Make a results object and add results to it from the smoothness metric.
186 results = PageMeasurementResults() 185 results = PageMeasurementResults()
187 results.WillMeasurePage(page.Page('http://foo.com/', None)) 186 results.WillMeasurePage(page.Page('http://foo.com/', None))
188 smoothness_metric = smoothness.SmoothnessMetric(None) 187 smoothness_metric = smoothness.SmoothnessMetric(stats)
189 smoothness_metric.SetStats(stats)
190 smoothness_metric.AddResults(None, results) 188 smoothness_metric.AddResults(None, results)
191 results.DidMeasurePage() 189 results.DidMeasurePage()
192 190
193 self.assertEquals( 191 self.assertEquals(
194 expected_frame_times, 192 expected_frame_times,
195 results.page_results[0]['frame_times'].value) 193 results.page_results[0]['frame_times'].value)
196 self.assertAlmostEquals( 194 self.assertAlmostEquals(
197 1000.0 * (total_time_seconds / num_frames_sent), 195 1000.0 * (total_time_seconds / num_frames_sent),
198 results.page_results[0]['mean_frame_time'].value, 196 results.page_results[0]['mean_frame_time'].value,
199 places=2) 197 places=2)
200 198
201 # We don't verify the correctness of the discrepancy computation itself, 199 # We don't verify the correctness of the discrepancy computation itself,
202 # because we have a separate unit test for that purpose. 200 # because we have a separate unit test for that purpose.
203 self.assertAlmostEquals( 201 self.assertAlmostEquals(
204 statistics.FrameDiscrepancy(stats.frame_timestamps, True), 202 statistics.FrameDiscrepancy(stats.frame_timestamps, True),
205 results.page_results[0]['jank'].value, 203 results.page_results[0]['jank'].value,
206 places=4) 204 places=4)
207 205
208 # We do not verify the correctness of Percentile here; Percentile should 206 # We do not verify the correctness of Percentile here; Percentile should
209 # have its own test. 207 # have its own test.
210 # The 17 here represents a threshold of 17 ms; this should match the value 208 # The 17 here represents a threshold of 17 ms; this should match the value
211 # in the smoothness metric. 209 # in the smoothness metric.
212 self.assertEquals( 210 self.assertEquals(
213 statistics.Percentile(expected_frame_times, 95.0) < 17.0, 211 statistics.Percentile(expected_frame_times, 95.0) < 17.0,
214 results.page_results[0]['mostly_smooth'].value) 212 results.page_results[0]['mostly_smooth'].value)
OLDNEW
« no previous file with comments | « tools/perf/metrics/smoothness.py ('k') | tools/telemetry/telemetry/core/backends/chrome/chrome_browser_backend.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698