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

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

Issue 167343003: Add latency metric mean_js_touch_scroll_latency for JS touch handler driven scroll (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 10 months 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
« no previous file with comments | « tools/perf/metrics/rendering_stats.py ('k') | tools/perf/metrics/smoothness.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.rendering_stats import UI_COMP_NAME, BEGIN_COMP_NAME, END_COMP_NAME 8 from metrics.rendering_stats import UI_COMP_NAME, BEGIN_COMP_NAME, END_COMP_NAME
9 from metrics.rendering_stats import GetScrollInputLatencyEvents 9 from metrics.rendering_stats import GetScrollInputLatencyEvents
10 from metrics.rendering_stats import ComputeMouseWheelScrollLatency 10 from metrics.rendering_stats import ComputeMouseWheelScrollLatency
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 self.record_times.append([]) 54 self.record_times.append([])
55 self.recorded_pixel_counts.append([]) 55 self.recorded_pixel_counts.append([])
56 self.rasterize_times.append([]) 56 self.rasterize_times.append([])
57 self.rasterized_pixel_counts.append([]) 57 self.rasterized_pixel_counts.append([])
58 58
59 class ReferenceInputLatencyStats(object): 59 class ReferenceInputLatencyStats(object):
60 """ Stores expected data for comparison with actual input latency stats """ 60 """ Stores expected data for comparison with actual input latency stats """
61 def __init__(self): 61 def __init__(self):
62 self.mouse_wheel_scroll_latency = [] 62 self.mouse_wheel_scroll_latency = []
63 self.touch_scroll_latency = [] 63 self.touch_scroll_latency = []
64 self.js_touch_scroll_latency = []
64 self.mouse_wheel_scroll_events = [] 65 self.mouse_wheel_scroll_events = []
65 self.touch_scroll_events = [] 66 self.touch_scroll_events = []
67 self.js_touch_scroll_events = []
66 68
67 def AddMainThreadRenderingStats(mock_timer, thread, first_frame, 69 def AddMainThreadRenderingStats(mock_timer, thread, first_frame,
68 ref_stats = None): 70 ref_stats = None):
69 """ Adds a random main thread rendering stats event. 71 """ Adds a random main thread rendering stats event.
70 72
71 thread: The timeline model thread to which the event will be added. 73 thread: The timeline model thread to which the event will be added.
72 first_frame: Is this the first frame within the bounds of an action? 74 first_frame: Is this the first frame within the bounds of an action?
73 ref_stats: A ReferenceRenderingStats object to record expected values. 75 ref_stats: A ReferenceRenderingStats object to record expected values.
74 """ 76 """
75 # Create randonm data and timestap for main thread rendering stats. 77 # Create randonm data and timestap for main thread rendering stats.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 start_thread.AddAsyncSlice(async_slice) 181 start_thread.AddAsyncSlice(async_slice)
180 182
181 if not ref_latency_stats: 183 if not ref_latency_stats:
182 return 184 return
183 185
184 if input_type == 'MouseWheel': 186 if input_type == 'MouseWheel':
185 ref_latency_stats.mouse_wheel_scroll_events.append(async_sub_slice) 187 ref_latency_stats.mouse_wheel_scroll_events.append(async_sub_slice)
186 ref_latency_stats.mouse_wheel_scroll_latency.append( 188 ref_latency_stats.mouse_wheel_scroll_latency.append(
187 (data[END_COMP_NAME]['time'] - data[BEGIN_COMP_NAME]['time']) / 1000.0) 189 (data[END_COMP_NAME]['time'] - data[BEGIN_COMP_NAME]['time']) / 1000.0)
188 190
189
190 if input_type == 'GestureScrollUpdate': 191 if input_type == 'GestureScrollUpdate':
191 ref_latency_stats.touch_scroll_events.append(async_sub_slice) 192 ref_latency_stats.touch_scroll_events.append(async_sub_slice)
192 ref_latency_stats.touch_scroll_latency.append( 193 ref_latency_stats.touch_scroll_latency.append(
193 (data[END_COMP_NAME]['time'] - data[UI_COMP_NAME]['time']) / 1000.0) 194 (data[END_COMP_NAME]['time'] - data[UI_COMP_NAME]['time']) / 1000.0)
194 195
196 if input_type == 'TouchMove':
197 ref_latency_stats.js_touch_scroll_events.append(async_sub_slice)
198 ref_latency_stats.js_touch_scroll_latency.append(
199 (data[END_COMP_NAME]['time'] - data[UI_COMP_NAME]['time']) / 1000.0)
200
195 class RenderingStatsUnitTest(unittest.TestCase): 201 class RenderingStatsUnitTest(unittest.TestCase):
196 def testFromTimeline(self): 202 def testFromTimeline(self):
197 timeline = model.TimelineModel() 203 timeline = model.TimelineModel()
198 204
199 # Create a browser process and a renderer process, and a main thread and 205 # Create a browser process and a renderer process, and a main thread and
200 # impl thread for each. 206 # impl thread for each.
201 browser = timeline.GetOrCreateProcess(pid = 1) 207 browser = timeline.GetOrCreateProcess(pid = 1)
202 browser_main = browser.GetOrCreateThread(tid = 11) 208 browser_main = browser.GetOrCreateThread(tid = 11)
203 browser_compositor = browser.GetOrCreateThread(tid = 12) 209 browser_compositor = browser.GetOrCreateThread(tid = 12)
204 renderer = timeline.GetOrCreateProcess(pid = 2) 210 renderer = timeline.GetOrCreateProcess(pid = 2)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 ref_latency_stats = ReferenceInputLatencyStats() 293 ref_latency_stats = ReferenceInputLatencyStats()
288 294
289 # Create 10 input latency stats events for Action A. 295 # Create 10 input latency stats events for Action A.
290 timer.Advance() 296 timer.Advance()
291 renderer_main.BeginSlice('webkit.console', 'ActionA', timer.Get(), '') 297 renderer_main.BeginSlice('webkit.console', 'ActionA', timer.Get(), '')
292 for _ in xrange(0, 10): 298 for _ in xrange(0, 10):
293 AddInputLatencyStats(timer, 'MouseWheel', browser_main, 299 AddInputLatencyStats(timer, 'MouseWheel', browser_main,
294 renderer_main, ref_latency_stats) 300 renderer_main, ref_latency_stats)
295 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, 301 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main,
296 renderer_main, ref_latency_stats) 302 renderer_main, ref_latency_stats)
303 AddInputLatencyStats(timer, 'TouchMove', browser_main,
304 renderer_main, ref_latency_stats)
297 renderer_main.EndSlice(timer.Get()) 305 renderer_main.EndSlice(timer.Get())
298 306
299 # Create 5 input latency stats events not within any action. 307 # Create 5 input latency stats events not within any action.
300 for _ in xrange(0, 5): 308 for _ in xrange(0, 5):
301 AddInputLatencyStats(timer, 'MouseWheel', browser_main, 309 AddInputLatencyStats(timer, 'MouseWheel', browser_main,
302 renderer_main, None) 310 renderer_main, None)
303 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, 311 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main,
304 renderer_main, None) 312 renderer_main, None)
313 AddInputLatencyStats(timer, 'TouchMove', browser_main,
314 renderer_main, None)
305 315
306 # Create 10 input latency stats events for Action B. 316 # Create 10 input latency stats events for Action B.
307 timer.Advance() 317 timer.Advance()
308 renderer_main.BeginSlice('webkit.console', 'ActionB', timer.Get(), '') 318 renderer_main.BeginSlice('webkit.console', 'ActionB', timer.Get(), '')
309 for _ in xrange(0, 10): 319 for _ in xrange(0, 10):
310 AddInputLatencyStats(timer, 'MouseWheel', browser_main, 320 AddInputLatencyStats(timer, 'MouseWheel', browser_main,
311 renderer_main, ref_latency_stats) 321 renderer_main, ref_latency_stats)
312 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, 322 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main,
313 renderer_main, ref_latency_stats) 323 renderer_main, ref_latency_stats)
324 AddInputLatencyStats(timer, 'TouchMove', browser_main,
325 renderer_main, ref_latency_stats)
314 renderer_main.EndSlice(timer.Get()) 326 renderer_main.EndSlice(timer.Get())
315 327
316 # Create 10 input latency stats events for Action A. 328 # Create 10 input latency stats events for Action A.
317 timer.Advance() 329 timer.Advance()
318 renderer_main.BeginSlice('webkit.console', 'ActionA', timer.Get(), '') 330 renderer_main.BeginSlice('webkit.console', 'ActionA', timer.Get(), '')
319 for _ in xrange(0, 10): 331 for _ in xrange(0, 10):
320 AddInputLatencyStats(timer, 'MouseWheel', browser_main, 332 AddInputLatencyStats(timer, 'MouseWheel', browser_main,
321 renderer_main, ref_latency_stats) 333 renderer_main, ref_latency_stats)
322 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, 334 AddInputLatencyStats(timer, 'GestureScrollUpdate', browser_main,
323 renderer_main, ref_latency_stats) 335 renderer_main, ref_latency_stats)
336 AddInputLatencyStats(timer, 'TouchMove', browser_main,
337 renderer_main, ref_latency_stats)
324 renderer_main.EndSlice(timer.Get()) 338 renderer_main.EndSlice(timer.Get())
325 339
326 browser_main.FinalizeImport() 340 browser_main.FinalizeImport()
327 renderer_main.FinalizeImport() 341 renderer_main.FinalizeImport()
328 342
329 mouse_wheel_scroll_events = [] 343 mouse_wheel_scroll_events = []
330 touch_scroll_events = [] 344 touch_scroll_events = []
345 js_touch_scroll_events = []
331 346
332 timeline_markers = timeline.FindTimelineMarkers( 347 timeline_markers = timeline.FindTimelineMarkers(
333 ['ActionA', 'ActionB', 'ActionA']) 348 ['ActionA', 'ActionB', 'ActionA'])
334 for timeline_range in [ timeline_bounds.Bounds.CreateFromEvent(marker) 349 for timeline_range in [ timeline_bounds.Bounds.CreateFromEvent(marker)
335 for marker in timeline_markers ]: 350 for marker in timeline_markers ]:
336 if timeline_range.is_empty: 351 if timeline_range.is_empty:
337 continue 352 continue
338 tmp_mouse_events, tmp_touch_events = GetScrollInputLatencyEvents( 353 tmp_mouse_events = GetScrollInputLatencyEvents(
339 browser, timeline_range) 354 'MouseWheel', browser, timeline_range)
355 tmp_touch_scroll_events = GetScrollInputLatencyEvents(
356 'GestureScrollUpdate', browser, timeline_range)
357 tmp_js_touch_scroll_events = GetScrollInputLatencyEvents(
358 'TouchMove', browser, timeline_range)
340 mouse_wheel_scroll_events.extend(tmp_mouse_events) 359 mouse_wheel_scroll_events.extend(tmp_mouse_events)
341 touch_scroll_events.extend(tmp_touch_events) 360 touch_scroll_events.extend(tmp_touch_scroll_events)
361 js_touch_scroll_events.extend(tmp_js_touch_scroll_events)
342 362
343 self.assertEquals(mouse_wheel_scroll_events, 363 self.assertEquals(mouse_wheel_scroll_events,
344 ref_latency_stats.mouse_wheel_scroll_events) 364 ref_latency_stats.mouse_wheel_scroll_events)
345 self.assertEquals(touch_scroll_events, 365 self.assertEquals(touch_scroll_events,
346 ref_latency_stats.touch_scroll_events) 366 ref_latency_stats.touch_scroll_events)
367 self.assertEquals(js_touch_scroll_events,
368 ref_latency_stats.js_touch_scroll_events)
347 self.assertEquals(ComputeMouseWheelScrollLatency(mouse_wheel_scroll_events), 369 self.assertEquals(ComputeMouseWheelScrollLatency(mouse_wheel_scroll_events),
348 ref_latency_stats.mouse_wheel_scroll_latency) 370 ref_latency_stats.mouse_wheel_scroll_latency)
349 self.assertEquals(ComputeTouchScrollLatency(touch_scroll_events), 371 self.assertEquals(ComputeTouchScrollLatency(touch_scroll_events),
350 ref_latency_stats.touch_scroll_latency) 372 ref_latency_stats.touch_scroll_latency)
373 self.assertEquals(ComputeTouchScrollLatency(js_touch_scroll_events),
374 ref_latency_stats.js_touch_scroll_latency)
OLDNEW
« no previous file with comments | « tools/perf/metrics/rendering_stats.py ('k') | tools/perf/metrics/smoothness.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698