OLD | NEW |
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 |
11 from metrics.rendering_stats import ComputeTouchScrollLatency | 11 from metrics.rendering_stats import ComputeTouchScrollLatency |
12 from metrics.rendering_stats import HasRenderingStats | 12 from metrics.rendering_stats import HasRenderingStats |
13 from metrics.rendering_stats import RenderingStats | 13 from metrics.rendering_stats import RenderingStats |
| 14 from metrics.rendering_stats import NotEnoughFramesError |
14 import telemetry.core.timeline.bounds as timeline_bounds | 15 import telemetry.core.timeline.bounds as timeline_bounds |
15 from telemetry.core.timeline import model | 16 from telemetry.core.timeline import model |
16 import telemetry.core.timeline.async_slice as tracing_async_slice | 17 import telemetry.core.timeline.async_slice as tracing_async_slice |
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. |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 process_without_frames.FinalizeImport() | 218 process_without_frames.FinalizeImport() |
218 self.assertFalse(HasRenderingStats(thread_without_frames)) | 219 self.assertFalse(HasRenderingStats(thread_without_frames)) |
219 | 220 |
220 # A process with rendering stats and frames in them | 221 # A process with rendering stats and frames in them |
221 process_with_frames = timeline.GetOrCreateProcess(pid = 3) | 222 process_with_frames = timeline.GetOrCreateProcess(pid = 3) |
222 thread_with_frames = process_with_frames.GetOrCreateThread(tid = 31) | 223 thread_with_frames = process_with_frames.GetOrCreateThread(tid = 31) |
223 AddImplThreadRenderingStats(timer, thread_with_frames, True, None) | 224 AddImplThreadRenderingStats(timer, thread_with_frames, True, None) |
224 process_with_frames.FinalizeImport() | 225 process_with_frames.FinalizeImport() |
225 self.assertTrue(HasRenderingStats(thread_with_frames)) | 226 self.assertTrue(HasRenderingStats(thread_with_frames)) |
226 | 227 |
| 228 def testRangeWithoutFrames(self): |
| 229 timer = MockTimer() |
| 230 timeline = model.TimelineModel() |
| 231 |
| 232 # Create a renderer process, with a main thread and impl thread. |
| 233 renderer = timeline.GetOrCreateProcess(pid = 2) |
| 234 renderer_main = renderer.GetOrCreateThread(tid = 21) |
| 235 renderer_compositor = renderer.GetOrCreateThread(tid = 22) |
| 236 |
| 237 # Create 10 main and impl rendering stats events for Action A. |
| 238 timer.Advance(2, 4) |
| 239 renderer_main.BeginSlice('webkit.console', 'ActionA', timer.Get(), '') |
| 240 for i in xrange(0, 10): |
| 241 first = (i == 0) |
| 242 AddMainThreadRenderingStats(timer, renderer_main, first, None) |
| 243 AddImplThreadRenderingStats(timer, renderer_compositor, first, None) |
| 244 timer.Advance(2, 4) |
| 245 renderer_main.EndSlice(timer.Get()) |
| 246 |
| 247 # Create 5 main and impl rendering stats events not within any action. |
| 248 for i in xrange(0, 5): |
| 249 first = (i == 0) |
| 250 AddMainThreadRenderingStats(timer, renderer_main, first, None) |
| 251 AddImplThreadRenderingStats(timer, renderer_compositor, first, None) |
| 252 |
| 253 # Create Action B without any frames. This should trigger |
| 254 # NotEnoughFramesError when the RenderingStats object is created. |
| 255 timer.Advance(2, 4) |
| 256 renderer_main.BeginSlice('webkit.console', 'ActionB', timer.Get(), '') |
| 257 timer.Advance(2, 4) |
| 258 renderer_main.EndSlice(timer.Get()) |
| 259 |
| 260 renderer.FinalizeImport() |
| 261 |
| 262 timeline_markers = timeline.FindTimelineMarkers(['ActionA', 'ActionB']) |
| 263 timeline_ranges = [ timeline_bounds.Bounds.CreateFromEvent(marker) |
| 264 for marker in timeline_markers ] |
| 265 self.assertRaises(NotEnoughFramesError, RenderingStats, |
| 266 renderer, None, timeline_ranges) |
| 267 |
227 def testFromTimeline(self): | 268 def testFromTimeline(self): |
228 timeline = model.TimelineModel() | 269 timeline = model.TimelineModel() |
229 | 270 |
230 # Create a browser process and a renderer process, and a main thread and | 271 # Create a browser process and a renderer process, and a main thread and |
231 # impl thread for each. | 272 # impl thread for each. |
232 browser = timeline.GetOrCreateProcess(pid = 1) | 273 browser = timeline.GetOrCreateProcess(pid = 1) |
233 browser_main = browser.GetOrCreateThread(tid = 11) | 274 browser_main = browser.GetOrCreateThread(tid = 11) |
234 browser_compositor = browser.GetOrCreateThread(tid = 12) | 275 browser_compositor = browser.GetOrCreateThread(tid = 12) |
235 renderer = timeline.GetOrCreateProcess(pid = 2) | 276 renderer = timeline.GetOrCreateProcess(pid = 2) |
236 renderer_main = renderer.GetOrCreateThread(tid = 21) | 277 renderer_main = renderer.GetOrCreateThread(tid = 21) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 self.assertEquals(touch_scroll_events, | 441 self.assertEquals(touch_scroll_events, |
401 ref_latency_stats.touch_scroll_events) | 442 ref_latency_stats.touch_scroll_events) |
402 self.assertEquals(js_touch_scroll_events, | 443 self.assertEquals(js_touch_scroll_events, |
403 ref_latency_stats.js_touch_scroll_events) | 444 ref_latency_stats.js_touch_scroll_events) |
404 self.assertEquals(ComputeMouseWheelScrollLatency(mouse_wheel_scroll_events), | 445 self.assertEquals(ComputeMouseWheelScrollLatency(mouse_wheel_scroll_events), |
405 ref_latency_stats.mouse_wheel_scroll_latency) | 446 ref_latency_stats.mouse_wheel_scroll_latency) |
406 self.assertEquals(ComputeTouchScrollLatency(touch_scroll_events), | 447 self.assertEquals(ComputeTouchScrollLatency(touch_scroll_events), |
407 ref_latency_stats.touch_scroll_latency) | 448 ref_latency_stats.touch_scroll_latency) |
408 self.assertEquals(ComputeTouchScrollLatency(js_touch_scroll_events), | 449 self.assertEquals(ComputeTouchScrollLatency(js_touch_scroll_events), |
409 ref_latency_stats.js_touch_scroll_latency) | 450 ref_latency_stats.js_touch_scroll_latency) |
OLD | NEW |