| 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 from telemetry import multi_page_benchmark | 5 from telemetry import multi_page_benchmark |
| 6 from telemetry import util | |
| 7 | 6 |
| 8 | 7 |
| 9 class ImageDecoding(multi_page_benchmark.MultiPageBenchmark): | 8 class ImageDecoding(multi_page_benchmark.MultiPageBenchmark): |
| 10 def MeasurePage(self, _, tab, results): | 9 def WillNavigateToPage(self, page, tab): |
| 10 tab.timeline.Start() |
| 11 |
| 12 def MeasurePage(self, page, tab, results): |
| 13 tab.timeline.Stop() |
| 11 def _IsDone(): | 14 def _IsDone(): |
| 12 return tab.runtime.Evaluate('isDone') | 15 return tab.runtime.Evaluate('isDone') |
| 13 | 16 |
| 14 with tab.timeline.Recorder(tab.timeline): | 17 decode_image_events = \ |
| 15 tab.runtime.Execute('runBenchmark()') | 18 tab.timeline.timeline_events.GetAllOfType('DecodeImage') |
| 16 util.WaitFor(_IsDone, 60) | 19 |
| 17 iterations = tab.runtime.Evaluate('minIterations') | 20 # If it is a real image benchmark, then store only the last-minIterations |
| 18 decode_image = tab.timeline.timeline_events.GetAllOfType('DecodeImage') | 21 # decode tasks. |
| 19 elapsed_times = [d.elapsed_time for d in decode_image[-iterations:]] | 22 if (hasattr(page, 'is_image_decoding_benchmark') and |
| 23 page.is_image_decoding_benchmark): |
| 24 assert _IsDone() |
| 25 max_event_count = tab.runtime.Evaluate('minIterations') |
| 26 decode_image_events = decode_image_events[-max_event_count:] |
| 27 |
| 28 elapsed_times = [d.elapsed_time for d in decode_image_events] |
| 20 if not elapsed_times: | 29 if not elapsed_times: |
| 21 results.Add('ImageDecoding_avg', 'ms', 'unsupported') | 30 results.Add('ImageDecoding_avg', 'ms', 'unsupported') |
| 22 return | 31 return |
| 23 image_decoding_avg = sum(elapsed_times) / len(elapsed_times) | 32 image_decoding_avg = sum(elapsed_times) / len(elapsed_times) |
| 24 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg) | 33 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg) |
| OLD | NEW |