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

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

Issue 2112013003: sandwich: Use cachetool's batch mode to speed-up cache processing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@af00
Patch Set: s/Online/Batch Created 4 years, 5 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
« no previous file with comments | « tools/android/loading/sandwich_prefetch.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import csv 5 import csv
6 import logging 6 import logging
7 import os 7 import os
8 import shutil 8 import shutil
9 9
10 import chrome_cache 10 import chrome_cache
11 import common_util 11 import common_util
12 import loading_trace 12 import loading_trace
13 import request_track 13 import request_track
14 import sandwich_metrics 14 import sandwich_metrics
15 import sandwich_runner 15 import sandwich_runner
16 import task_manager 16 import task_manager
17 17
18 18
19 def _BuildPatchedCache(original_cache_run_path, original_cache_archive_path, 19 def _BuildPatchedCache(original_cache_run_path, original_cache_archive_path,
20 cache_archive_dest_path): 20 cache_archive_dest_path):
21 CACHE_CONTROL_VALUE = 'max-age=0,stale-while-revalidate=315360000' 21 CACHE_CONTROL_VALUE = 'max-age=0,stale-while-revalidate=315360000'
22 trace_path = os.path.join( 22 trace_path = os.path.join(
23 original_cache_run_path, '0', sandwich_runner.TRACE_FILENAME) 23 original_cache_run_path, '0', sandwich_runner.TRACE_FILENAME)
24 trace = loading_trace.LoadingTrace.FromJsonFile(trace_path) 24 trace = loading_trace.LoadingTrace.FromJsonFile(trace_path)
25 patch_count = 0 25 patch_count = 0
26 with common_util.TemporaryDirectory(prefix='sandwich_tmp') as tmp_path: 26 with common_util.TemporaryDirectory(prefix='sandwich_tmp') as tmp_path:
27 cache_path = os.path.join(tmp_path, 'cache') 27 cache_path = os.path.join(tmp_path, 'cache')
28 chrome_cache.UnzipDirectoryContent(original_cache_archive_path, cache_path) 28 chrome_cache.UnzipDirectoryContent(original_cache_archive_path, cache_path)
29 cache_backend = chrome_cache.CacheBackend(cache_path, 'simple') 29 cache_backend = chrome_cache.BatchCacheBackend(
30 cache_path, chrome_cache.CacheBackendType.SIMPLE)
30 cache_keys = set(cache_backend.ListKeys()) 31 cache_keys = set(cache_backend.ListKeys())
31 for request in trace.request_track.GetEvents(): 32 for request in trace.request_track.GetEvents():
32 if request.url not in cache_keys: 33 if request.url not in cache_keys:
33 continue 34 continue
34 caching_policy = request_track.CachingPolicy(request) 35 caching_policy = request_track.CachingPolicy(request)
35 assert caching_policy.IsCacheable() 36 assert caching_policy.IsCacheable()
36 freshness = caching_policy.GetFreshnessLifetimes() 37 freshness = caching_policy.GetFreshnessLifetimes()
37 if freshness[0] == 0: 38 if freshness[0] == 0:
38 continue 39 continue
39 request.SetHTTPResponseHeader('cache-control', CACHE_CONTROL_VALUE) 40 request.SetHTTPResponseHeader('cache-control', CACHE_CONTROL_VALUE)
40 raw_headers = request.GetRawResponseHeaders() 41 raw_headers = request.GetRawResponseHeaders()
41 cache_backend.UpdateRawResponseHeaders(request.url, raw_headers) 42 cache_backend.UpdateRawResponseHeaders(request.url, raw_headers)
42 patch_count += 1 43 patch_count += 1
44 cache_backend.ProcessBatch()
43 chrome_cache.ZipDirectoryContent(cache_path, cache_archive_dest_path) 45 chrome_cache.ZipDirectoryContent(cache_path, cache_archive_dest_path)
44 logging.info('Patched %d cached resources out of %d' % ( 46 logging.info('Patched %d cached resources out of %d' % (
45 patch_count, len(cache_keys))) 47 patch_count, len(cache_keys)))
46 48
47 49
48 class StaleWhileRevalidateBenchmarkBuilder(task_manager.Builder): 50 class StaleWhileRevalidateBenchmarkBuilder(task_manager.Builder):
49 """A builder for a graph of tasks for Stale-While-Revalidate study benchmarks. 51 """A builder for a graph of tasks for Stale-While-Revalidate study benchmarks.
50 """ 52 """
51 53
52 def __init__(self, common_builder): 54 def __init__(self, common_builder):
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 145
144 run_metrics_list.sort(key=lambda e: e['repeat_id']) 146 run_metrics_list.sort(key=lambda e: e['repeat_id'])
145 with open(ExtractMetrics.path, 'w') as csv_file: 147 with open(ExtractMetrics.path, 'w') as csv_file:
146 writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names + 148 writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names +
147 sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) 149 sandwich_metrics.COMMON_CSV_COLUMN_NAMES))
148 writer.writeheader() 150 writer.writeheader()
149 for trace_metrics in run_metrics_list: 151 for trace_metrics in run_metrics_list:
150 writer.writerow(trace_metrics) 152 writer.writerow(trace_metrics)
151 153
152 self._common_builder.default_final_tasks.append(ExtractMetrics) 154 self._common_builder.default_final_tasks.append(ExtractMetrics)
OLDNEW
« no previous file with comments | « tools/android/loading/sandwich_prefetch.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698