| 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 from telemetry.perf_tests_helper import FlattenList | 8 from telemetry.perf_tests_helper import FlattenList |
| 9 import telemetry.timeline.async_slice as tracing_async_slice | 9 import telemetry.timeline.async_slice as tracing_async_slice |
| 10 import telemetry.timeline.bounds as timeline_bounds | 10 import telemetry.timeline.bounds as timeline_bounds |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return self.milliseconds | 47 return self.milliseconds |
| 48 | 48 |
| 49 | 49 |
| 50 class ReferenceRenderingStats(object): | 50 class ReferenceRenderingStats(object): |
| 51 """ Stores expected data for comparison with actual RenderingStats """ | 51 """ Stores expected data for comparison with actual RenderingStats """ |
| 52 | 52 |
| 53 def __init__(self): | 53 def __init__(self): |
| 54 self.frame_timestamps = [] | 54 self.frame_timestamps = [] |
| 55 self.frame_times = [] | 55 self.frame_times = [] |
| 56 self.approximated_pixel_percentages = [] | 56 self.approximated_pixel_percentages = [] |
| 57 self.checkerboarded_pixel_percentages = [] |
| 57 | 58 |
| 58 def AppendNewRange(self): | 59 def AppendNewRange(self): |
| 59 self.frame_timestamps.append([]) | 60 self.frame_timestamps.append([]) |
| 60 self.frame_times.append([]) | 61 self.frame_times.append([]) |
| 61 self.approximated_pixel_percentages.append([]) | 62 self.approximated_pixel_percentages.append([]) |
| 63 self.checkerboarded_pixel_percentages.append([]) |
| 62 | 64 |
| 63 | 65 |
| 64 class ReferenceInputLatencyStats(object): | 66 class ReferenceInputLatencyStats(object): |
| 65 """ Stores expected data for comparison with actual input latency stats """ | 67 """ Stores expected data for comparison with actual input latency stats """ |
| 66 | 68 |
| 67 def __init__(self): | 69 def __init__(self): |
| 68 self.input_event_latency = [] | 70 self.input_event_latency = [] |
| 69 self.input_event = [] | 71 self.input_event = [] |
| 70 | 72 |
| 71 | 73 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 ref_stats=None): | 137 ref_stats=None): |
| 136 """ Adds a random impl thread rendering stats event. | 138 """ Adds a random impl thread rendering stats event. |
| 137 | 139 |
| 138 thread: The timeline model thread to which the event will be added. | 140 thread: The timeline model thread to which the event will be added. |
| 139 first_frame: Is this the first frame within the bounds of an action? | 141 first_frame: Is this the first frame within the bounds of an action? |
| 140 ref_stats: A ReferenceRenderingStats object to record expected values. | 142 ref_stats: A ReferenceRenderingStats object to record expected values. |
| 141 """ | 143 """ |
| 142 # Create randonm data and timestap for impl thread rendering stats. | 144 # Create randonm data and timestap for impl thread rendering stats. |
| 143 data = {'frame_count': 1, | 145 data = {'frame_count': 1, |
| 144 'visible_content_area': random.uniform(0, 100), | 146 'visible_content_area': random.uniform(0, 100), |
| 145 'approximated_visible_content_area': random.uniform(0, 5)} | 147 'approximated_visible_content_area': random.uniform(0, 5), |
| 148 'checkerboarded_visible_content_area': random.uniform(0, 5)} |
| 146 timestamp = mock_timer.AdvanceAndGet() | 149 timestamp = mock_timer.AdvanceAndGet() |
| 147 | 150 |
| 148 # Add a slice with the event data to the given thread. | 151 # Add a slice with the event data to the given thread. |
| 149 thread.PushCompleteSlice( | 152 thread.PushCompleteSlice( |
| 150 'benchmark', 'BenchmarkInstrumentation::ImplThreadRenderingStats', | 153 'benchmark', 'BenchmarkInstrumentation::ImplThreadRenderingStats', |
| 151 timestamp, duration=0.0, thread_timestamp=None, thread_duration=None, | 154 timestamp, duration=0.0, thread_timestamp=None, thread_duration=None, |
| 152 args={'data': data}) | 155 args={'data': data}) |
| 153 | 156 |
| 154 if not ref_stats: | 157 if not ref_stats: |
| 155 return | 158 return |
| 156 | 159 |
| 157 # Add timestamp only if a frame was output | 160 # Add timestamp only if a frame was output |
| 158 if data['frame_count'] == 1: | 161 if data['frame_count'] == 1: |
| 159 if not first_frame: | 162 if not first_frame: |
| 160 # Add frame_time if this is not the first frame in within the bounds of an | 163 # Add frame_time if this is not the first frame in within the bounds of an |
| 161 # action. | 164 # action. |
| 162 prev_timestamp = ref_stats.frame_timestamps[-1][-1] | 165 prev_timestamp = ref_stats.frame_timestamps[-1][-1] |
| 163 ref_stats.frame_times[-1].append(round(timestamp - prev_timestamp, 2)) | 166 ref_stats.frame_times[-1].append(round(timestamp - prev_timestamp, 2)) |
| 164 ref_stats.frame_timestamps[-1].append(timestamp) | 167 ref_stats.frame_timestamps[-1].append(timestamp) |
| 165 | 168 |
| 166 ref_stats.approximated_pixel_percentages[-1].append( | 169 ref_stats.approximated_pixel_percentages[-1].append( |
| 167 round(DivideIfPossibleOrZero(data['approximated_visible_content_area'], | 170 round(DivideIfPossibleOrZero(data['approximated_visible_content_area'], |
| 168 data['visible_content_area']) * 100.0, 3)) | 171 data['visible_content_area']) * 100.0, 3)) |
| 169 | 172 |
| 173 ref_stats.checkerboarded_pixel_percentages[-1].append( |
| 174 round(DivideIfPossibleOrZero(data['checkerboarded_visible_content_area'], |
| 175 data['visible_content_area']) * 100.0, 3)) |
| 170 | 176 |
| 171 def AddInputLatencyStats(mock_timer, start_thread, end_thread, | 177 def AddInputLatencyStats(mock_timer, start_thread, end_thread, |
| 172 ref_latency_stats=None): | 178 ref_latency_stats=None): |
| 173 """ Adds a random input latency stats event. | 179 """ Adds a random input latency stats event. |
| 174 | 180 |
| 175 start_thread: The start thread on which the async slice is added. | 181 start_thread: The start thread on which the async slice is added. |
| 176 end_thread: The end thread on which the async slice is ended. | 182 end_thread: The end thread on which the async slice is ended. |
| 177 ref_latency_stats: A ReferenceInputLatencyStats object for expected values. | 183 ref_latency_stats: A ReferenceInputLatencyStats object for expected values. |
| 178 """ | 184 """ |
| 179 | 185 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 timeline_ranges = [timeline_bounds.Bounds.CreateFromEvent(marker) | 461 timeline_ranges = [timeline_bounds.Bounds.CreateFromEvent(marker) |
| 456 for marker in timeline_markers] | 462 for marker in timeline_markers] |
| 457 stats = RenderingStats(renderer, browser, None, timeline_ranges) | 463 stats = RenderingStats(renderer, browser, None, timeline_ranges) |
| 458 | 464 |
| 459 # Compare rendering stats to reference. | 465 # Compare rendering stats to reference. |
| 460 self.assertEquals(stats.frame_timestamps, | 466 self.assertEquals(stats.frame_timestamps, |
| 461 browser_ref_stats.frame_timestamps) | 467 browser_ref_stats.frame_timestamps) |
| 462 self.assertEquals(stats.frame_times, browser_ref_stats.frame_times) | 468 self.assertEquals(stats.frame_times, browser_ref_stats.frame_times) |
| 463 self.assertEquals(stats.approximated_pixel_percentages, | 469 self.assertEquals(stats.approximated_pixel_percentages, |
| 464 renderer_ref_stats.approximated_pixel_percentages) | 470 renderer_ref_stats.approximated_pixel_percentages) |
| 471 self.assertEquals(stats.checkerboarded_pixel_percentages, |
| 472 renderer_ref_stats.checkerboarded_pixel_percentages) |
| 465 | 473 |
| 466 def testInputLatencyFromTimeline(self): | 474 def testInputLatencyFromTimeline(self): |
| 467 timeline = model.TimelineModel() | 475 timeline = model.TimelineModel() |
| 468 | 476 |
| 469 # Create a browser process and a renderer process. | 477 # Create a browser process and a renderer process. |
| 470 browser = timeline.GetOrCreateProcess(pid=1) | 478 browser = timeline.GetOrCreateProcess(pid=1) |
| 471 browser_main = browser.GetOrCreateThread(tid=11) | 479 browser_main = browser.GetOrCreateThread(tid=11) |
| 472 renderer = timeline.GetOrCreateProcess(pid=2) | 480 renderer = timeline.GetOrCreateProcess(pid=2) |
| 473 renderer_main = renderer.GetOrCreateThread(tid=21) | 481 renderer_main = renderer.GetOrCreateThread(tid=21) |
| 474 | 482 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 stats = RenderingStats(renderer, browser, None, timeline_ranges) | 531 stats = RenderingStats(renderer, browser, None, timeline_ranges) |
| 524 self.assertEquals(FlattenList(stats.input_event_latency), [ | 532 self.assertEquals(FlattenList(stats.input_event_latency), [ |
| 525 latency for name, latency in ref_latency.input_event_latency | 533 latency for name, latency in ref_latency.input_event_latency |
| 526 if name != SCROLL_UPDATE_EVENT_NAME]) | 534 if name != SCROLL_UPDATE_EVENT_NAME]) |
| 527 self.assertEquals(FlattenList(stats.scroll_update_latency), [ | 535 self.assertEquals(FlattenList(stats.scroll_update_latency), [ |
| 528 latency for name, latency in ref_latency.input_event_latency | 536 latency for name, latency in ref_latency.input_event_latency |
| 529 if name == SCROLL_UPDATE_EVENT_NAME]) | 537 if name == SCROLL_UPDATE_EVENT_NAME]) |
| 530 self.assertEquals(FlattenList(stats.gesture_scroll_update_latency), [ | 538 self.assertEquals(FlattenList(stats.gesture_scroll_update_latency), [ |
| 531 latency for name, latency in ref_latency.input_event_latency | 539 latency for name, latency in ref_latency.input_event_latency |
| 532 if name == GESTURE_SCROLL_UPDATE_EVENT_NAME]) | 540 if name == GESTURE_SCROLL_UPDATE_EVENT_NAME]) |
| OLD | NEW |