| 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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 class ReferenceRenderingStats(object): | 48 class ReferenceRenderingStats(object): |
| 49 """ Stores expected data for comparison with actual RenderingStats """ | 49 """ Stores expected data for comparison with actual RenderingStats """ |
| 50 def __init__(self): | 50 def __init__(self): |
| 51 self.frame_timestamps = [] | 51 self.frame_timestamps = [] |
| 52 self.frame_times = [] | 52 self.frame_times = [] |
| 53 self.paint_times = [] | 53 self.paint_times = [] |
| 54 self.painted_pixel_counts = [] | 54 self.painted_pixel_counts = [] |
| 55 self.record_times = [] | 55 self.record_times = [] |
| 56 self.recorded_pixel_counts = [] | 56 self.recorded_pixel_counts = [] |
| 57 self.rasterize_times = [] | |
| 58 self.rasterized_pixel_counts = [] | |
| 59 self.approximated_pixel_percentages = [] | 57 self.approximated_pixel_percentages = [] |
| 60 | 58 |
| 61 def AppendNewRange(self): | 59 def AppendNewRange(self): |
| 62 self.frame_timestamps.append([]) | 60 self.frame_timestamps.append([]) |
| 63 self.frame_times.append([]) | 61 self.frame_times.append([]) |
| 64 self.paint_times.append([]) | 62 self.paint_times.append([]) |
| 65 self.painted_pixel_counts.append([]) | 63 self.painted_pixel_counts.append([]) |
| 66 self.record_times.append([]) | 64 self.record_times.append([]) |
| 67 self.recorded_pixel_counts.append([]) | 65 self.recorded_pixel_counts.append([]) |
| 68 self.rasterize_times.append([]) | |
| 69 self.rasterized_pixel_counts.append([]) | |
| 70 self.approximated_pixel_percentages.append([]) | 66 self.approximated_pixel_percentages.append([]) |
| 71 | 67 |
| 72 class ReferenceInputLatencyStats(object): | 68 class ReferenceInputLatencyStats(object): |
| 73 """ Stores expected data for comparison with actual input latency stats """ | 69 """ Stores expected data for comparison with actual input latency stats """ |
| 74 def __init__(self): | 70 def __init__(self): |
| 75 self.input_event_latency = [] | 71 self.input_event_latency = [] |
| 76 self.input_event = [] | 72 self.input_event = [] |
| 77 | 73 |
| 78 def AddMainThreadRenderingStats(mock_timer, thread, ref_stats = None): | 74 def AddMainThreadRenderingStats(mock_timer, thread, ref_stats = None): |
| 79 """ Adds a random main thread rendering stats event. | 75 """ Adds a random main thread rendering stats event. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 def AddImplThreadRenderingStats(mock_timer, thread, first_frame, | 133 def AddImplThreadRenderingStats(mock_timer, thread, first_frame, |
| 138 ref_stats = None): | 134 ref_stats = None): |
| 139 """ Adds a random impl thread rendering stats event. | 135 """ Adds a random impl thread rendering stats event. |
| 140 | 136 |
| 141 thread: The timeline model thread to which the event will be added. | 137 thread: The timeline model thread to which the event will be added. |
| 142 first_frame: Is this the first frame within the bounds of an action? | 138 first_frame: Is this the first frame within the bounds of an action? |
| 143 ref_stats: A ReferenceRenderingStats object to record expected values. | 139 ref_stats: A ReferenceRenderingStats object to record expected values. |
| 144 """ | 140 """ |
| 145 # Create randonm data and timestap for impl thread rendering stats. | 141 # Create randonm data and timestap for impl thread rendering stats. |
| 146 data = { 'frame_count': 1, | 142 data = { 'frame_count': 1, |
| 147 'rasterize_time': mock_timer.Advance(5, 10) / 1000.0, | |
| 148 'rasterized_pixel_count': 1280*720, | |
| 149 'visible_content_area': random.uniform(0, 100), | 143 'visible_content_area': random.uniform(0, 100), |
| 150 'approximated_visible_content_area': random.uniform(0, 5)} | 144 'approximated_visible_content_area': random.uniform(0, 5)} |
| 151 timestamp = mock_timer.Get() | 145 timestamp = mock_timer.Get() |
| 152 | 146 |
| 153 # Add a slice with the event data to the given thread. | 147 # Add a slice with the event data to the given thread. |
| 154 thread.PushCompleteSlice( | 148 thread.PushCompleteSlice( |
| 155 'benchmark', 'BenchmarkInstrumentation::ImplThreadRenderingStats', | 149 'benchmark', 'BenchmarkInstrumentation::ImplThreadRenderingStats', |
| 156 timestamp, duration=0.0, thread_timestamp=None, thread_duration=None, | 150 timestamp, duration=0.0, thread_timestamp=None, thread_duration=None, |
| 157 args={'data': data}) | 151 args={'data': data}) |
| 158 | 152 |
| 159 if not ref_stats: | 153 if not ref_stats: |
| 160 return | 154 return |
| 161 | 155 |
| 162 # Add timestamp only if a frame was output | 156 # Add timestamp only if a frame was output |
| 163 if data['frame_count'] == 1: | 157 if data['frame_count'] == 1: |
| 164 if not first_frame: | 158 if not first_frame: |
| 165 # Add frame_time if this is not the first frame in within the bounds of an | 159 # Add frame_time if this is not the first frame in within the bounds of an |
| 166 # action. | 160 # action. |
| 167 prev_timestamp = ref_stats.frame_timestamps[-1][-1] | 161 prev_timestamp = ref_stats.frame_timestamps[-1][-1] |
| 168 ref_stats.frame_times[-1].append(round(timestamp - prev_timestamp, 2)) | 162 ref_stats.frame_times[-1].append(round(timestamp - prev_timestamp, 2)) |
| 169 ref_stats.frame_timestamps[-1].append(timestamp) | 163 ref_stats.frame_timestamps[-1].append(timestamp) |
| 170 | 164 |
| 171 ref_stats.rasterize_times[-1].append(data['rasterize_time'] * 1000.0) | |
| 172 ref_stats.rasterized_pixel_counts[-1].append(data['rasterized_pixel_count']) | |
| 173 ref_stats.approximated_pixel_percentages[-1].append( | 165 ref_stats.approximated_pixel_percentages[-1].append( |
| 174 round(DivideIfPossibleOrZero(data['approximated_visible_content_area'], | 166 round(DivideIfPossibleOrZero(data['approximated_visible_content_area'], |
| 175 data['visible_content_area']) * 100.0, 3)) | 167 data['visible_content_area']) * 100.0, 3)) |
| 176 | 168 |
| 177 | 169 |
| 178 def AddInputLatencyStats(mock_timer, start_thread, end_thread, | 170 def AddInputLatencyStats(mock_timer, start_thread, end_thread, |
| 179 ref_latency_stats = None): | 171 ref_latency_stats = None): |
| 180 """ Adds a random input latency stats event. | 172 """ Adds a random input latency stats event. |
| 181 | 173 |
| 182 start_thread: The start thread on which the async slice is added. | 174 start_thread: The start thread on which the async slice is added. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 timeline_markers = timeline.FindTimelineMarkers( | 437 timeline_markers = timeline.FindTimelineMarkers( |
| 446 ['ActionA', 'ActionB', 'ActionA']) | 438 ['ActionA', 'ActionB', 'ActionA']) |
| 447 timeline_ranges = [ timeline_bounds.Bounds.CreateFromEvent(marker) | 439 timeline_ranges = [ timeline_bounds.Bounds.CreateFromEvent(marker) |
| 448 for marker in timeline_markers ] | 440 for marker in timeline_markers ] |
| 449 stats = RenderingStats(renderer, browser, timeline_ranges) | 441 stats = RenderingStats(renderer, browser, timeline_ranges) |
| 450 | 442 |
| 451 # Compare rendering stats to reference. | 443 # Compare rendering stats to reference. |
| 452 self.assertEquals(stats.frame_timestamps, | 444 self.assertEquals(stats.frame_timestamps, |
| 453 browser_ref_stats.frame_timestamps) | 445 browser_ref_stats.frame_timestamps) |
| 454 self.assertEquals(stats.frame_times, browser_ref_stats.frame_times) | 446 self.assertEquals(stats.frame_times, browser_ref_stats.frame_times) |
| 455 self.assertEquals(stats.rasterize_times, renderer_ref_stats.rasterize_times) | |
| 456 self.assertEquals(stats.rasterized_pixel_counts, | |
| 457 renderer_ref_stats.rasterized_pixel_counts) | |
| 458 self.assertEquals(stats.approximated_pixel_percentages, | 447 self.assertEquals(stats.approximated_pixel_percentages, |
| 459 renderer_ref_stats.approximated_pixel_percentages) | 448 renderer_ref_stats.approximated_pixel_percentages) |
| 460 self.assertEquals(stats.paint_times, renderer_ref_stats.paint_times) | 449 self.assertEquals(stats.paint_times, renderer_ref_stats.paint_times) |
| 461 self.assertEquals(stats.painted_pixel_counts, | 450 self.assertEquals(stats.painted_pixel_counts, |
| 462 renderer_ref_stats.painted_pixel_counts) | 451 renderer_ref_stats.painted_pixel_counts) |
| 463 self.assertEquals(stats.record_times, renderer_ref_stats.record_times) | 452 self.assertEquals(stats.record_times, renderer_ref_stats.record_times) |
| 464 self.assertEquals(stats.recorded_pixel_counts, | 453 self.assertEquals(stats.recorded_pixel_counts, |
| 465 renderer_ref_stats.recorded_pixel_counts) | 454 renderer_ref_stats.recorded_pixel_counts) |
| 466 | 455 |
| 467 def testInputLatencyFromTimeline(self): | 456 def testInputLatencyFromTimeline(self): |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 stats = RenderingStats(renderer, browser, timeline_ranges) | 516 stats = RenderingStats(renderer, browser, timeline_ranges) |
| 528 self.assertEquals(FlattenList(stats.input_event_latency), [ | 517 self.assertEquals(FlattenList(stats.input_event_latency), [ |
| 529 latency for name, latency in ref_latency.input_event_latency | 518 latency for name, latency in ref_latency.input_event_latency |
| 530 if name != SCROLL_UPDATE_EVENT_NAME]) | 519 if name != SCROLL_UPDATE_EVENT_NAME]) |
| 531 self.assertEquals(FlattenList(stats.scroll_update_latency), [ | 520 self.assertEquals(FlattenList(stats.scroll_update_latency), [ |
| 532 latency for name, latency in ref_latency.input_event_latency | 521 latency for name, latency in ref_latency.input_event_latency |
| 533 if name == SCROLL_UPDATE_EVENT_NAME]) | 522 if name == SCROLL_UPDATE_EVENT_NAME]) |
| 534 self.assertEquals(FlattenList(stats.gesture_scroll_update_latency), [ | 523 self.assertEquals(FlattenList(stats.gesture_scroll_update_latency), [ |
| 535 latency for name, latency in ref_latency.input_event_latency | 524 latency for name, latency in ref_latency.input_event_latency |
| 536 if name == GESTURE_SCROLL_UPDATE_EVENT_NAME]) | 525 if name == GESTURE_SCROLL_UPDATE_EVENT_NAME]) |
| OLD | NEW |