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_process, 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_process = browser_process | |
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 self.initInputLatencyFromTimeline(timeline_range) | |
43 | |
44 def initInputLatencyFromTimeline(self, timeline_range): | |
nduca
2014/01/13 18:49:32
needs unit tests too
Yufeng Shen (Slow to review)
2014/01/14 00:05:47
unittests added in
tools/perf/metrics/rendering_s
| |
45 event_name = "InputLatency" | |
46 ui_comp_name = 'INPUT_EVENT_LATENCY_UI_COMPONENT' | |
47 begin_comp_name = 'INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT' | |
48 end_comp_name = 'INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT' | |
49 mouse_wheel_events = [] | |
50 scroll_events = [] | |
51 for event in self.browser_process.IterAllAsyncSlicesOfName(event_name): | |
52 if event.start >= timeline_range.min and event.end <= timeline_range.max: | |
53 for ss in event.sub_slices: | |
54 if 'step' not in ss.args: | |
55 continue | |
56 if 'data' not in ss.args: | |
57 continue | |
58 if ss.args['step'] == 'MouseWheel': | |
59 mouse_wheel_events.append(ss) | |
60 elif ss.args['step'] == 'GestureScrollUpdate': | |
61 scroll_events.append(ss) | |
62 | |
63 # mouse_wheel_latency is the time from when mouse wheel event reaches RWH | |
64 # to buffer swapped. | |
65 for event in mouse_wheel_events: | |
66 data = event.args['data'] | |
67 if begin_comp_name in data and end_comp_name in data: | |
68 latency = data[end_comp_name]['time'] - data[begin_comp_name]['time'] | |
69 self.mouse_wheel_latency.append(latency / 1000.0) | |
70 | |
71 # gesture_scroll_latency is the time from when gesture scroll event reaches | |
72 # RWH to buffer swapped. It is available on all platforms. | |
73 # touch_scroll_latency is the time from when the touch event reaches browser | |
74 # to when the buffer swapped due to the scroll generated from the original | |
75 # touch event. This is only available in Aura currently. | |
76 for event in scroll_events: | |
77 data = event.args['data'] | |
78 if begin_comp_name in data and end_comp_name in data: | |
79 latency = data[end_comp_name]['time'] - data[begin_comp_name]['time'] | |
80 self.gesture_scroll_latency.append(latency / 1000.0) | |
81 if ui_comp_name in data and end_comp_name in data: | |
82 latency = data[end_comp_name]['time'] - data[ui_comp_name]['time'] | |
83 self.touch_scroll_latency.append(latency / 1000.0) | |
38 | 84 |
39 def initMainThreadStatsFromTimeline(self, timeline_range): | 85 def initMainThreadStatsFromTimeline(self, timeline_range): |
40 event_name = 'BenchmarkInstrumentation::MainThreadRenderingStats' | 86 event_name = 'BenchmarkInstrumentation::MainThreadRenderingStats' |
41 events = [] | 87 events = [] |
42 for event in self.renderer_process.IterAllSlicesOfName(event_name): | 88 for event in self.renderer_process.IterAllSlicesOfName(event_name): |
43 if event.start >= timeline_range.min and event.end <= timeline_range.max: | 89 if event.start >= timeline_range.min and event.end <= timeline_range.max: |
44 if 'data' not in event.args: | 90 if 'data' not in event.args: |
45 continue | 91 continue |
46 events.append(event) | 92 events.append(event) |
47 events.sort(key=attrgetter('start')) | 93 events.sort(key=attrgetter('start')) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 self.frame_timestamps.append( | 132 self.frame_timestamps.append( |
87 event.start) | 133 event.start) |
88 if not first_frame: | 134 if not first_frame: |
89 self.frame_times.append(round(self.frame_timestamps[-1] - | 135 self.frame_times.append(round(self.frame_timestamps[-1] - |
90 self.frame_timestamps[-2], 2)) | 136 self.frame_timestamps[-2], 2)) |
91 first_frame = False | 137 first_frame = False |
92 self.rasterize_time.append(1000.0 * | 138 self.rasterize_time.append(1000.0 * |
93 event.args['data']['rasterize_time']) | 139 event.args['data']['rasterize_time']) |
94 self.rasterized_pixel_count.append( | 140 self.rasterized_pixel_count.append( |
95 event.args['data']['rasterized_pixel_count']) | 141 event.args['data']['rasterized_pixel_count']) |
OLD | NEW |