| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """This measurement runs a blink performance test and reports the results.""" | |
| 6 | |
| 7 import os | |
| 8 import sys | |
| 9 | |
| 10 from telemetry.page import page_measurement | |
| 11 from telemetry.page import page_set | |
| 12 | |
| 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 BlinkPerf(page_measurement.PageMeasurement): | |
| 56 def __init__(self): | |
| 57 super(BlinkPerf, self).__init__('') | |
| 58 with open(os.path.join(os.path.dirname(__file__), | |
| 59 'blink_perf.js'), 'r') as f: | |
| 60 self._blink_perf_js = f.read() | |
| 61 | |
| 62 def CreatePageSet(self, args, options): | |
| 63 if len(args) < 2: | |
| 64 print 'Must specify a file or directory to run.' | |
| 65 sys.exit(1) | |
| 66 | |
| 67 page_set_arg = args[1] | |
| 68 | |
| 69 if not os.path.exists(page_set_arg): | |
| 70 print '%s does not exist.' % page_set_arg | |
| 71 sys.exit(1) | |
| 72 | |
| 73 return CreatePageSetFromPath(page_set_arg) | |
| 74 | |
| 75 @property | |
| 76 def results_are_the_same_on_every_page(self): | |
| 77 return False | |
| 78 | |
| 79 def WillNavigateToPage(self, page, tab): | |
| 80 page.script_to_evaluate_on_commit = self._blink_perf_js | |
| 81 | |
| 82 def CustomizeBrowserOptions(self, options): | |
| 83 options.AppendExtraBrowserArgs([ | |
| 84 '--js-flags=--expose_gc', | |
| 85 '--enable-experimental-web-platform-features' | |
| 86 ]) | |
| 87 | |
| 88 def MeasurePage(self, page, tab, results): | |
| 89 tab.WaitForJavaScriptExpression('testRunner.isDone', 600) | |
| 90 | |
| 91 log = tab.EvaluateJavaScript('document.getElementById("log").innerHTML') | |
| 92 | |
| 93 for line in log.splitlines(): | |
| 94 if not line.startswith('values '): | |
| 95 continue | |
| 96 parts = line.split() | |
| 97 values = [float(v.replace(',', '')) for v in parts[1:-1]] | |
| 98 units = parts[-1] | |
| 99 metric = page.display_name.split('.')[0].replace('/', '_') | |
| 100 results.Add(metric, units, values) | |
| 101 break | |
| 102 | |
| 103 print log | |
| OLD | NEW |