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