Chromium Code Reviews| Index: tools/perf/metrics/rendering_stats_unittest.py |
| diff --git a/tools/perf/metrics/rendering_stats_unittest.py b/tools/perf/metrics/rendering_stats_unittest.py |
| index 6a225fcf8f838555d044fde189b7c29a80781e85..84888569fb442afaace705f2955f684f28050eef 100644 |
| --- a/tools/perf/metrics/rendering_stats_unittest.py |
| +++ b/tools/perf/metrics/rendering_stats_unittest.py |
| @@ -8,6 +8,7 @@ import unittest |
| from metrics.rendering_stats import RenderingStats |
| import telemetry.core.timeline.bounds as timeline_bounds |
| from telemetry.core.timeline import model |
| +import telemetry.core.timeline.async_slice as tracing_async_slice |
| class MockTimer(object): |
| @@ -40,7 +41,62 @@ class ReferenceRenderingStats(object): |
| self.recorded_pixel_count = [] |
| self.rasterize_time = [] |
| self.rasterized_pixel_count = [] |
| + self.mouse_wheel_latency = [] |
| + self.gesture_scroll_latency = [] |
|
nduca
2014/01/23 18:34:45
these member variable names should be chosen to cl
|
| + self.touch_scroll_latency = [] |
| +def AddBrowserInputLatencyStats(mock_timer, input_type, start_thread, |
| + end_thread, ref_stats = None): |
| + """ Adds a random browser process input latency stats event. |
| + |
| + input_type: The input type for which the latency slice is generated. |
| + start_thread: The start thread on which the async slice is added. |
| + end_thread: The end thread on which the async slice is ended. |
| + ref_stats: A ReferenceRenderingStats object to record expected values. |
| + """ |
| + ui_comp_name = 'INPUT_EVENT_LATENCY_UI_COMPONENT' |
| + begin_comp_name = 'INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT' |
| + end_comp_name = 'INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT' |
| + |
| + mock_timer.Advance() |
| + ui_comp_time = mock_timer.Get() * 1000.0 |
| + mock_timer.Advance() |
| + begin_comp_time = mock_timer.Get() * 1000.0 |
| + mock_timer.Advance(10, 20) |
| + end_comp_time = mock_timer.Get() * 1000.0 |
| + |
| + data = { ui_comp_name: {'time': ui_comp_time}, |
| + begin_comp_name: {'time': begin_comp_time}, |
| + end_comp_name: {'time': end_comp_time} } |
| + |
| + timestamp = mock_timer.Get() |
| + |
| + async_slice = tracing_async_slice.AsyncSlice( |
| + 'benchmark', 'InputLatency', timestamp) |
| + |
| + async_sub_slice = tracing_async_slice.AsyncSlice( |
| + 'benchmark', 'InputLatency', timestamp) |
| + async_sub_slice.args = {'data': data, 'step': input_type} |
| + async_sub_slice.parent_slice = async_slice |
| + async_sub_slice.start_thread = start_thread |
| + async_sub_slice.end_thread = end_thread |
| + |
| + async_slice.sub_slices.append(async_sub_slice) |
| + async_slice.start_thread = start_thread |
| + async_slice.end_thread = end_thread |
| + start_thread.AddAsyncSlice(async_slice) |
| + |
| + if not ref_stats: |
| + return |
| + |
| + if input_type == 'MouseWheel': |
| + ref_stats.mouse_wheel_latency.append( |
| + (data[end_comp_name]['time'] - data[begin_comp_name]['time']) / 1000.0) |
| + elif input_type == 'GestureScrollUpdate': |
| + ref_stats.gesture_scroll_latency.append( |
| + (data[end_comp_name]['time'] - data[begin_comp_name]['time']) / 1000.0) |
| + ref_stats.touch_scroll_latency.append( |
| + (data[end_comp_name]['time'] - data[ui_comp_name]['time']) / 1000.0) |
| def AddMainThreadRenderingStats(mock_timer, thread, first_frame, |
| ref_stats = None): |
| @@ -143,6 +199,10 @@ class RenderingStatsUnitTest(unittest.TestCase): |
| AddImplThreadRenderingStats(timer, renderer_compositor, first, ref_stats) |
| AddMainThreadRenderingStats(timer, browser_main, first, None) |
| AddImplThreadRenderingStats(timer, browser_compositor, first, None) |
| + AddBrowserInputLatencyStats(timer, 'MouseWheel', browser_main, |
| + renderer_main, ref_stats) |
| + AddBrowserInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, |
| + renderer_main, ref_stats) |
| renderer_main.EndSlice(timer.Get()) |
| # Create 5 main and impl rendering stats events not within any action. |
| @@ -152,6 +212,10 @@ class RenderingStatsUnitTest(unittest.TestCase): |
| AddImplThreadRenderingStats(timer, renderer_compositor, first, None) |
| AddMainThreadRenderingStats(timer, browser_main, first, None) |
| AddImplThreadRenderingStats(timer, browser_compositor, first, None) |
| + AddBrowserInputLatencyStats(timer, 'MouseWheel', browser_main, |
| + renderer_main, None) |
| + AddBrowserInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, |
| + renderer_main, None) |
| # Create 10 main and impl rendering stats events for Action B. |
| timer.Advance() |
| @@ -162,6 +226,10 @@ class RenderingStatsUnitTest(unittest.TestCase): |
| AddImplThreadRenderingStats(timer, renderer_compositor, first, ref_stats) |
| AddMainThreadRenderingStats(timer, browser_main, first, None) |
| AddImplThreadRenderingStats(timer, browser_compositor, first, None) |
| + AddBrowserInputLatencyStats(timer, 'MouseWheel', browser_main, |
| + renderer_main, ref_stats) |
| + AddBrowserInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, |
| + renderer_main, ref_stats) |
| renderer_main.EndSlice(timer.Get()) |
| # Create 10 main and impl rendering stats events for Action A. |
| @@ -173,6 +241,10 @@ class RenderingStatsUnitTest(unittest.TestCase): |
| AddImplThreadRenderingStats(timer, renderer_compositor, first, ref_stats) |
| AddMainThreadRenderingStats(timer, browser_main, first, None) |
| AddImplThreadRenderingStats(timer, browser_compositor, first, None) |
| + AddBrowserInputLatencyStats(timer, 'MouseWheel', browser_main, |
|
nduca
2014/01/23 18:34:45
it worries me that this is one huge unit test. Can
Yufeng Shen (Slow to review)
2014/01/30 01:16:05
Done.
|
| + renderer_main, ref_stats) |
| + AddBrowserInputLatencyStats(timer, 'GestureScrollUpdate', browser_main, |
| + renderer_main, ref_stats) |
| renderer_main.EndSlice(timer.Get()) |
| renderer_main.FinalizeImport() |
| @@ -182,7 +254,7 @@ class RenderingStatsUnitTest(unittest.TestCase): |
| ['ActionA', 'ActionB', 'ActionA']) |
| timeline_ranges = [ timeline_bounds.Bounds.CreateFromEvent(marker) |
| for marker in timeline_markers ] |
| - stats = RenderingStats(renderer, timeline_ranges) |
| + stats = RenderingStats(renderer, browser_main, timeline_ranges) |
| # Compare rendering stats to reference. |
| self.assertEquals(stats.frame_timestamps, ref_stats.frame_timestamps) |
| @@ -193,5 +265,9 @@ class RenderingStatsUnitTest(unittest.TestCase): |
| self.assertEquals(stats.paint_time, ref_stats.paint_time) |
| self.assertEquals(stats.painted_pixel_count, ref_stats.painted_pixel_count) |
| self.assertEquals(stats.record_time, ref_stats.record_time) |
| - self.assertEquals(stats.recorded_pixel_count, |
| - ref_stats.recorded_pixel_count) |
| + self.assertEquals(stats.mouse_wheel_latency, |
| + ref_stats.mouse_wheel_latency) |
| + self.assertEquals(stats.gesture_scroll_latency, |
| + ref_stats.gesture_scroll_latency) |
| + self.assertEquals(stats.touch_scroll_latency, |
| + ref_stats.touch_scroll_latency) |