| 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 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.CacheBackend( | 
 |   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) | 
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  143  |  144  | 
|  144       run_metrics_list.sort(key=lambda e: e['repeat_id']) |  145       run_metrics_list.sort(key=lambda e: e['repeat_id']) | 
|  145       with open(ExtractMetrics.path, 'w') as csv_file: |  146       with open(ExtractMetrics.path, 'w') as csv_file: | 
|  146         writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names + |  147         writer = csv.DictWriter(csv_file, fieldnames=(additional_column_names + | 
|  147                                     sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) |  148                                     sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) | 
|  148         writer.writeheader() |  149         writer.writeheader() | 
|  149         for trace_metrics in run_metrics_list: |  150         for trace_metrics in run_metrics_list: | 
|  150           writer.writerow(trace_metrics) |  151           writer.writerow(trace_metrics) | 
|  151  |  152  | 
|  152     self._common_builder.default_final_tasks.append(ExtractMetrics) |  153     self._common_builder.default_final_tasks.append(ExtractMetrics) | 
| OLD | NEW |