Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / tools / perf / perf_tools / image_decoding_benchmark.py
blob58b6155c8b827c82b1ec3cfcfbb9c60d12737ed0
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
3 # found in the LICENSE file.
5 from telemetry.page import page_benchmark
8 class ImageDecoding(page_benchmark.PageBenchmark):
9 def WillNavigateToPage(self, page, tab):
10 tab.StartTimelineRecording()
12 def MeasurePage(self, page, tab, results):
13 tab.StopTimelineRecording()
14 def _IsDone():
15 return tab.EvaluateJavaScript('isDone')
17 decode_image_events = \
18 tab.timeline_model.GetAllOfName('DecodeImage')
20 # If it is a real image benchmark, then store only the last-minIterations
21 # decode tasks.
22 if (hasattr(page,
23 'image_decoding_benchmark_limit_results_to_min_iterations') and
24 page.image_decoding_benchmark_limit_results_to_min_iterations):
25 assert _IsDone()
26 min_iterations = tab.EvaluateJavaScript('minIterations')
27 decode_image_events = decode_image_events[-min_iterations:]
29 durations = [d.duration_ms for d in decode_image_events]
30 if not durations:
31 results.Add('ImageDecoding_avg', 'ms', 'unsupported')
32 return
33 image_decoding_avg = sum(durations) / len(durations)
34 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg)