Commit 866025e8 authored by gabadie's avatar gabadie Committed by Commit bot

sandwich: Fixes a bug when served from cache request are before.

Before, prefetch experiment's CSV collection was maintaining a dict
of transfered bytes per URLs as it was iterating over all resource
requests and served from memory cache URLs request would just grabe
the size from this dictionary. But we may have requests served from
memory cache before original request that filled the memory cache,
leading to a KeyError.

This CL fixes this issue by first building the dictionary by going
over resources requests, and then actually sum the bytes using this
dictionary, avoiding the KeyError.

BUG=582080

Review-Url: https://codereview.chromium.org/2134763002
Cr-Commit-Position: refs/heads/master@{#404626}
parent d74b7d28
...@@ -414,16 +414,14 @@ def _ProcessRunOutputDir( ...@@ -414,16 +414,14 @@ def _ProcessRunOutputDir(
run_output_verifier.VerifyTrace(trace) run_output_verifier.VerifyTrace(trace)
logging.info('extracting metrics from trace: %s', trace_path) logging.info('extracting metrics from trace: %s', trace_path)
served_from_network_bytes = 0
served_from_cache_bytes = 0 # Gather response size per URLs.
urls_hitting_network = set()
response_sizes = {} response_sizes = {}
for request in sandwich_utils.FilterOutDataAndIncompleteRequests( for request in sandwich_utils.FilterOutDataAndIncompleteRequests(
trace.request_track.GetEvents()): trace.request_track.GetEvents()):
# Ignore requests served from the blink's cache. # Ignore requests served from the blink's cache.
if request.served_from_cache: if request.served_from_cache:
continue continue
urls_hitting_network.add(request.url)
if request.from_disk_cache: if request.from_disk_cache:
if request.url in cached_encoded_data_lengths: if request.url in cached_encoded_data_lengths:
response_size = cached_encoded_data_lengths[request.url] response_size = cached_encoded_data_lengths[request.url]
...@@ -433,13 +431,27 @@ def _ProcessRunOutputDir( ...@@ -433,13 +431,27 @@ def _ProcessRunOutputDir(
# load. # load.
logging.warning('Looks like could be served from memory cache: %s', logging.warning('Looks like could be served from memory cache: %s',
request.url) request.url)
response_size = response_sizes[request.url] if request.url in response_sizes:
served_from_cache_bytes += response_size response_size = response_sizes[request.url]
else: else:
response_size = request.GetResponseTransportLength() response_size = request.GetResponseTransportLength()
served_from_network_bytes += response_size
response_sizes[request.url] = response_size response_sizes[request.url] = response_size
# Sums the served from cache/network bytes.
served_from_network_bytes = 0
served_from_cache_bytes = 0
urls_hitting_network = set()
for request in sandwich_utils.FilterOutDataAndIncompleteRequests(
trace.request_track.GetEvents()):
# Ignore requests served from the blink's cache.
if request.served_from_cache:
continue
urls_hitting_network.add(request.url)
if request.from_disk_cache:
served_from_cache_bytes += response_sizes[request.url]
else:
served_from_network_bytes += response_sizes[request.url]
# Make sure the served from blink's cache requests have at least one # Make sure the served from blink's cache requests have at least one
# corresponding request that was not served from the blink's cache. # corresponding request that was not served from the blink's cache.
for request in sandwich_utils.FilterOutDataAndIncompleteRequests( for request in sandwich_utils.FilterOutDataAndIncompleteRequests(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment