OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 Implements a task builder for benchmarking effects of NoState Prefetch. | 6 Implements a task builder for benchmarking effects of NoState Prefetch. |
7 Noticeable steps of the task pipeline: | 7 Noticeable steps of the task pipeline: |
8 * Save a WPR archive | 8 * Save a WPR archive |
9 * Process the WPR archive to make all resources cacheable | 9 * Process the WPR archive to make all resources cacheable |
10 * Process cache archive to patch response headers back to their original | 10 * Process cache archive to patch response headers back to their original |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 runner_output_dir): | 407 runner_output_dir): |
408 trace_path = os.path.join(repeat_dir, sandwich_runner.TRACE_FILENAME) | 408 trace_path = os.path.join(repeat_dir, sandwich_runner.TRACE_FILENAME) |
409 | 409 |
410 logging.info('loading trace: %s', trace_path) | 410 logging.info('loading trace: %s', trace_path) |
411 trace = loading_trace.LoadingTrace.FromJsonFile(trace_path) | 411 trace = loading_trace.LoadingTrace.FromJsonFile(trace_path) |
412 | 412 |
413 logging.info('verifying trace: %s', trace_path) | 413 logging.info('verifying trace: %s', trace_path) |
414 run_output_verifier.VerifyTrace(trace) | 414 run_output_verifier.VerifyTrace(trace) |
415 | 415 |
416 logging.info('extracting metrics from trace: %s', trace_path) | 416 logging.info('extracting metrics from trace: %s', trace_path) |
417 served_from_network_bytes = 0 | 417 |
418 served_from_cache_bytes = 0 | 418 # Gather response size per URLs. |
419 urls_hitting_network = set() | |
420 response_sizes = {} | 419 response_sizes = {} |
421 for request in sandwich_utils.FilterOutDataAndIncompleteRequests( | 420 for request in sandwich_utils.FilterOutDataAndIncompleteRequests( |
422 trace.request_track.GetEvents()): | 421 trace.request_track.GetEvents()): |
423 # Ignore requests served from the blink's cache. | 422 # Ignore requests served from the blink's cache. |
424 if request.served_from_cache: | 423 if request.served_from_cache: |
425 continue | 424 continue |
426 urls_hitting_network.add(request.url) | |
427 if request.from_disk_cache: | 425 if request.from_disk_cache: |
428 if request.url in cached_encoded_data_lengths: | 426 if request.url in cached_encoded_data_lengths: |
429 response_size = cached_encoded_data_lengths[request.url] | 427 response_size = cached_encoded_data_lengths[request.url] |
430 else: | 428 else: |
431 # Some fat webpages may overflow the Memory cache, and so some | 429 # Some fat webpages may overflow the Memory cache, and so some |
432 # requests might be served from disk cache couple of times per page | 430 # requests might be served from disk cache couple of times per page |
433 # load. | 431 # load. |
434 logging.warning('Looks like could be served from memory cache: %s', | 432 logging.warning('Looks like could be served from memory cache: %s', |
435 request.url) | 433 request.url) |
436 response_size = response_sizes[request.url] | 434 if request.url in response_sizes: |
437 served_from_cache_bytes += response_size | 435 response_size = response_sizes[request.url] |
438 else: | 436 else: |
439 response_size = request.GetResponseTransportLength() | 437 response_size = request.GetResponseTransportLength() |
440 served_from_network_bytes += response_size | |
441 response_sizes[request.url] = response_size | 438 response_sizes[request.url] = response_size |
442 | 439 |
| 440 # Sums the served from cache/network bytes. |
| 441 served_from_network_bytes = 0 |
| 442 served_from_cache_bytes = 0 |
| 443 urls_hitting_network = set() |
| 444 for request in sandwich_utils.FilterOutDataAndIncompleteRequests( |
| 445 trace.request_track.GetEvents()): |
| 446 # Ignore requests served from the blink's cache. |
| 447 if request.served_from_cache: |
| 448 continue |
| 449 urls_hitting_network.add(request.url) |
| 450 if request.from_disk_cache: |
| 451 served_from_cache_bytes += response_sizes[request.url] |
| 452 else: |
| 453 served_from_network_bytes += response_sizes[request.url] |
| 454 |
443 # Make sure the served from blink's cache requests have at least one | 455 # Make sure the served from blink's cache requests have at least one |
444 # corresponding request that was not served from the blink's cache. | 456 # corresponding request that was not served from the blink's cache. |
445 for request in sandwich_utils.FilterOutDataAndIncompleteRequests( | 457 for request in sandwich_utils.FilterOutDataAndIncompleteRequests( |
446 trace.request_track.GetEvents()): | 458 trace.request_track.GetEvents()): |
447 assert (request.url in urls_hitting_network or | 459 assert (request.url in urls_hitting_network or |
448 not request.served_from_cache) | 460 not request.served_from_cache) |
449 | 461 |
450 run_metrics = { | 462 run_metrics = { |
451 'url': trace.url, | 463 'url': trace.url, |
452 'repeat_id': repeat_id, | 464 'repeat_id': repeat_id, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 run_metrics_list = _ProcessRunOutputDir( | 669 run_metrics_list = _ProcessRunOutputDir( |
658 cache_validation_result, benchmark_setup, RunBenchmark.path) | 670 cache_validation_result, benchmark_setup, RunBenchmark.path) |
659 with open(ProcessRunOutputDir.path, 'w') as csv_file: | 671 with open(ProcessRunOutputDir.path, 'w') as csv_file: |
660 writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names + | 672 writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names + |
661 sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) | 673 sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) |
662 writer.writeheader() | 674 writer.writeheader() |
663 for trace_metrics in run_metrics_list: | 675 for trace_metrics in run_metrics_list: |
664 writer.writerow(trace_metrics) | 676 writer.writerow(trace_metrics) |
665 | 677 |
666 self._common_builder.default_final_tasks.append(ProcessRunOutputDir) | 678 self._common_builder.default_final_tasks.append(ProcessRunOutputDir) |
OLD | NEW |