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 collections | 5 import collections |
6 | 6 |
7 from metrics import Metric | 7 from metrics import Metric |
8 from telemetry.core import bitmap | 8 from telemetry.core import bitmap |
9 | 9 |
10 | 10 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 # TODO(tonyg): Bitrate is arbitrary here. Experiment with screen capture | 131 # TODO(tonyg): Bitrate is arbitrary here. Experiment with screen capture |
132 # overhead vs. speed index accuracy and set the bitrate appropriately. | 132 # overhead vs. speed index accuracy and set the bitrate appropriately. |
133 tab.StartVideoCapture(min_bitrate_mbps=4) | 133 tab.StartVideoCapture(min_bitrate_mbps=4) |
134 | 134 |
135 def Stop(self, tab): | 135 def Stop(self, tab): |
136 # Ignore white because Chrome may blank out the page during load and we want | 136 # Ignore white because Chrome may blank out the page during load and we want |
137 # that to count as 0% complete. Relying on this fact, we also blank out the | 137 # that to count as 0% complete. Relying on this fact, we also blank out the |
138 # previous page to white. The tolerance of 8 experimentally does well with | 138 # previous page to white. The tolerance of 8 experimentally does well with |
139 # video capture at 4mbps. We should keep this as low as possible with | 139 # video capture at 4mbps. We should keep this as low as possible with |
140 # supported video compression settings. | 140 # supported video compression settings. |
| 141 video_capture = tab.StopVideoCapture() |
141 histograms = [(time, bmp.ColorHistogram(ignore_color=bitmap.WHITE, | 142 histograms = [(time, bmp.ColorHistogram(ignore_color=bitmap.WHITE, |
142 tolerance=8)) | 143 tolerance=8)) |
143 for time, bmp in tab.StopVideoCapture()] | 144 for time, bmp in video_capture.GetVideoFrameIter()] |
144 | 145 |
145 start_histogram = histograms[0][1] | 146 start_histogram = histograms[0][1] |
146 final_histogram = histograms[-1][1] | 147 final_histogram = histograms[-1][1] |
147 total_distance = start_histogram.Distance(final_histogram) | 148 total_distance = start_histogram.Distance(final_histogram) |
148 | 149 |
149 def FrameProgress(histogram): | 150 def FrameProgress(histogram): |
150 if total_distance == 0: | 151 if total_distance == 0: |
151 if histogram.Distance(final_histogram) == 0: | 152 if histogram.Distance(final_histogram) == 0: |
152 return 1.0 | 153 return 1.0 |
153 else: | 154 else: |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 frame = paint_event.args['frameId'] | 296 frame = paint_event.args['frameId'] |
296 return (frame,) + GetBox(paint_event.args['data']['clip']) | 297 return (frame,) + GetBox(paint_event.args['data']['clip']) |
297 | 298 |
298 def _GroupEventByRectangle(self, paint_events): | 299 def _GroupEventByRectangle(self, paint_events): |
299 """Group all paint events according to the rectangle that they update.""" | 300 """Group all paint events according to the rectangle that they update.""" |
300 result = collections.defaultdict(list) | 301 result = collections.defaultdict(list) |
301 for event in paint_events: | 302 for event in paint_events: |
302 assert event.name == 'Paint' | 303 assert event.name == 'Paint' |
303 result[self._GetRectangle(event)].append(event) | 304 result[self._GetRectangle(event)].append(event) |
304 return result | 305 return result |
OLD | NEW |