| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import telemetry.timeline.async_slice as tracing_async_slice | 8 import telemetry.timeline.async_slice as tracing_async_slice |
| 9 import telemetry.timeline.bounds as timeline_bounds | 9 import telemetry.timeline.bounds as timeline_bounds |
| 10 from telemetry.perf_tests_helper import FlattenList | 10 from telemetry.perf_tests_helper import FlattenList |
| 11 from telemetry.timeline import model | 11 from telemetry.timeline import model |
| 12 from telemetry.util.statistics import DivideIfPossibleOrZero | 12 from telemetry.util.statistics import DivideIfPossibleOrZero |
| 13 from telemetry.web_perf.metrics.rendering_stats import ( | 13 from telemetry.web_perf.metrics.rendering_stats import ( |
| 14 BEGIN_COMP_NAME, | 14 BEGIN_COMP_NAME, |
| 15 BEGIN_SCROLL_UPDATE_COMP_NAME, | 15 BEGIN_SCROLL_UPDATE_COMP_NAME, |
| 16 END_COMP_NAME, | 16 END_COMP_NAME, |
| 17 FORWARD_SCROLL_UPDATE_COMP_NAME, | 17 FORWARD_SCROLL_UPDATE_COMP_NAME, |
| 18 GESTURE_SCROLL_UPDATE_EVENT_NAME, | 18 GESTURE_SCROLL_UPDATE_EVENT_NAME, |
| 19 ORIGINAL_COMP_NAME, | 19 ORIGINAL_COMP_NAME, |
| 20 SCROLL_UPDATE_EVENT_NAME, | 20 SCROLL_UPDATE_EVENT_NAME, |
| 21 UI_COMP_NAME) | 21 UI_COMP_NAME) |
| 22 from telemetry.web_perf.metrics.rendering_stats import ( | 22 from telemetry.web_perf.metrics.rendering_stats import ( |
| 23 ComputeInputEventLatencies) | 23 ComputeInputEventLatencies) |
| 24 from telemetry.web_perf.metrics.rendering_stats import GetInputLatencyEvents | 24 from telemetry.web_perf.metrics.rendering_stats import GetInputLatencyEvents |
| 25 from telemetry.web_perf.metrics.rendering_stats import HasRenderingStats | 25 from telemetry.web_perf.metrics.rendering_stats import HasRenderingStats |
| 26 from telemetry.web_perf.metrics.rendering_stats import NotEnoughFramesError | |
| 27 from telemetry.web_perf.metrics.rendering_stats import RenderingStats | 26 from telemetry.web_perf.metrics.rendering_stats import RenderingStats |
| 28 | 27 |
| 29 | 28 |
| 30 class MockTimer(object): | 29 class MockTimer(object): |
| 31 """A mock timer class which can generate random durations. | 30 """A mock timer class which can generate random durations. |
| 32 | 31 |
| 33 An instance of this class is used as a global timer to generate random | 32 An instance of this class is used as a global timer to generate random |
| 34 durations for stats and consistent timestamps for all mock trace events. | 33 durations for stats and consistent timestamps for all mock trace events. |
| 35 The unit of time is milliseconds. | 34 The unit of time is milliseconds. |
| 36 """ | 35 """ |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 timer.Advance(2, 4) | 294 timer.Advance(2, 4) |
| 296 renderer_main.BeginSlice('webkit.console', 'ActionB', timer.Get(), '') | 295 renderer_main.BeginSlice('webkit.console', 'ActionB', timer.Get(), '') |
| 297 timer.Advance(2, 4) | 296 timer.Advance(2, 4) |
| 298 renderer_main.EndSlice(timer.Get()) | 297 renderer_main.EndSlice(timer.Get()) |
| 299 | 298 |
| 300 renderer.FinalizeImport() | 299 renderer.FinalizeImport() |
| 301 | 300 |
| 302 timeline_markers = timeline.FindTimelineMarkers(['ActionA', 'ActionB']) | 301 timeline_markers = timeline.FindTimelineMarkers(['ActionA', 'ActionB']) |
| 303 timeline_ranges = [ timeline_bounds.Bounds.CreateFromEvent(marker) | 302 timeline_ranges = [ timeline_bounds.Bounds.CreateFromEvent(marker) |
| 304 for marker in timeline_markers ] | 303 for marker in timeline_markers ] |
| 305 self.assertRaises(NotEnoughFramesError, RenderingStats, | 304 |
| 306 renderer, None, timeline_ranges) | 305 stats = RenderingStats(renderer, None, timeline_ranges) |
| 306 self.assertEquals(0, len(stats.frame_timestamps[1])) |
| 307 |
| 307 | 308 |
| 308 def testFromTimeline(self): | 309 def testFromTimeline(self): |
| 309 timeline = model.TimelineModel() | 310 timeline = model.TimelineModel() |
| 310 | 311 |
| 311 # Create a browser process and a renderer process, and a main thread and | 312 # Create a browser process and a renderer process, and a main thread and |
| 312 # impl thread for each. | 313 # impl thread for each. |
| 313 browser = timeline.GetOrCreateProcess(pid = 1) | 314 browser = timeline.GetOrCreateProcess(pid = 1) |
| 314 browser_main = browser.GetOrCreateThread(tid = 11) | 315 browser_main = browser.GetOrCreateThread(tid = 11) |
| 315 browser_compositor = browser.GetOrCreateThread(tid = 12) | 316 browser_compositor = browser.GetOrCreateThread(tid = 12) |
| 316 renderer = timeline.GetOrCreateProcess(pid = 2) | 317 renderer = timeline.GetOrCreateProcess(pid = 2) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 stats = RenderingStats(renderer, browser, timeline_ranges) | 472 stats = RenderingStats(renderer, browser, timeline_ranges) |
| 472 self.assertEquals(FlattenList(stats.input_event_latency), [ | 473 self.assertEquals(FlattenList(stats.input_event_latency), [ |
| 473 latency for name, latency in ref_latency.input_event_latency | 474 latency for name, latency in ref_latency.input_event_latency |
| 474 if name != SCROLL_UPDATE_EVENT_NAME]) | 475 if name != SCROLL_UPDATE_EVENT_NAME]) |
| 475 self.assertEquals(FlattenList(stats.scroll_update_latency), [ | 476 self.assertEquals(FlattenList(stats.scroll_update_latency), [ |
| 476 latency for name, latency in ref_latency.input_event_latency | 477 latency for name, latency in ref_latency.input_event_latency |
| 477 if name == SCROLL_UPDATE_EVENT_NAME]) | 478 if name == SCROLL_UPDATE_EVENT_NAME]) |
| 478 self.assertEquals(FlattenList(stats.gesture_scroll_update_latency), [ | 479 self.assertEquals(FlattenList(stats.gesture_scroll_update_latency), [ |
| 479 latency for name, latency in ref_latency.input_event_latency | 480 latency for name, latency in ref_latency.input_event_latency |
| 480 if name == GESTURE_SCROLL_UPDATE_EVENT_NAME]) | 481 if name == GESTURE_SCROLL_UPDATE_EVENT_NAME]) |
| OLD | NEW |