Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: tools/android/loading/sandwich.py

Issue 1872313002: sandwich: Implement SandwichTaskBuilder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses pasko's comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 task_parser = task_manager.CommandLineParser()
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
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, task_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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 sandwich_runner = SandwichRunner() 252 sandwich_runner = SandwichRunner()
234 # Reuse the WPR's forwarding to access the webpage from Android. 253 # Reuse the WPR's forwarding to access the webpage from Android.
235 sandwich_runner.wpr_record = True 254 sandwich_runner.wpr_record = True
236 sandwich_runner.wpr_archive_path = os.path.join(out_path, 'wpr') 255 sandwich_runner.wpr_archive_path = os.path.join(out_path, 'wpr')
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 trace_path = os.path.join(
263 out_path, 'run', '0', sandwich_runner.TRACE_FILENAME)
264 shutil.copy(trace_path, args.output)
244 return 0 265 return 0
245 266
246 267
268 def _RunAllMain(args):
269 builder = sandwich_task_builder.SandwichTaskBuilder(
270 output_directory=args.output,
271 job_path=args.job,
272 url_repeat=args.url_repeat)
273 if args.wpr_archive_path:
274 builder.OverridePathToWprArchive(args.wpr_archive_path)
275 else:
276 builder.PopulateWprRecordingTask()
277 builder.PopulateCommonPipelines()
278
279 runner_transformer_name = 'no-network-emulation'
280 runner_transformer = lambda arg: None
281 builder.PopulateLoadBenchmark(sandwich_misc.EMPTY_CACHE_DISCOVERER,
282 runner_transformer_name, runner_transformer)
283 builder.PopulateLoadBenchmark(sandwich_misc.FULL_CACHE_DISCOVERER,
284 runner_transformer_name, runner_transformer)
285
286 if args.gen_full:
287 for subresource_discoverer in sandwich_misc.SUBRESOURCE_DISCOVERERS:
288 if subresource_discoverer == sandwich_misc.FULL_CACHE_DISCOVERER:
289 continue
290 for network_condition in ['Regular4G', 'Regular3G', 'Regular2G']:
291 runner_transformer_name = network_condition.lower()
292 runner_transformer = sandwich_task_builder.NetworkSimulationTransformer(
293 network_condition)
294 builder.PopulateLoadBenchmark(
295 subresource_discoverer, runner_transformer_name, runner_transformer)
296
297 return task_manager.ExecuteWithCommandLine(
298 args, builder.tasks.values(), builder.default_final_tasks)
299
300
247 def main(command_line_args): 301 def main(command_line_args):
248 logging.basicConfig(level=logging.INFO) 302 logging.basicConfig(level=logging.INFO)
249 devil_chromium.Initialize() 303 devil_chromium.Initialize()
250 304
251 args = _ArgumentParser().parse_args(command_line_args) 305 args = _ArgumentParser().parse_args(command_line_args)
252 OPTIONS.SetParsedArgs(args) 306 OPTIONS.SetParsedArgs(args)
253 307
254 if args.subcommand == 'record-wpr': 308 if args.subcommand == 'record-wpr':
255 return _RecordWprMain(args) 309 return _RecordWprMain(args)
256 if args.subcommand == 'patch-wpr': 310 if args.subcommand == 'patch-wpr':
257 sandwich_misc.PatchWpr(args.wpr_archive_path) 311 sandwich_misc.PatchWpr(args.wpr_archive_path)
258 return 0 312 return 0
259 if args.subcommand == 'create-cache': 313 if args.subcommand == 'create-cache':
260 return _CreateCacheMain(args) 314 return _CreateCacheMain(args)
261 if args.subcommand == 'run': 315 if args.subcommand == 'run':
262 return _RunJobMain(args) 316 return _RunJobMain(args)
263 if args.subcommand == 'extract-metrics': 317 if args.subcommand == 'extract-metrics':
264 return _ExtractMetricsMain(args) 318 return _ExtractMetricsMain(args)
265 if args.subcommand == 'filter-cache': 319 if args.subcommand == 'filter-cache':
266 return _FilterCacheMain(args) 320 return _FilterCacheMain(args)
267 if args.subcommand == 'record-test-trace': 321 if args.subcommand == 'record-test-trace':
268 return _RecordWebServerTestTrace(args) 322 return _RecordWebServerTestTrace(args)
323 if args.subcommand == 'run-all':
324 return _RunAllMain(args)
269 assert False 325 assert False
270 326
271 327
272 if __name__ == '__main__': 328 if __name__ == '__main__':
273 sys.exit(main(sys.argv[1:])) 329 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698