| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """A tool to run the playback tests, used by the buildbot slaves. | |
| 7 | |
| 8 When this is run, the current directory (cwd) should be the outer build | |
| 9 directory (e.g., chrome-release/build/). | |
| 10 | |
| 11 For a list of command-line options, call this script with '--help'. | |
| 12 """ | |
| 13 | |
| 14 import logging | |
| 15 import optparse | |
| 16 import os | |
| 17 import shutil | |
| 18 import simplejson as json | |
| 19 import subprocess | |
| 20 import sys | |
| 21 import tempfile | |
| 22 import threading | |
| 23 | |
| 24 from common import chromium_utils | |
| 25 from slave import build_directory | |
| 26 from slave import xvfb | |
| 27 from slave.chromium import playback_benchmark_replay | |
| 28 | |
| 29 # So we can import google.*_utils below with native Pythons. | |
| 30 sys.path.append(os.path.abspath('src/tools/python')) | |
| 31 | |
| 32 USAGE = '%s [options]' % os.path.basename(sys.argv[0]) | |
| 33 | |
| 34 SERVER_PORT = 8080 | |
| 35 START_URL = 'http://localhost:%i' % SERVER_PORT | |
| 36 | |
| 37 def print_result(top, name, result, refbuild): | |
| 38 prefix = '' | |
| 39 if top: | |
| 40 prefix = '*' | |
| 41 score_label = 'score' | |
| 42 if refbuild: | |
| 43 score_label = 'score_ref' | |
| 44 print ('%sRESULT %s: %s= %s ms (smaller is better)' % | |
| 45 (prefix, name, score_label, str(result))) | |
| 46 | |
| 47 | |
| 48 def run_benchmark(options, use_refbuild, benchmark_results): | |
| 49 build_dir = os.path.abspath(build_directory.GetBuildOutputDirectory()) | |
| 50 | |
| 51 if not use_refbuild: | |
| 52 build_dir = os.path.join(build_dir, options.target) | |
| 53 else: | |
| 54 build_dir = os.path.join(os.path.dirname(build_dir), 'chrome', 'tools', | |
| 55 'test', 'reference_build') | |
| 56 if chromium_utils.IsMac(): | |
| 57 build_dir = os.path.join(build_dir, 'chrome_mac') | |
| 58 elif chromium_utils.IsLinux(): | |
| 59 build_dir = os.path.join(build_dir, 'chrome_linux') | |
| 60 else: | |
| 61 build_dir = os.path.join(build_dir, 'chrome_win') | |
| 62 | |
| 63 if chromium_utils.IsWindows(): | |
| 64 chrome_exe_name = 'chrome.exe' | |
| 65 elif chromium_utils.IsLinux(): | |
| 66 chrome_exe_name = 'chrome' | |
| 67 else: | |
| 68 chrome_exe_name = 'Chromium' | |
| 69 chrome_exe_path = os.path.join(build_dir, chrome_exe_name) | |
| 70 if not os.path.exists(chrome_exe_path): | |
| 71 raise chromium_utils.PathNotFound('Unable to find %s' % chrome_exe_path) | |
| 72 | |
| 73 temp_dir = tempfile.mkdtemp() | |
| 74 command = [chrome_exe_path, | |
| 75 '--user-data-dir=%s' % temp_dir, | |
| 76 '--no-first-run', | |
| 77 '--no-default-browser-check', | |
| 78 START_URL] | |
| 79 | |
| 80 print "Executing: " | |
| 81 print command | |
| 82 browser_process = subprocess.Popen(command) | |
| 83 | |
| 84 benchmark_results['ready'].wait() | |
| 85 if benchmark_results['ready'].isSet(): | |
| 86 results = json.loads(benchmark_results['results'])[0] | |
| 87 print_result(True, 'Total', results['score'], use_refbuild) | |
| 88 for child in results['children']: | |
| 89 print_result(False, child['name'], child['score'], use_refbuild) | |
| 90 benchmark_results['ready'].clear() | |
| 91 | |
| 92 if chromium_utils.IsWindows(): | |
| 93 subprocess.call('taskkill /f /pid %i /t' % browser_process.pid) | |
| 94 else: | |
| 95 os.system('kill -15 %i' % browser_process.pid) | |
| 96 browser_process.wait() | |
| 97 shutil.rmtree(temp_dir) | |
| 98 return 0 | |
| 99 | |
| 100 | |
| 101 def playback_benchmark(options, args): | |
| 102 """Using the target build configuration, run the playback test.""" | |
| 103 # TODO(thakis): Stop looking at options.build_dir here. | |
| 104 root_dir = os.path.dirname(options.build_dir) # That's src dir. | |
| 105 data_dir = os.path.join(root_dir, 'data', 'webapp_benchmarks', 'gmailjs') | |
| 106 | |
| 107 benchmark_results = {'ready': threading.Event()} | |
| 108 def callback(results): | |
| 109 benchmark_results['results'] = results | |
| 110 benchmark_results['ready'].set() | |
| 111 | |
| 112 benchmark = playback_benchmark_replay.ReplayBenchmark(callback, | |
| 113 data_dir, | |
| 114 SERVER_PORT) | |
| 115 server_thread = threading.Thread(target=benchmark.RunForever) | |
| 116 server_thread.setDaemon(True) | |
| 117 server_thread.start() | |
| 118 | |
| 119 if chromium_utils.IsLinux(): | |
| 120 xvfb.StartVirtualX(options.target, '') | |
| 121 | |
| 122 result = run_benchmark(options, False, benchmark_results) | |
| 123 result |= run_benchmark(options, True, benchmark_results) | |
| 124 | |
| 125 if chromium_utils.IsLinux(): | |
| 126 xvfb.StopVirtualX(options.target) | |
| 127 | |
| 128 return result | |
| 129 | |
| 130 | |
| 131 def main(): | |
| 132 # Initialize logging. | |
| 133 log_level = logging.INFO | |
| 134 logging.basicConfig(level=log_level, | |
| 135 format='%(asctime)s %(filename)s:%(lineno)-3d' | |
| 136 ' %(levelname)s %(message)s', | |
| 137 datefmt='%y%m%d %H:%M:%S') | |
| 138 | |
| 139 option_parser = optparse.OptionParser(usage=USAGE) | |
| 140 | |
| 141 option_parser.add_option('', '--target', default='Release', | |
| 142 help='build target (Debug or Release)') | |
| 143 option_parser.add_option('', '--build-dir', default='chrome', | |
| 144 help='path to main build directory (the parent of ' | |
| 145 'the Release or Debug directory)') | |
| 146 options, args = option_parser.parse_args() | |
| 147 return playback_benchmark(options, args) | |
| 148 | |
| 149 | |
| 150 if '__main__' == __name__: | |
| 151 sys.exit(main()) | |
| OLD | NEW |