- add sources.
[platform/framework/web/crosswalk.git] / src / tools / perf / measurements / record_per_area.py
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
3 # found in the LICENSE file.
4
5 import time
6
7 from metrics import smoothness
8 from telemetry.page import page_measurement
9
10 class RecordPerArea(page_measurement.PageMeasurement):
11   def __init__(self):
12     super(RecordPerArea, self).__init__('', True)
13
14   def AddCommandLineOptions(self, parser):
15     parser.add_option('--start-wait-time', dest='start_wait_time',
16                       default=2,
17                       help='Wait time before the benchmark is started ' +
18                       '(must be long enought to load all content)')
19
20   def CustomizeBrowserOptions(self, options):
21     smoothness.SmoothnessMetrics.CustomizeBrowserOptions(options)
22     options.AppendExtraBrowserArgs([
23         '--enable-impl-side-painting',
24         '--force-compositing-mode',
25         '--enable-threaded-compositing',
26         '--enable-gpu-benchmarking'
27     ])
28
29   def MeasurePage(self, page, tab, results):
30     # Wait until the page has loaded and come to a somewhat steady state.
31     # Needs to be adjusted for every device (~2 seconds for workstation).
32     time.sleep(float(self.options.start_wait_time))
33
34     # Enqueue benchmark
35     tab.ExecuteJavaScript("""
36         window.benchmark_results = {};
37         window.benchmark_results.done = false;
38         chrome.gpuBenchmarking.runMicroBenchmark(
39             "picture_record_benchmark",
40             function(value) {
41               window.benchmark_results.done = true;
42               window.benchmark_results.results = value;
43             }, [{width: 1, height: 1},
44                 {width: 250, height: 250},
45                 {width: 500, height: 500},
46                 {width: 750, height: 750},
47                 {width: 1000, height: 1000},
48                 {width: 256, height: 1024},
49                 {width: 1024, height: 256}]);
50     """)
51
52     tab.WaitForJavaScriptExpression('window.benchmark_results.done', 300)
53
54     all_data = tab.EvaluateJavaScript('window.benchmark_results.results')
55     for data in all_data:
56       width = data['width']
57       height = data['height']
58       area = width * height
59       time_ms = data['time_ms']
60
61       results.Add('area_%07d_%dx%d' % (area, width, height), 'ms', time_ms)
62