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 from metrics.rendering_stats import NotEnoughFramesError |
| 15 from telemetry.util.statistics import DivideIfPossibleOrZero |
15 import telemetry.core.timeline.bounds as timeline_bounds | 16 import telemetry.core.timeline.bounds as timeline_bounds |
16 from telemetry.core.timeline import model | 17 from telemetry.core.timeline import model |
17 import telemetry.core.timeline.async_slice as tracing_async_slice | 18 import telemetry.core.timeline.async_slice as tracing_async_slice |
18 | 19 |
19 | 20 |
20 class MockTimer(object): | 21 class MockTimer(object): |
21 """A mock timer class which can generate random durations. | 22 """A mock timer class which can generate random durations. |
22 | 23 |
23 An instance of this class is used as a global timer to generate random | 24 An instance of this class is used as a global timer to generate random |
24 durations for stats and consistent timestamps for all mock trace events. | 25 durations for stats and consistent timestamps for all mock trace events. |
(...skipping 15 matching lines...) Expand all Loading... |
40 """ Stores expected data for comparison with actual RenderingStats """ | 41 """ Stores expected data for comparison with actual RenderingStats """ |
41 def __init__(self): | 42 def __init__(self): |
42 self.frame_timestamps = [] | 43 self.frame_timestamps = [] |
43 self.frame_times = [] | 44 self.frame_times = [] |
44 self.paint_times = [] | 45 self.paint_times = [] |
45 self.painted_pixel_counts = [] | 46 self.painted_pixel_counts = [] |
46 self.record_times = [] | 47 self.record_times = [] |
47 self.recorded_pixel_counts = [] | 48 self.recorded_pixel_counts = [] |
48 self.rasterize_times = [] | 49 self.rasterize_times = [] |
49 self.rasterized_pixel_counts = [] | 50 self.rasterized_pixel_counts = [] |
| 51 self.approximated_pixel_percentages = [] |
50 | 52 |
51 def AppendNewRange(self): | 53 def AppendNewRange(self): |
52 self.frame_timestamps.append([]) | 54 self.frame_timestamps.append([]) |
53 self.frame_times.append([]) | 55 self.frame_times.append([]) |
54 self.paint_times.append([]) | 56 self.paint_times.append([]) |
55 self.painted_pixel_counts.append([]) | 57 self.painted_pixel_counts.append([]) |
56 self.record_times.append([]) | 58 self.record_times.append([]) |
57 self.recorded_pixel_counts.append([]) | 59 self.recorded_pixel_counts.append([]) |
58 self.rasterize_times.append([]) | 60 self.rasterize_times.append([]) |
59 self.rasterized_pixel_counts.append([]) | 61 self.rasterized_pixel_counts.append([]) |
| 62 self.approximated_pixel_percentages.append([]) |
60 | 63 |
61 class ReferenceInputLatencyStats(object): | 64 class ReferenceInputLatencyStats(object): |
62 """ Stores expected data for comparison with actual input latency stats """ | 65 """ Stores expected data for comparison with actual input latency stats """ |
63 def __init__(self): | 66 def __init__(self): |
64 self.mouse_wheel_scroll_latency = [] | 67 self.mouse_wheel_scroll_latency = [] |
65 self.touch_scroll_latency = [] | 68 self.touch_scroll_latency = [] |
66 self.js_touch_scroll_latency = [] | 69 self.js_touch_scroll_latency = [] |
67 self.mouse_wheel_scroll_events = [] | 70 self.mouse_wheel_scroll_events = [] |
68 self.touch_scroll_events = [] | 71 self.touch_scroll_events = [] |
69 self.js_touch_scroll_events = [] | 72 self.js_touch_scroll_events = [] |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ref_stats = None): | 115 ref_stats = None): |
113 """ Adds a random impl thread rendering stats event. | 116 """ Adds a random impl thread rendering stats event. |
114 | 117 |
115 thread: The timeline model thread to which the event will be added. | 118 thread: The timeline model thread to which the event will be added. |
116 first_frame: Is this the first frame within the bounds of an action? | 119 first_frame: Is this the first frame within the bounds of an action? |
117 ref_stats: A ReferenceRenderingStats object to record expected values. | 120 ref_stats: A ReferenceRenderingStats object to record expected values. |
118 """ | 121 """ |
119 # Create randonm data and timestap for impl thread rendering stats. | 122 # Create randonm data and timestap for impl thread rendering stats. |
120 data = { 'frame_count': 1, | 123 data = { 'frame_count': 1, |
121 'rasterize_time': mock_timer.Advance(5, 10) / 1000.0, | 124 'rasterize_time': mock_timer.Advance(5, 10) / 1000.0, |
122 'rasterized_pixel_count': 1280*720 } | 125 'rasterized_pixel_count': 1280*720, |
| 126 'visible_content_area': random.uniform(0, 100), |
| 127 'approximated_visible_content_area': random.uniform(0, 5)} |
123 timestamp = mock_timer.Get() | 128 timestamp = mock_timer.Get() |
124 | 129 |
125 # Add a slice with the event data to the given thread. | 130 # Add a slice with the event data to the given thread. |
126 thread.PushCompleteSlice( | 131 thread.PushCompleteSlice( |
127 'benchmark', 'BenchmarkInstrumentation::ImplThreadRenderingStats', | 132 'benchmark', 'BenchmarkInstrumentation::ImplThreadRenderingStats', |
128 timestamp, duration=0.0, thread_timestamp=None, thread_duration=None, | 133 timestamp, duration=0.0, thread_timestamp=None, thread_duration=None, |
129 args={'data': data}) | 134 args={'data': data}) |
130 | 135 |
131 if not ref_stats: | 136 if not ref_stats: |
132 return | 137 return |
133 | 138 |
134 # Add timestamp only if a frame was output | 139 # Add timestamp only if a frame was output |
135 if data['frame_count'] == 1: | 140 if data['frame_count'] == 1: |
136 if not first_frame: | 141 if not first_frame: |
137 # Add frame_time if this is not the first frame in within the bounds of an | 142 # Add frame_time if this is not the first frame in within the bounds of an |
138 # action. | 143 # action. |
139 prev_timestamp = ref_stats.frame_timestamps[-1][-1] | 144 prev_timestamp = ref_stats.frame_timestamps[-1][-1] |
140 ref_stats.frame_times[-1].append(round(timestamp - prev_timestamp, 2)) | 145 ref_stats.frame_times[-1].append(round(timestamp - prev_timestamp, 2)) |
141 ref_stats.frame_timestamps[-1].append(timestamp) | 146 ref_stats.frame_timestamps[-1].append(timestamp) |
142 | 147 |
143 ref_stats.rasterize_times[-1].append(data['rasterize_time'] * 1000.0) | 148 ref_stats.rasterize_times[-1].append(data['rasterize_time'] * 1000.0) |
144 ref_stats.rasterized_pixel_counts[-1].append(data['rasterized_pixel_count']) | 149 ref_stats.rasterized_pixel_counts[-1].append(data['rasterized_pixel_count']) |
| 150 ref_stats.approximated_pixel_percentages[-1].append( |
| 151 round(DivideIfPossibleOrZero(data['approximated_visible_content_area'], |
| 152 data['visible_content_area']) * 100.0, 3)) |
145 | 153 |
146 | 154 |
147 def AddInputLatencyStats(mock_timer, input_type, start_thread, end_thread, | 155 def AddInputLatencyStats(mock_timer, input_type, start_thread, end_thread, |
148 ref_latency_stats = None): | 156 ref_latency_stats = None): |
149 """ Adds a random input latency stats event. | 157 """ Adds a random input latency stats event. |
150 | 158 |
151 input_type: The input type for which the latency slice is generated. | 159 input_type: The input type for which the latency slice is generated. |
152 start_thread: The start thread on which the async slice is added. | 160 start_thread: The start thread on which the async slice is added. |
153 end_thread: The end thread on which the async slice is ended. | 161 end_thread: The end thread on which the async slice is ended. |
154 ref_latency_stats: A ReferenceInputLatencyStats object for expected values. | 162 ref_latency_stats: A ReferenceInputLatencyStats object for expected values. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 for marker in timeline_markers ] | 360 for marker in timeline_markers ] |
353 stats = RenderingStats(renderer, browser, timeline_ranges) | 361 stats = RenderingStats(renderer, browser, timeline_ranges) |
354 | 362 |
355 # Compare rendering stats to reference. | 363 # Compare rendering stats to reference. |
356 self.assertEquals(stats.frame_timestamps, | 364 self.assertEquals(stats.frame_timestamps, |
357 browser_ref_stats.frame_timestamps) | 365 browser_ref_stats.frame_timestamps) |
358 self.assertEquals(stats.frame_times, browser_ref_stats.frame_times) | 366 self.assertEquals(stats.frame_times, browser_ref_stats.frame_times) |
359 self.assertEquals(stats.rasterize_times, renderer_ref_stats.rasterize_times) | 367 self.assertEquals(stats.rasterize_times, renderer_ref_stats.rasterize_times) |
360 self.assertEquals(stats.rasterized_pixel_counts, | 368 self.assertEquals(stats.rasterized_pixel_counts, |
361 renderer_ref_stats.rasterized_pixel_counts) | 369 renderer_ref_stats.rasterized_pixel_counts) |
| 370 self.assertEquals(stats.approximated_pixel_percentages, |
| 371 renderer_ref_stats.approximated_pixel_percentages) |
362 self.assertEquals(stats.paint_times, renderer_ref_stats.paint_times) | 372 self.assertEquals(stats.paint_times, renderer_ref_stats.paint_times) |
363 self.assertEquals(stats.painted_pixel_counts, | 373 self.assertEquals(stats.painted_pixel_counts, |
364 renderer_ref_stats.painted_pixel_counts) | 374 renderer_ref_stats.painted_pixel_counts) |
365 self.assertEquals(stats.record_times, renderer_ref_stats.record_times) | 375 self.assertEquals(stats.record_times, renderer_ref_stats.record_times) |
366 self.assertEquals(stats.recorded_pixel_counts, | 376 self.assertEquals(stats.recorded_pixel_counts, |
367 renderer_ref_stats.recorded_pixel_counts) | 377 renderer_ref_stats.recorded_pixel_counts) |
368 | 378 |
369 def testScrollLatencyFromTimeline(self): | 379 def testScrollLatencyFromTimeline(self): |
370 timeline = model.TimelineModel() | 380 timeline = model.TimelineModel() |
371 | 381 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 self.assertEquals(touch_scroll_events, | 465 self.assertEquals(touch_scroll_events, |
456 ref_latency_stats.touch_scroll_events) | 466 ref_latency_stats.touch_scroll_events) |
457 self.assertEquals(js_touch_scroll_events, | 467 self.assertEquals(js_touch_scroll_events, |
458 ref_latency_stats.js_touch_scroll_events) | 468 ref_latency_stats.js_touch_scroll_events) |
459 self.assertEquals(ComputeMouseWheelScrollLatency(mouse_wheel_scroll_events), | 469 self.assertEquals(ComputeMouseWheelScrollLatency(mouse_wheel_scroll_events), |
460 ref_latency_stats.mouse_wheel_scroll_latency) | 470 ref_latency_stats.mouse_wheel_scroll_latency) |
461 self.assertEquals(ComputeTouchScrollLatency(touch_scroll_events), | 471 self.assertEquals(ComputeTouchScrollLatency(touch_scroll_events), |
462 ref_latency_stats.touch_scroll_latency) | 472 ref_latency_stats.touch_scroll_latency) |
463 self.assertEquals(ComputeTouchScrollLatency(js_touch_scroll_events), | 473 self.assertEquals(ComputeTouchScrollLatency(js_touch_scroll_events), |
464 ref_latency_stats.js_touch_scroll_latency) | 474 ref_latency_stats.js_touch_scroll_latency) |
OLD | NEW |