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

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

Issue 29423005: telemetry: Add GetRendererProcessFromTab to timeline model. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update unit test. 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.backends.chrome.tracing_backend import RawTraceResultImpl 11 from telemetry.core.trace_result import TraceResult
12 from telemetry.core.backends.chrome.trace_result import TraceResult 12 from telemetry.core.backends.chrome.tracing_backend import ChromeRawTraceResult
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'
17 18
18 19
19 class MockTimer(object): 20 class MockTimer(object):
20 """A mock timer class which can generate random durations. 21 """A mock timer class which can generate random durations.
21 22
22 An instance of this class is used as a global timer to generate random 23 An instance of this class is used as a global timer to generate random
23 durations for stats and consistent timestamps for all mock trace events. 24 durations for stats and consistent timestamps for all mock trace events.
24 """ 25 """
25 def __init__(self): 26 def __init__(self):
26 self.microseconds = 0 27 self.microseconds = 0
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 trace_events = [] 100 trace_events = []
100 total_time_seconds = 0.0 101 total_time_seconds = 0.0
101 num_frames_sent = 0.0 102 num_frames_sent = 0.0
102 first_frame = True 103 first_frame = True
103 previous_frame_time = None 104 previous_frame_time = None
104 # This list represents time differences between frames in milliseconds. 105 # This list represents time differences between frames in milliseconds.
105 expected_frame_times = [] 106 expected_frame_times = []
106 107
107 # Append start trace events for the timeline marker and gesture marker, 108 # Append start trace events for the timeline marker and gesture marker,
108 # with some amount of time in between them. 109 # with some amount of time in between them.
109 trace_events.append({'name': rendering_stats.RENDER_PROCESS_MARKER, 110 trace_events.append({'name': RENDERER_PROCESS_MARKER,
110 'tts': mock_timer.microseconds, 111 'tts': mock_timer.microseconds,
111 'args': {}, 112 'args': {},
112 'pid': 20978, 113 'pid': 20978,
113 'ts': mock_timer.microseconds, 114 'ts': mock_timer.microseconds,
114 'cat': 'webkit', 115 'cat': 'webkit',
115 'tid': 11, 116 'tid': 11,
116 'ph': 'S', # Phase: start. 117 'ph': 'S', # Phase: start.
117 'id': '0x12345'}) 118 'id': '0x12345'})
118 mock_timer.Advance() 119 mock_timer.Advance()
119 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER, 120 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER,
(...skipping 30 matching lines...) Expand all
150 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER, 151 trace_events.append({'name': SYNTHETIC_GESTURE_MARKER,
151 'tts': mock_timer.microseconds, 152 'tts': mock_timer.microseconds,
152 'args': {}, 153 'args': {},
153 'pid': 20978, 154 'pid': 20978,
154 'ts': mock_timer.microseconds, 155 'ts': mock_timer.microseconds,
155 'cat': 'webkit', 156 'cat': 'webkit',
156 'tid': 11, 157 'tid': 11,
157 'ph': 'F', # Phase: finish. 158 'ph': 'F', # Phase: finish.
158 'id': '0xabcde'}) 159 'id': '0xabcde'})
159 mock_timer.Advance() 160 mock_timer.Advance()
160 trace_events.append({'name': rendering_stats.RENDER_PROCESS_MARKER, 161 trace_events.append({'name': RENDERER_PROCESS_MARKER,
161 'tts': mock_timer.microseconds, 162 'tts': mock_timer.microseconds,
162 'args': {}, 163 'args': {},
163 'pid': 20978, 164 'pid': 20978,
164 'ts': mock_timer.microseconds, 165 'ts': mock_timer.microseconds,
165 'cat': 'webkit', 166 'cat': 'webkit',
166 'tid': 11, 167 'tid': 11,
167 'ph': 'F', 168 'ph': 'F',
168 'id': '0x12345'}) 169 'id': '0x12345'})
169 170
170 # Create a timeline object from the trace. 171 # Create a timeline object from the trace.
171 trace_impl = RawTraceResultImpl(trace_events) 172 trace_result = TraceResult(ChromeRawTraceResult(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 render_process_marker = timeline.FindTimelineMarkers( 177 renderer_process_markers = timeline.FindTimelineMarkers(
178 rendering_stats.RENDER_PROCESS_MARKER) 178 RENDERER_PROCESS_MARKER)
179 self.assertEquals(len(renderer_process_markers), 1)
180 renderer_process = renderer_process_markers[0].start_thread.parent
179 timeline_markers = timeline.FindTimelineMarkers( 181 timeline_markers = timeline.FindTimelineMarkers(
180 SYNTHETIC_GESTURE_MARKER) 182 SYNTHETIC_GESTURE_MARKER)
181 stats = rendering_stats.RenderingStats( 183 stats = rendering_stats.RenderingStats(renderer_process, timeline_markers)
182 render_process_marker, timeline_markers)
183 184
184 # Make a results object and add results to it from the smoothness metric. 185 # Make a results object and add results to it from the smoothness metric.
185 results = PageMeasurementResults() 186 results = PageMeasurementResults()
186 results.WillMeasurePage(page.Page('http://foo.com/', None)) 187 results.WillMeasurePage(page.Page('http://foo.com/', None))
187 smoothness_metric = smoothness.SmoothnessMetric(stats) 188 smoothness_metric = smoothness.SmoothnessMetric(None)
189 smoothness_metric.SetStats(stats)
188 smoothness_metric.AddResults(None, results) 190 smoothness_metric.AddResults(None, results)
189 results.DidMeasurePage() 191 results.DidMeasurePage()
190 192
191 self.assertEquals( 193 self.assertEquals(
192 expected_frame_times, 194 expected_frame_times,
193 results.page_results[0]['frame_times'].value) 195 results.page_results[0]['frame_times'].value)
194 self.assertAlmostEquals( 196 self.assertAlmostEquals(
195 1000.0 * (total_time_seconds / num_frames_sent), 197 1000.0 * (total_time_seconds / num_frames_sent),
196 results.page_results[0]['mean_frame_time'].value, 198 results.page_results[0]['mean_frame_time'].value,
197 places=2) 199 places=2)
198 200
199 # We don't verify the correctness of the discrepancy computation itself, 201 # We don't verify the correctness of the discrepancy computation itself,
200 # because we have a separate unit test for that purpose. 202 # because we have a separate unit test for that purpose.
201 self.assertAlmostEquals( 203 self.assertAlmostEquals(
202 statistics.FrameDiscrepancy(stats.frame_timestamps, True), 204 statistics.FrameDiscrepancy(stats.frame_timestamps, True),
203 results.page_results[0]['jank'].value, 205 results.page_results[0]['jank'].value,
204 places=4) 206 places=4)
205 207
206 # We do not verify the correctness of Percentile here; Percentile should 208 # We do not verify the correctness of Percentile here; Percentile should
207 # have its own test. 209 # have its own test.
208 # The 17 here represents a threshold of 17 ms; this should match the value 210 # The 17 here represents a threshold of 17 ms; this should match the value
209 # in the smoothness metric. 211 # in the smoothness metric.
210 self.assertEquals( 212 self.assertEquals(
211 statistics.Percentile(expected_frame_times, 95.0) < 17.0, 213 statistics.Percentile(expected_frame_times, 95.0) < 17.0,
212 results.page_results[0]['mostly_smooth'].value) 214 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