| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 305 |
| 306 if not os.path.isdir(args.output): | 306 if not os.path.isdir(args.output): |
| 307 try: | 307 try: |
| 308 os.makedirs(args.output) | 308 os.makedirs(args.output) |
| 309 except OSError: | 309 except OSError: |
| 310 logging.error('Cannot create directory for results: %s' % args.output) | 310 logging.error('Cannot create directory for results: %s' % args.output) |
| 311 raise | 311 raise |
| 312 else: | 312 else: |
| 313 _CleanPreviousTraces(args.output) | 313 _CleanPreviousTraces(args.output) |
| 314 | 314 |
| 315 run_infos = { |
| 316 'cache-op': args.cache_op, |
| 317 'job': args.job, |
| 318 'urls': [] |
| 319 } |
| 315 job_urls = _ReadUrlsFromJobDescription(args.job) | 320 job_urls = _ReadUrlsFromJobDescription(args.job) |
| 316 device = device_utils.DeviceUtils.HealthyDevices()[0] | 321 device = device_utils.DeviceUtils.HealthyDevices()[0] |
| 317 local_cache_archive_path = os.path.join(args.output, 'cache.zip') | 322 local_cache_archive_path = os.path.join(args.output, 'cache.zip') |
| 318 local_cache_directory_path = None | 323 local_cache_directory_path = None |
| 319 | 324 |
| 320 if args.cache_op == 'push': | 325 if args.cache_op == 'push': |
| 321 assert os.path.isfile(local_cache_archive_path) | 326 assert os.path.isfile(local_cache_archive_path) |
| 322 local_cache_directory_path = tempfile.mkdtemp(suffix='.cache') | 327 local_cache_directory_path = tempfile.mkdtemp(suffix='.cache') |
| 323 _UnzipDirectoryContent(local_cache_archive_path, local_cache_directory_path) | 328 _UnzipDirectoryContent(local_cache_archive_path, local_cache_directory_path) |
| 324 | 329 |
| 325 with device_setup.WprHost(device, args.wpr_archive, args.wpr_record, | 330 with device_setup.WprHost(device, args.wpr_archive, args.wpr_record, |
| 326 args.disable_wpr_script_injection) as additional_flags: | 331 args.disable_wpr_script_injection) as additional_flags: |
| 327 pages_loaded = 0 | |
| 328 for _ in xrange(args.repeat): | 332 for _ in xrange(args.repeat): |
| 329 for url in job_urls: | 333 for url in job_urls: |
| 330 if args.cache_op == 'push': | 334 if args.cache_op == 'push': |
| 331 device.KillAll(_CHROME_PACKAGE, quiet=True) | 335 device.KillAll(_CHROME_PACKAGE, quiet=True) |
| 332 _PushBrowserCache(device, local_cache_directory_path) | 336 _PushBrowserCache(device, local_cache_directory_path) |
| 333 with device_setup.DeviceConnection( | 337 with device_setup.DeviceConnection( |
| 334 device=device, | 338 device=device, |
| 335 additional_flags=additional_flags) as connection: | 339 additional_flags=additional_flags) as connection: |
| 336 if (pages_loaded == 0 and args.cache_op == 'save' or | 340 if (not run_infos['urls'] and args.cache_op == 'save' or |
| 337 args.cache_op == 'clear'): | 341 args.cache_op == 'clear'): |
| 338 connection.ClearCache() | 342 connection.ClearCache() |
| 339 page_track.PageTrack(connection) | 343 page_track.PageTrack(connection) |
| 340 tracing_track = tracing.TracingTrack(connection, | 344 tracing_track = tracing.TracingTrack(connection, |
| 341 categories=pull_sandwich_metrics.CATEGORIES) | 345 categories=pull_sandwich_metrics.CATEGORIES) |
| 342 connection.SetUpMonitoring() | 346 connection.SetUpMonitoring() |
| 343 connection.SendAndIgnoreResponse('Page.navigate', {'url': url}) | 347 connection.SendAndIgnoreResponse('Page.navigate', {'url': url}) |
| 344 connection.StartMonitoring() | 348 connection.StartMonitoring() |
| 345 pages_loaded += 1 | |
| 346 _SaveChromeTrace(tracing_track.ToJsonDict(), args.output, | 349 _SaveChromeTrace(tracing_track.ToJsonDict(), args.output, |
| 347 str(pages_loaded)) | 350 str(len(run_infos['urls']))) |
| 351 run_infos['urls'].append(url) |
| 348 | 352 |
| 349 if local_cache_directory_path: | 353 if local_cache_directory_path: |
| 350 shutil.rmtree(local_cache_directory_path) | 354 shutil.rmtree(local_cache_directory_path) |
| 351 | 355 |
| 352 if args.cache_op == 'save': | 356 if args.cache_op == 'save': |
| 353 # Move Chrome to background to allow it to flush the index. | 357 # Move Chrome to background to allow it to flush the index. |
| 354 device.adb.Shell('am start com.google.android.launcher') | 358 device.adb.Shell('am start com.google.android.launcher') |
| 355 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS) | 359 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS) |
| 356 device.KillAll(_CHROME_PACKAGE, quiet=True) | 360 device.KillAll(_CHROME_PACKAGE, quiet=True) |
| 357 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS) | 361 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS) |
| 358 | 362 |
| 359 cache_directory_path = _PullBrowserCache(device) | 363 cache_directory_path = _PullBrowserCache(device) |
| 360 _ZipDirectoryContent(cache_directory_path, local_cache_archive_path) | 364 _ZipDirectoryContent(cache_directory_path, local_cache_archive_path) |
| 361 shutil.rmtree(cache_directory_path) | 365 shutil.rmtree(cache_directory_path) |
| 362 | 366 |
| 367 with open(os.path.join(args.output, 'run_infos.json'), 'w') as file_output: |
| 368 json.dump(run_infos, file_output, indent=2) |
| 369 |
| 363 | 370 |
| 364 if __name__ == '__main__': | 371 if __name__ == '__main__': |
| 365 sys.exit(main()) | 372 sys.exit(main()) |
| OLD | NEW |