| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 os | 5 import os |
| 6 import sys |
| 6 | 7 |
| 7 from telemetry import test | 8 from telemetry import test |
| 8 from telemetry.core import util | 9 from telemetry.core import util |
| 10 from telemetry.page import page_measurement |
| 11 from telemetry.page import page_set |
| 9 | 12 |
| 10 from measurements import blink_perf | 13 |
| 14 def _CreatePageSetFromPath(path): |
| 15 assert os.path.exists(path) |
| 16 |
| 17 page_set_dict = {'pages': []} |
| 18 |
| 19 def _AddPage(path): |
| 20 if not path.endswith('.html'): |
| 21 return |
| 22 if '../' in open(path, 'r').read(): |
| 23 # If the page looks like it references its parent dir, include it. |
| 24 page_set_dict['serving_dirs'] = [os.path.dirname(os.path.dirname(path))] |
| 25 page_set_dict['pages'].append({'url': |
| 26 'file://' + path.replace('\\', '/')}) |
| 27 |
| 28 def _AddDir(dir_path, skipped): |
| 29 for candidate_path in os.listdir(dir_path): |
| 30 if candidate_path == 'resources': |
| 31 continue |
| 32 candidate_path = os.path.join(dir_path, candidate_path) |
| 33 if candidate_path.startswith(tuple([os.path.join(path, s) |
| 34 for s in skipped])): |
| 35 continue |
| 36 if os.path.isdir(candidate_path): |
| 37 _AddDir(candidate_path, skipped) |
| 38 else: |
| 39 _AddPage(candidate_path) |
| 40 |
| 41 if os.path.isdir(path): |
| 42 skipped = [] |
| 43 skipped_file = os.path.join(path, 'Skipped') |
| 44 if os.path.exists(skipped_file): |
| 45 for line in open(skipped_file, 'r').readlines(): |
| 46 line = line.strip() |
| 47 if line and not line.startswith('#'): |
| 48 skipped.append(line.replace('/', os.sep)) |
| 49 _AddDir(path, skipped) |
| 50 else: |
| 51 _AddPage(path) |
| 52 return page_set.PageSet.FromDict(page_set_dict, os.getcwd() + os.sep) |
| 53 |
| 54 |
| 55 class _BlinkPerfMeasurement(page_measurement.PageMeasurement): |
| 56 """Tuns a blink performance test and reports the results.""" |
| 57 def __init__(self): |
| 58 super(_BlinkPerfMeasurement, self).__init__('') |
| 59 with open(os.path.join(os.path.dirname(__file__), |
| 60 'blink_perf.js'), 'r') as f: |
| 61 self._blink_perf_js = f.read() |
| 62 |
| 63 def CreatePageSet(self, args, options): |
| 64 if len(args) < 2: |
| 65 print 'Must specify a file or directory to run.' |
| 66 sys.exit(1) |
| 67 |
| 68 page_set_arg = args[1] |
| 69 |
| 70 if not os.path.exists(page_set_arg): |
| 71 print '%s does not exist.' % page_set_arg |
| 72 sys.exit(1) |
| 73 |
| 74 return _CreatePageSetFromPath(page_set_arg) |
| 75 |
| 76 @property |
| 77 def results_are_the_same_on_every_page(self): |
| 78 return False |
| 79 |
| 80 def WillNavigateToPage(self, page, tab): |
| 81 page.script_to_evaluate_on_commit = self._blink_perf_js |
| 82 |
| 83 def CustomizeBrowserOptions(self, options): |
| 84 options.AppendExtraBrowserArgs([ |
| 85 '--js-flags=--expose_gc', |
| 86 '--enable-experimental-web-platform-features' |
| 87 ]) |
| 88 |
| 89 def MeasurePage(self, page, tab, results): |
| 90 tab.WaitForJavaScriptExpression('testRunner.isDone', 600) |
| 91 |
| 92 log = tab.EvaluateJavaScript('document.getElementById("log").innerHTML') |
| 93 |
| 94 for line in log.splitlines(): |
| 95 if not line.startswith('values '): |
| 96 continue |
| 97 parts = line.split() |
| 98 values = [float(v.replace(',', '')) for v in parts[1:-1]] |
| 99 units = parts[-1] |
| 100 metric = page.display_name.split('.')[0].replace('/', '_') |
| 101 results.Add(metric, units, values) |
| 102 break |
| 103 |
| 104 print log |
| 11 | 105 |
| 12 | 106 |
| 13 class BlinkPerfAll(test.Test): | 107 class BlinkPerfAll(test.Test): |
| 14 tag = 'all' | 108 tag = 'all' |
| 15 test = blink_perf.BlinkPerf | 109 test = _BlinkPerfMeasurement |
| 16 | 110 |
| 17 def CreatePageSet(self, options): | 111 def CreatePageSet(self, options): |
| 18 path = os.path.join( | 112 path = os.path.join( |
| 19 util.GetChromiumSrcDir(), 'third_party', 'WebKit', 'PerformanceTests') | 113 util.GetChromiumSrcDir(), 'third_party', 'WebKit', 'PerformanceTests') |
| 20 return blink_perf.CreatePageSetFromPath(path) | 114 return _CreatePageSetFromPath(path) |
| 21 | 115 |
| 22 class BlinkPerfAnimation(test.Test): | 116 class BlinkPerfAnimation(test.Test): |
| 23 tag = 'animation' | 117 tag = 'animation' |
| 24 test = blink_perf.BlinkPerf | 118 test = _BlinkPerfMeasurement |
| 25 | 119 |
| 26 def CreatePageSet(self, options): | 120 def CreatePageSet(self, options): |
| 27 path = os.path.join(util.GetChromiumSrcDir(), | 121 path = os.path.join(util.GetChromiumSrcDir(), |
| 28 'third_party', 'WebKit', 'PerformanceTests', 'Animation') | 122 'third_party', 'WebKit', 'PerformanceTests', 'Animation') |
| 29 return blink_perf.CreatePageSetFromPath(path) | 123 return _CreatePageSetFromPath(path) |
| 30 | 124 |
| 31 class BlinkPerfWebAnimations(test.Test): | 125 class BlinkPerfWebAnimations(test.Test): |
| 32 tag = 'web_animations' | 126 tag = 'web_animations' |
| 33 test = blink_perf.BlinkPerf | 127 test = _BlinkPerfMeasurement |
| 34 enabled = False | 128 enabled = False |
| 35 | 129 |
| 36 def CreatePageSet(self, options): | 130 def CreatePageSet(self, options): |
| 37 path = os.path.join(util.GetChromiumSrcDir(), | 131 path = os.path.join(util.GetChromiumSrcDir(), |
| 38 'third_party', 'WebKit', 'PerformanceTests', 'Animation') | 132 'third_party', 'WebKit', 'PerformanceTests', 'Animation') |
| 39 return blink_perf.CreatePageSetFromPath(path) | 133 return _CreatePageSetFromPath(path) |
| 40 | 134 |
| 41 def CustomizeBrowserOptions(self, options): | 135 def CustomizeBrowserOptions(self, options): |
| 42 options.AppendExtraBrowserArgs('--enable-web-animations-css') | 136 options.AppendExtraBrowserArgs('--enable-web-animations-css') |
| OLD | NEW |