| 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 from operator import attrgetter | 5 from operator import attrgetter |
| 6 | 6 |
| 7 | 7 |
| 8 class RenderingStats(object): | 8 class RenderingStats(object): |
| 9 def __init__(self, renderer_process, timeline_ranges): | 9 def __init__(self, renderer_process, browser_main_thread, timeline_ranges): |
| 10 """ | 10 """ |
| 11 Utility class for extracting rendering statistics from the timeline (or | 11 Utility class for extracting rendering statistics from the timeline (or |
| 12 other loggin facilities), and providing them in a common format to classes | 12 other loggin facilities), and providing them in a common format to classes |
| 13 that compute benchmark metrics from this data. | 13 that compute benchmark metrics from this data. |
| 14 | 14 |
| 15 Stats can either be numbers, or lists of numbers. Classes that calculate | 15 Stats can either be numbers, or lists of numbers. Classes that calculate |
| 16 metrics from the stats must be able to handle both cases. The length of | 16 metrics from the stats must be able to handle both cases. The length of |
| 17 different list stats may vary. | 17 different list stats may vary. |
| 18 | 18 |
| 19 All *_time values are measured in milliseconds. | 19 All *_time values are measured in milliseconds. |
| 20 """ | 20 """ |
| 21 assert(len(timeline_ranges) > 0) | 21 assert(len(timeline_ranges) > 0) |
| 22 self.renderer_process = renderer_process | 22 self.renderer_process = renderer_process |
| 23 self.browser_main_thread = browser_main_thread |
| 23 | 24 |
| 24 self.frame_timestamps = [] | 25 self.frame_timestamps = [] |
| 25 self.frame_times = [] | 26 self.frame_times = [] |
| 26 self.paint_time = [] | 27 self.paint_time = [] |
| 27 self.painted_pixel_count = [] | 28 self.painted_pixel_count = [] |
| 28 self.record_time = [] | 29 self.record_time = [] |
| 29 self.recorded_pixel_count = [] | 30 self.recorded_pixel_count = [] |
| 30 self.rasterize_time = [] | 31 self.rasterize_time = [] |
| 31 self.rasterized_pixel_count = [] | 32 self.rasterized_pixel_count = [] |
| 33 self.mouse_wheel_latency = [] |
| 34 self.gesture_scroll_latency = [] |
| 35 self.touch_scroll_latency = [] |
| 32 | 36 |
| 33 for timeline_range in timeline_ranges: | 37 for timeline_range in timeline_ranges: |
| 34 if timeline_range.is_empty: | 38 if timeline_range.is_empty: |
| 35 continue | 39 continue |
| 36 self.initMainThreadStatsFromTimeline(timeline_range) | 40 self.initMainThreadStatsFromTimeline(timeline_range) |
| 37 self.initImplThreadStatsFromTimeline(timeline_range) | 41 self.initImplThreadStatsFromTimeline(timeline_range) |
| 42 if self.browser_main_thread: |
| 43 self.initInputLatencyFromTimeline(timeline_range) |
| 44 |
| 45 def initInputLatencyFromTimeline(self, timeline_range): |
| 46 event_name = "InputLatency" |
| 47 ui_comp_name = 'INPUT_EVENT_LATENCY_UI_COMPONENT' |
| 48 begin_comp_name = 'INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT' |
| 49 end_comp_name = 'INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT' |
| 50 mouse_wheel_events = [] |
| 51 scroll_events = [] |
| 52 for event in self.browser_main_thread.IterAllAsyncSlicesOfName(event_name): |
| 53 if event.start >= timeline_range.min and event.end <= timeline_range.max: |
| 54 for ss in event.sub_slices: |
| 55 if 'step' not in ss.args: |
| 56 continue |
| 57 if 'data' not in ss.args: |
| 58 continue |
| 59 if ss.args['step'] == 'MouseWheel': |
| 60 mouse_wheel_events.append(ss) |
| 61 elif ss.args['step'] == 'GestureScrollUpdate': |
| 62 scroll_events.append(ss) |
| 63 |
| 64 # mouse_wheel_latency is the time from when mouse wheel event reaches RWH |
| 65 # to buffer swapped. |
| 66 for event in mouse_wheel_events: |
| 67 data = event.args['data'] |
| 68 if begin_comp_name in data and end_comp_name in data: |
| 69 latency = data[end_comp_name]['time'] - data[begin_comp_name]['time'] |
| 70 self.mouse_wheel_latency.append(latency / 1000.0) |
| 71 |
| 72 # gesture_scroll_latency is the time from when gesture scroll event reaches |
| 73 # RWH to buffer swapped. It is available on all platforms. |
| 74 # touch_scroll_latency is the time from when the touch event reaches browser |
| 75 # to when the buffer swapped due to the scroll generated from the original |
| 76 # touch event. This is only available in Aura currently. |
| 77 for event in scroll_events: |
| 78 data = event.args['data'] |
| 79 if begin_comp_name in data and end_comp_name in data: |
| 80 latency = data[end_comp_name]['time'] - data[begin_comp_name]['time'] |
| 81 self.gesture_scroll_latency.append(latency / 1000.0) |
| 82 if ui_comp_name in data and end_comp_name in data: |
| 83 latency = data[end_comp_name]['time'] - data[ui_comp_name]['time'] |
| 84 self.touch_scroll_latency.append(latency / 1000.0) |
| 38 | 85 |
| 39 def initMainThreadStatsFromTimeline(self, timeline_range): | 86 def initMainThreadStatsFromTimeline(self, timeline_range): |
| 40 event_name = 'BenchmarkInstrumentation::MainThreadRenderingStats' | 87 event_name = 'BenchmarkInstrumentation::MainThreadRenderingStats' |
| 41 events = [] | 88 events = [] |
| 42 for event in self.renderer_process.IterAllSlicesOfName(event_name): | 89 for event in self.renderer_process.IterAllSlicesOfName(event_name): |
| 43 if event.start >= timeline_range.min and event.end <= timeline_range.max: | 90 if event.start >= timeline_range.min and event.end <= timeline_range.max: |
| 44 if 'data' not in event.args: | 91 if 'data' not in event.args: |
| 45 continue | 92 continue |
| 46 events.append(event) | 93 events.append(event) |
| 47 events.sort(key=attrgetter('start')) | 94 events.sort(key=attrgetter('start')) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 self.frame_timestamps.append( | 133 self.frame_timestamps.append( |
| 87 event.start) | 134 event.start) |
| 88 if not first_frame: | 135 if not first_frame: |
| 89 self.frame_times.append(round(self.frame_timestamps[-1] - | 136 self.frame_times.append(round(self.frame_timestamps[-1] - |
| 90 self.frame_timestamps[-2], 2)) | 137 self.frame_timestamps[-2], 2)) |
| 91 first_frame = False | 138 first_frame = False |
| 92 self.rasterize_time.append(1000.0 * | 139 self.rasterize_time.append(1000.0 * |
| 93 event.args['data']['rasterize_time']) | 140 event.args['data']['rasterize_time']) |
| 94 self.rasterized_pixel_count.append( | 141 self.rasterized_pixel_count.append( |
| 95 event.args['data']['rasterized_pixel_count']) | 142 event.args['data']['rasterized_pixel_count']) |
| OLD | NEW |