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