| 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 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 in Task names (prefer names without spaces and special characters). | 94 in Task names (prefer names without spaces and special characters). |
| 95 transformer_list: An ordered list of function that takes an instance of | 95 transformer_list: An ordered list of function that takes an instance of |
| 96 SandwichRunner as parameter, would be applied immediately before | 96 SandwichRunner as parameter, would be applied immediately before |
| 97 SandwichRunner.Run() in the given order. | 97 SandwichRunner.Run() in the given order. |
| 98 | 98 |
| 99 Here is the full dependency of the added tree for the returned task: | 99 Here is the full dependency of the added tree for the returned task: |
| 100 <transformer_list_name>/{swr,worstcase}-metrics.csv | 100 <transformer_list_name>/{swr,worstcase}-metrics.csv |
| 101 depends on: <transformer_list_name>/{swr,worstcase}-run/ | 101 depends on: <transformer_list_name>/{swr,worstcase}-run/ |
| 102 depends on: some tasks saved by PopulateCommonPipelines() | 102 depends on: some tasks saved by PopulateCommonPipelines() |
| 103 """ | 103 """ |
| 104 ADDITIONAL_COLUMN_NAMES = ['url', 'repeat_id'] |
| 105 |
| 104 task_prefix = os.path.join(transformer_list_name, '') | 106 task_prefix = os.path.join(transformer_list_name, '') |
| 105 if enable_swr: | 107 if enable_swr: |
| 106 task_prefix += 'swr' | 108 task_prefix += 'swr' |
| 107 else: | 109 else: |
| 108 task_prefix += 'worstcase' | 110 task_prefix += 'worstcase' |
| 109 | 111 |
| 110 @self.RegisterTask(task_prefix + '-run/', [self._patched_cache_task]) | 112 @self.RegisterTask(task_prefix + '-run/', [self._patched_cache_task]) |
| 111 def RunBenchmark(): | 113 def RunBenchmark(): |
| 112 runner = self._common_builder.CreateSandwichRunner() | 114 runner = self._common_builder.CreateSandwichRunner() |
| 113 for transformer in transformer_list: | 115 for transformer in transformer_list: |
| 114 transformer(runner) | 116 transformer(runner) |
| 115 runner.wpr_archive_path = self._common_builder.original_wpr_task.path | 117 runner.wpr_archive_path = self._common_builder.original_wpr_task.path |
| 116 runner.wpr_out_log_path = os.path.join( | 118 runner.wpr_out_log_path = os.path.join( |
| 117 RunBenchmark.path, sandwich_runner.WPR_LOG_FILENAME) | 119 RunBenchmark.path, sandwich_runner.WPR_LOG_FILENAME) |
| 118 runner.cache_archive_path = self._patched_cache_task.path | 120 runner.cache_archive_path = self._patched_cache_task.path |
| 119 runner.cache_operation = sandwich_runner.CacheOperation.PUSH | 121 runner.cache_operation = sandwich_runner.CacheOperation.PUSH |
| 120 runner.output_dir = RunBenchmark.path | 122 runner.output_dir = RunBenchmark.path |
| 121 if enable_swr: | 123 if enable_swr: |
| 122 runner.chrome_args.append('--enable-features=StaleWhileRevalidate2') | 124 runner.chrome_args.append('--enable-features=StaleWhileRevalidate2') |
| 123 runner.Run() | 125 runner.Run() |
| 124 | 126 |
| 125 @self.RegisterTask(task_prefix + '-metrics.csv', [RunBenchmark]) | 127 @self.RegisterTask(task_prefix + '-metrics.csv', [RunBenchmark]) |
| 126 def ExtractMetrics(): | 128 def ExtractMetrics(): |
| 127 trace_metrics_list = \ | 129 run_metrics_list = [] |
| 128 sandwich_metrics.ExtractMetricsFromRunnerOutputDirectory( | 130 for repeat_id, repeat_dir in sandwich_runner.WalkRepeatedRuns( |
| 129 None, RunBenchmark.path) | 131 RunBenchmark.path): |
| 130 trace_metrics_list.sort(key=lambda e: e['repeat_id']) | 132 trace_path = os.path.join(repeat_dir, sandwich_runner.TRACE_FILENAME) |
| 133 logging.info('processing trace: %s', trace_path) |
| 134 trace = loading_trace.LoadingTrace.FromJsonFile(trace_path) |
| 135 run_metrics = { |
| 136 'url': trace.url, |
| 137 'repeat_id': repeat_id, |
| 138 } |
| 139 run_metrics.update( |
| 140 sandwich_metrics.ExtractCommonMetricsFromRepeatDirectory( |
| 141 repeat_dir, trace)) |
| 142 run_metrics_list.append(run_metrics) |
| 143 |
| 144 run_metrics_list.sort(key=lambda e: e['repeat_id']) |
| 131 with open(ExtractMetrics.path, 'w') as csv_file: | 145 with open(ExtractMetrics.path, 'w') as csv_file: |
| 132 writer = csv.DictWriter(csv_file, | 146 writer = csv.DictWriter(csv_file, fieldnames=(ADDITIONAL_COLUMN_NAMES + |
| 133 fieldnames=sandwich_metrics.CSV_FIELD_NAMES) | 147 sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) |
| 134 writer.writeheader() | 148 writer.writeheader() |
| 135 for trace_metrics in trace_metrics_list: | 149 for trace_metrics in run_metrics_list: |
| 136 writer.writerow(trace_metrics) | 150 writer.writerow(trace_metrics) |
| 137 | 151 |
| 138 self._common_builder.default_final_tasks.append(ExtractMetrics) | 152 self._common_builder.default_final_tasks.append(ExtractMetrics) |
| OLD | NEW |