OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 Queue | 5 import Queue |
6 import datetime | 6 import datetime |
7 import logging | 7 import logging |
8 import re | 8 import re |
9 import threading | 9 import threading |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 SurfaceStatsCollector.Result('max_frame_delay', None, 'vsyncs'), | 78 SurfaceStatsCollector.Result('max_frame_delay', None, 'vsyncs'), |
79 SurfaceStatsCollector.Result('frame_lengths', None, 'vsyncs'), | 79 SurfaceStatsCollector.Result('frame_lengths', None, 'vsyncs'), |
80 SurfaceStatsCollector.Result('avg_surface_fps', None, 'fps') | 80 SurfaceStatsCollector.Result('avg_surface_fps', None, 'fps') |
81 ] | 81 ] |
82 | 82 |
83 @staticmethod | 83 @staticmethod |
84 def _GetNormalizedDeltas(data, refresh_period): | 84 def _GetNormalizedDeltas(data, refresh_period): |
85 deltas = [t2 - t1 for t1, t2 in zip(data, data[1:])] | 85 deltas = [t2 - t1 for t1, t2 in zip(data, data[1:])] |
86 return (deltas, [delta / refresh_period for delta in deltas]) | 86 return (deltas, [delta / refresh_period for delta in deltas]) |
87 | 87 |
| 88 @staticmethod |
| 89 def _CalculateResults(refresh_period, timestamps, result_suffix): |
| 90 """Returns a list of SurfaceStatsCollector.Result.""" |
| 91 frame_count = len(timestamps) |
| 92 seconds = timestamps[-1] - timestamps[0] |
| 93 |
| 94 frame_lengths, normalized_frame_lengths = \ |
| 95 SurfaceStatsCollector._GetNormalizedDeltas(timestamps, refresh_period) |
| 96 length_changes, normalized_changes = \ |
| 97 SurfaceStatsCollector._GetNormalizedDeltas( |
| 98 frame_lengths, refresh_period) |
| 99 jankiness = [max(0, round(change)) for change in normalized_changes] |
| 100 pause_threshold = 20 |
| 101 jank_count = sum(1 for change in jankiness |
| 102 if change > 0 and change < pause_threshold) |
| 103 return [ |
| 104 SurfaceStatsCollector.Result( |
| 105 'avg_surface_fps' + result_suffix, |
| 106 int(round(frame_count / seconds)), 'fps'), |
| 107 SurfaceStatsCollector.Result( |
| 108 'jank_count' + result_suffix, jank_count, 'janks'), |
| 109 SurfaceStatsCollector.Result( |
| 110 'max_frame_delay' + result_suffix, |
| 111 round(max(normalized_frame_lengths)), |
| 112 'vsyncs'), |
| 113 SurfaceStatsCollector.Result( |
| 114 'frame_lengths' + result_suffix, normalized_frame_lengths, |
| 115 'vsyncs'), |
| 116 ] |
| 117 |
| 118 @staticmethod |
| 119 def _CalculateBuckets(refresh_period, timestamps): |
| 120 results = [] |
| 121 for pct in [0.99, 0.5]: |
| 122 sliced = timestamps[int(-pct * len(timestamps)) + 3 : ] |
| 123 results += SurfaceStatsCollector._CalculateResults( |
| 124 refresh_period, sliced, '_' + str(int(pct * 100))) |
| 125 return results |
| 126 |
88 def _StorePerfResults(self): | 127 def _StorePerfResults(self): |
89 if self._use_legacy_method: | 128 if self._use_legacy_method: |
90 surface_after = self._GetSurfaceStatsLegacy() | 129 surface_after = self._GetSurfaceStatsLegacy() |
91 td = surface_after['timestamp'] - self._surface_before['timestamp'] | 130 td = surface_after['timestamp'] - self._surface_before['timestamp'] |
92 seconds = td.seconds + td.microseconds / 1e6 | 131 seconds = td.seconds + td.microseconds / 1e6 |
93 frame_count = (surface_after['page_flip_count'] - | 132 frame_count = (surface_after['page_flip_count'] - |
94 self._surface_before['page_flip_count']) | 133 self._surface_before['page_flip_count']) |
95 else: | 134 self._results.append(SurfaceStatsCollector.Result( |
96 assert self._collector_thread | 135 'avg_surface_fps', int(round(frame_count / seconds)), 'fps')) |
97 (refresh_period, timestamps) = self._GetDataFromThread() | 136 return |
98 if not refresh_period or not len(timestamps) >= 3: | |
99 if self._warn_about_empty_data: | |
100 logging.warning('Surface stat data is empty') | |
101 return | |
102 frame_count = len(timestamps) | |
103 seconds = timestamps[-1] - timestamps[0] | |
104 | 137 |
105 frame_lengths, normalized_frame_lengths = \ | 138 # Non-legacy method. |
106 self._GetNormalizedDeltas(timestamps, refresh_period) | 139 assert self._collector_thread |
107 length_changes, normalized_changes = \ | 140 (refresh_period, timestamps) = self._GetDataFromThread() |
108 self._GetNormalizedDeltas(frame_lengths, refresh_period) | 141 if not refresh_period or not len(timestamps) >= 3: |
109 jankiness = [max(0, round(change)) for change in normalized_changes] | 142 if self._warn_about_empty_data: |
110 pause_threshold = 20 | 143 logging.warning('Surface stat data is empty') |
111 jank_count = sum(1 for change in jankiness | 144 return |
112 if change > 0 and change < pause_threshold) | |
113 | |
114 self._results.append(SurfaceStatsCollector.Result( | |
115 'refresh_period', refresh_period, 'seconds')) | |
116 self._results.append(SurfaceStatsCollector.Result( | |
117 'jank_count', jank_count, 'janks')) | |
118 self._results.append(SurfaceStatsCollector.Result( | |
119 'max_frame_delay', round(max(normalized_frame_lengths)), | |
120 'vsyncs')) | |
121 self._results.append(SurfaceStatsCollector.Result( | |
122 'frame_lengths', normalized_frame_lengths, 'vsyncs')) | |
123 self._results.append(SurfaceStatsCollector.Result( | 145 self._results.append(SurfaceStatsCollector.Result( |
124 'avg_surface_fps', int(round(frame_count / seconds)), 'fps')) | 146 'refresh_period', refresh_period, 'seconds')) |
| 147 self._results += self._CalculateResults(refresh_period, timestamps, '') |
| 148 self._results += self._CalculateBuckets(refresh_period, timestamps) |
125 | 149 |
126 def _CollectorThread(self): | 150 def _CollectorThread(self): |
127 last_timestamp = 0 | 151 last_timestamp = 0 |
128 timestamps = [] | 152 timestamps = [] |
129 retries = 0 | 153 retries = 0 |
130 | 154 |
131 while not self._stop_event.is_set(): | 155 while not self._stop_event.is_set(): |
132 self._get_data_event.wait(1) | 156 self._get_data_event.wait(1) |
133 try: | 157 try: |
134 refresh_period, new_timestamps = self._GetSurfaceFlingerFrameData() | 158 refresh_period, new_timestamps = self._GetSurfaceFlingerFrameData() |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 try: | 288 try: |
265 cur_surface = int(match.group(1), 16) | 289 cur_surface = int(match.group(1), 16) |
266 except Exception: | 290 except Exception: |
267 logging.error('Failed to parse current surface from ' + match.group(1)) | 291 logging.error('Failed to parse current surface from ' + match.group(1)) |
268 else: | 292 else: |
269 logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) | 293 logging.warning('Failed to call SurfaceFlinger surface ' + results[0]) |
270 return { | 294 return { |
271 'page_flip_count': cur_surface, | 295 'page_flip_count': cur_surface, |
272 'timestamp': datetime.datetime.now(), | 296 'timestamp': datetime.datetime.now(), |
273 } | 297 } |
OLD | NEW |