Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Instructs Chrome to load series of web pages and reports results. | 6 """Instructs Chrome to load series of web pages and reports results. |
| 7 | 7 |
| 8 When running Chrome is sandwiched between preprocessed disk caches and | 8 When running Chrome is sandwiched between preprocessed disk caches and |
| 9 WepPageReplay serving all connections. | 9 WepPageReplay serving all connections. |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 from pylib import constants | 28 from pylib import constants |
| 29 import devil_chromium | 29 import devil_chromium |
| 30 | 30 |
| 31 import chrome_cache | 31 import chrome_cache |
| 32 import common_util | 32 import common_util |
| 33 import emulation | 33 import emulation |
| 34 import options | 34 import options |
| 35 import sandwich_metrics | 35 import sandwich_metrics |
| 36 import sandwich_misc | 36 import sandwich_misc |
| 37 from sandwich_runner import SandwichRunner | 37 from sandwich_runner import SandwichRunner |
| 38 import sandwich_task_builder | |
| 39 import task_manager | |
| 38 from trace_test.webserver_test import WebServer | 40 from trace_test.webserver_test import WebServer |
| 39 | 41 |
| 40 | 42 |
| 41 # Use options layer to access constants. | 43 # Use options layer to access constants. |
| 42 OPTIONS = options.OPTIONS | 44 OPTIONS = options.OPTIONS |
| 43 | 45 |
| 44 | 46 |
| 45 def _ArgumentParser(): | 47 def _ArgumentParser(): |
| 46 """Build a command line argument's parser.""" | 48 """Build a command line argument's parser.""" |
| 47 # Command parser when dealing with jobs. | 49 # Command parser when dealing with jobs. |
| 48 common_job_parser = argparse.ArgumentParser(add_help=False) | 50 common_job_parser = argparse.ArgumentParser(add_help=False) |
| 49 common_job_parser.add_argument('--job', required=True, | 51 common_job_parser.add_argument('--job', required=True, |
| 50 help='JSON file with job description.') | 52 help='JSON file with job description.') |
| 51 | 53 |
| 54 orchestra_parser = task_manager.CommandLineParser() | |
|
pasko
2016/04/18 09:36:12
last instance of orchestra :)
gabadie
2016/04/19 17:39:48
Done.
| |
| 55 | |
| 52 # Plumbing parser to configure OPTIONS. | 56 # Plumbing parser to configure OPTIONS. |
| 53 plumbing_parser = OPTIONS.GetParentParser('plumbing options') | 57 plumbing_parser = OPTIONS.GetParentParser('plumbing options') |
| 54 | 58 |
| 55 # Main parser | 59 # Main parser |
| 56 parser = argparse.ArgumentParser(parents=[plumbing_parser]) | 60 parser = argparse.ArgumentParser(parents=[plumbing_parser]) |
| 57 subparsers = parser.add_subparsers(dest='subcommand', help='subcommand line') | 61 subparsers = parser.add_subparsers(dest='subcommand', help='subcommand line') |
| 58 | 62 |
| 59 # Record WPR subcommand. | 63 # Record WPR subcommand. |
| 60 record_wpr = subparsers.add_parser('record-wpr', parents=[common_job_parser], | 64 record_wpr = subparsers.add_parser('record-wpr', parents=[common_job_parser], |
| 61 help='Record WPR from sandwich job.') | 65 help='Record WPR from sandwich job.') |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 help='Record a test trace using the trace_test.webserver_test.') | 163 help='Record a test trace using the trace_test.webserver_test.') |
| 160 record_trace_parser.add_argument('--source-dir', type=str, required=True, | 164 record_trace_parser.add_argument('--source-dir', type=str, required=True, |
| 161 help='Base path where the files are opened' | 165 help='Base path where the files are opened' |
| 162 'by the web server.') | 166 'by the web server.') |
| 163 record_trace_parser.add_argument('--page', type=str, required=True, | 167 record_trace_parser.add_argument('--page', type=str, required=True, |
| 164 help='Source page in source-dir to navigate ' | 168 help='Source page in source-dir to navigate ' |
| 165 'to.') | 169 'to.') |
| 166 record_trace_parser.add_argument('-o', '--output', type=str, required=True, | 170 record_trace_parser.add_argument('-o', '--output', type=str, required=True, |
| 167 help='Output path of the generated trace.') | 171 help='Output path of the generated trace.') |
| 168 | 172 |
| 173 # Run all subcommand. | |
| 174 run_all = subparsers.add_parser('run-all', | |
| 175 parents=[common_job_parser, orchestra_parser], | |
| 176 help='Run all steps using the task manager ' | |
| 177 'infrastructure.') | |
| 178 run_all.add_argument('-g', '--gen-full', action='store_true', | |
| 179 help='Generate the full graph with all possible' | |
| 180 'benchmarks.') | |
| 181 run_all.add_argument('--wpr-archive', default=None, type=str, | |
| 182 dest='wpr_archive_path', | |
| 183 help='WebPageReplay archive to use, instead of ' | |
| 184 'generating one.') | |
| 185 run_all.add_argument('--url-repeat', default=1, type=int, | |
| 186 help='How many times to repeat the urls.') | |
| 187 | |
| 169 return parser | 188 return parser |
| 170 | 189 |
| 171 | 190 |
| 172 def _RecordWprMain(args): | 191 def _RecordWprMain(args): |
| 173 sandwich_runner = SandwichRunner() | 192 sandwich_runner = SandwichRunner() |
| 174 sandwich_runner.LoadJob(args.job) | 193 sandwich_runner.LoadJob(args.job) |
| 175 sandwich_runner.PullConfigFromArgs(args) | 194 sandwich_runner.PullConfigFromArgs(args) |
| 176 sandwich_runner.wpr_record = True | 195 sandwich_runner.wpr_record = True |
| 177 sandwich_runner.PrintConfig() | 196 sandwich_runner.PrintConfig() |
| 178 if not os.path.isdir(os.path.dirname(args.wpr_archive_path)): | 197 if not os.path.isdir(os.path.dirname(args.wpr_archive_path)): |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 sandwich_runner.trace_output_directory = os.path.join(out_path, 'run') | 256 sandwich_runner.trace_output_directory = os.path.join(out_path, 'run') |
| 238 with WebServer.Context( | 257 with WebServer.Context( |
| 239 source_dir=args.source_dir, communication_dir=out_path) as server: | 258 source_dir=args.source_dir, communication_dir=out_path) as server: |
| 240 address = server.Address() | 259 address = server.Address() |
| 241 sandwich_runner.urls = ['http://%s/%s' % (address, args.page)] | 260 sandwich_runner.urls = ['http://%s/%s' % (address, args.page)] |
| 242 sandwich_runner.Run() | 261 sandwich_runner.Run() |
| 243 shutil.copy(os.path.join(out_path, 'run', '0', 'trace.json'), args.output) | 262 shutil.copy(os.path.join(out_path, 'run', '0', 'trace.json'), args.output) |
| 244 return 0 | 263 return 0 |
| 245 | 264 |
| 246 | 265 |
| 266 def _RunAllMain(args): | |
| 267 builder = sandwich_task_builder.SandwichTaskBuilder( | |
| 268 output_directory=args.output, | |
| 269 job_path=args.job, | |
| 270 url_repeat=args.url_repeat) | |
| 271 if args.wpr_archive_path: | |
| 272 builder.OverridePathToWprArchive(args.wpr_archive_path) | |
| 273 else: | |
| 274 builder.PopulateWprRecordingTask() | |
| 275 builder.PopulateCommonPipelines() | |
| 276 builder.PopulateLoadBenchmark(sandwich_misc.NO_DISCOVERER) | |
|
pasko
2016/04/18 09:36:12
this would create:
1. output/dummy/no-discoverer-r
gabadie
2016/04/19 17:39:48
Done.
| |
| 277 builder.PopulateLoadBenchmark(sandwich_misc.FULL_CACHE_DISCOVERER) | |
| 278 | |
| 279 if args.gen_full: | |
| 280 for subresource_discoverer in sandwich_misc.SUBRESOURCE_DISCOVERERS: | |
| 281 if subresource_discoverer == sandwich_misc.FULL_CACHE_DISCOVERER: | |
| 282 continue | |
| 283 for network_condition in ['Regular4G', 'Regular3G', 'Regular2G']: | |
| 284 runner_transformer_name = network_condition.lower() | |
| 285 runner_transformer = sandwich_task_builder.NetworkSimulationTransformer( | |
| 286 network_condition) | |
| 287 builder.PopulateLoadBenchmark(subresource_discoverer, | |
|
pasko
2016/04/18 09:36:12
nit: this call looks 33% shorter with all params o
gabadie
2016/04/19 17:39:48
Done.
| |
| 288 runner_transformer_name, | |
| 289 runner_transformer) | |
| 290 | |
| 291 return task_manager.ExecuteWithCommandLine( | |
| 292 args, builder.tasks.values(), builder.default_final_tasks) | |
| 293 | |
| 294 | |
| 247 def main(command_line_args): | 295 def main(command_line_args): |
| 248 logging.basicConfig(level=logging.INFO) | 296 logging.basicConfig(level=logging.INFO) |
| 249 devil_chromium.Initialize() | 297 devil_chromium.Initialize() |
| 250 | 298 |
| 251 args = _ArgumentParser().parse_args(command_line_args) | 299 args = _ArgumentParser().parse_args(command_line_args) |
| 252 OPTIONS.SetParsedArgs(args) | 300 OPTIONS.SetParsedArgs(args) |
| 253 | 301 |
| 254 if args.subcommand == 'record-wpr': | 302 if args.subcommand == 'record-wpr': |
| 255 return _RecordWprMain(args) | 303 return _RecordWprMain(args) |
| 256 if args.subcommand == 'patch-wpr': | 304 if args.subcommand == 'patch-wpr': |
| 257 sandwich_misc.PatchWpr(args.wpr_archive_path) | 305 sandwich_misc.PatchWpr(args.wpr_archive_path) |
| 258 return 0 | 306 return 0 |
| 259 if args.subcommand == 'create-cache': | 307 if args.subcommand == 'create-cache': |
| 260 return _CreateCacheMain(args) | 308 return _CreateCacheMain(args) |
| 261 if args.subcommand == 'run': | 309 if args.subcommand == 'run': |
| 262 return _RunJobMain(args) | 310 return _RunJobMain(args) |
| 263 if args.subcommand == 'extract-metrics': | 311 if args.subcommand == 'extract-metrics': |
| 264 return _ExtractMetricsMain(args) | 312 return _ExtractMetricsMain(args) |
| 265 if args.subcommand == 'filter-cache': | 313 if args.subcommand == 'filter-cache': |
| 266 return _FilterCacheMain(args) | 314 return _FilterCacheMain(args) |
| 267 if args.subcommand == 'record-test-trace': | 315 if args.subcommand == 'record-test-trace': |
| 268 return _RecordWebServerTestTrace(args) | 316 return _RecordWebServerTestTrace(args) |
| 317 if args.subcommand == 'run-all': | |
| 318 return _RunAllMain(args) | |
| 269 assert False | 319 assert False |
| 270 | 320 |
| 271 | 321 |
| 272 if __name__ == '__main__': | 322 if __name__ == '__main__': |
| 273 sys.exit(main(sys.argv[1:])) | 323 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |