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 json | 6 import json |
| 7 import logging |
7 import os | 8 import os |
8 import shutil | 9 import shutil |
9 | 10 |
10 import chrome_cache | 11 import chrome_cache |
11 import common_util | 12 import common_util |
12 import emulation | 13 import emulation |
| 14 from loading_trace import LoadingTrace |
13 import sandwich_metrics | 15 import sandwich_metrics |
14 import sandwich_misc | 16 import sandwich_misc |
15 import sandwich_runner | 17 import sandwich_runner |
16 import task_manager | 18 import task_manager |
17 | 19 |
18 | 20 |
19 def NetworkSimulationTransformer(network_condition): | 21 def NetworkSimulationTransformer(network_condition): |
20 """Creates a function that accepts a SandwichRunner as a parameter and sets | 22 """Creates a function that accepts a SandwichRunner as a parameter and sets |
21 network emulation options on it. | 23 network emulation options on it. |
22 | 24 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 SandwichRunner.Run() in the given order. | 184 SandwichRunner.Run() in the given order. |
183 | 185 |
184 Here is the full dependency of the added tree for the returned task: | 186 Here is the full dependency of the added tree for the returned task: |
185 <transformer_list_name>/<subresource_discoverer>-metrics.csv | 187 <transformer_list_name>/<subresource_discoverer>-metrics.csv |
186 depends on: <transformer_list_name>/<subresource_discoverer>-run/ | 188 depends on: <transformer_list_name>/<subresource_discoverer>-run/ |
187 depends on: common/<subresource_discoverer>-cache.zip | 189 depends on: common/<subresource_discoverer>-cache.zip |
188 depends on: some tasks saved by PopulateCommonPipelines() | 190 depends on: some tasks saved by PopulateCommonPipelines() |
189 depends on: common/<subresource_discoverer>-setup.json | 191 depends on: common/<subresource_discoverer>-setup.json |
190 depends on: some tasks saved by PopulateCommonPipelines() | 192 depends on: some tasks saved by PopulateCommonPipelines() |
191 """ | 193 """ |
| 194 ADDITIONAL_COLUMN_NAMES = [ |
| 195 'url', |
| 196 'repeat_id', |
| 197 'subresource_discoverer', |
| 198 'subresource_count', |
| 199 # The amount of subresources detected at SetupBenchmark step. |
| 200 'subresource_count_theoretic', |
| 201 # Amount of subresources for caching as suggested by the subresource |
| 202 # discoverer. |
| 203 'cached_subresource_count_theoretic', |
| 204 'cached_subresource_count'] |
| 205 |
192 assert subresource_discoverer in sandwich_misc.SUBRESOURCE_DISCOVERERS | 206 assert subresource_discoverer in sandwich_misc.SUBRESOURCE_DISCOVERERS |
193 assert 'common' not in sandwich_misc.SUBRESOURCE_DISCOVERERS | 207 assert 'common' not in sandwich_misc.SUBRESOURCE_DISCOVERERS |
194 shared_task_prefix = os.path.join('common', subresource_discoverer) | 208 shared_task_prefix = os.path.join('common', subresource_discoverer) |
195 task_prefix = os.path.join(transformer_list_name, subresource_discoverer) | 209 task_prefix = os.path.join(transformer_list_name, subresource_discoverer) |
196 | 210 |
197 @self.RegisterTask(shared_task_prefix + '-setup.json', merge=True, | 211 @self.RegisterTask(shared_task_prefix + '-setup.json', merge=True, |
198 dependencies=[self._subresources_for_urls_task]) | 212 dependencies=[self._subresources_for_urls_task]) |
199 def SetupBenchmark(): | 213 def SetupBenchmark(): |
200 trace_path = os.path.join(self._subresources_for_urls_run_task.path, '0', | 214 trace_path = os.path.join(self._subresources_for_urls_run_task.path, '0', |
201 sandwich_runner.TRACE_FILENAME) | 215 sandwich_runner.TRACE_FILENAME) |
(...skipping 29 matching lines...) Expand all Loading... |
231 runner.wpr_out_log_path = os.path.join( | 245 runner.wpr_out_log_path = os.path.join( |
232 RunBenchmark.path, sandwich_runner.WPR_LOG_FILENAME) | 246 RunBenchmark.path, sandwich_runner.WPR_LOG_FILENAME) |
233 runner.cache_archive_path = BuildBenchmarkCacheArchive.path | 247 runner.cache_archive_path = BuildBenchmarkCacheArchive.path |
234 runner.cache_operation = sandwich_runner.CacheOperation.PUSH | 248 runner.cache_operation = sandwich_runner.CacheOperation.PUSH |
235 runner.output_dir = RunBenchmark.path | 249 runner.output_dir = RunBenchmark.path |
236 runner.Run() | 250 runner.Run() |
237 | 251 |
238 @self.RegisterTask(task_prefix + '-metrics.csv', | 252 @self.RegisterTask(task_prefix + '-metrics.csv', |
239 dependencies=[RunBenchmark]) | 253 dependencies=[RunBenchmark]) |
240 def ExtractMetrics(): | 254 def ExtractMetrics(): |
| 255 # TODO PERF IMPROVMENT(gabadie): Can load trace only once an use it for |
| 256 # validation and metrics extraction. |
241 sandwich_misc.VerifyBenchmarkOutputDirectory( | 257 sandwich_misc.VerifyBenchmarkOutputDirectory( |
242 SetupBenchmark.path, RunBenchmark.path) | 258 SetupBenchmark.path, RunBenchmark.path) |
243 trace_metrics_list = \ | 259 |
244 sandwich_metrics.ExtractMetricsFromRunnerOutputDirectory( | 260 benchmark_setup = json.load(open(SetupBenchmark.path)) |
245 SetupBenchmark.path, RunBenchmark.path) | 261 run_metrics_list = [] |
246 trace_metrics_list.sort(key=lambda e: e['repeat_id']) | 262 for repeat_id, repeat_dir in sandwich_runner.IterRepeatedRuns( |
| 263 RunBenchmark.path): |
| 264 trace_path = os.path.join(repeat_dir, sandwich_runner.TRACE_FILENAME) |
| 265 logging.info('processing trace \'%s\'' % trace_path) |
| 266 trace = LoadingTrace.FromJsonFile(trace_path) |
| 267 run_metrics = { |
| 268 'url': trace.url, |
| 269 'repeat_id': repeat_id, |
| 270 'subresource_discoverer': benchmark_setup['subresource_discoverer'], |
| 271 'subresource_count': len(sandwich_misc.ListUrlRequests( |
| 272 trace, sandwich_misc.RequestOutcome.All)), |
| 273 'subresource_count_theoretic': |
| 274 len(benchmark_setup['url_resources']), |
| 275 'cached_subresource_count': len(sandwich_misc.ListUrlRequests( |
| 276 trace, sandwich_misc.RequestOutcome.ServedFromCache)), |
| 277 'cached_subresource_count_theoretic': |
| 278 len(benchmark_setup['cache_whitelist']), |
| 279 } |
| 280 run_metrics.update( |
| 281 sandwich_metrics.ExtractCommonMetricsFromRepeatDirectory( |
| 282 repeat_dir, trace)) |
| 283 |
| 284 run_metrics_list.sort(key=lambda e: e['repeat_id']) |
247 with open(ExtractMetrics.path, 'w') as csv_file: | 285 with open(ExtractMetrics.path, 'w') as csv_file: |
248 writer = csv.DictWriter(csv_file, | 286 writer = csv.DictWriter(csv_file, fieldnames=(ADDITIONAL_COLUMN_NAMES + |
249 fieldnames=sandwich_metrics.CSV_FIELD_NAMES) | 287 sandwich_metrics.COMMON_CSV_COLUMN_NAMES)) |
250 writer.writeheader() | 288 writer.writeheader() |
251 for trace_metrics in trace_metrics_list: | 289 for trace_metrics in run_metrics_list: |
252 writer.writerow(trace_metrics) | 290 writer.writerow(trace_metrics) |
253 | 291 |
254 self._common_builder.default_final_tasks.append(ExtractMetrics) | 292 self._common_builder.default_final_tasks.append(ExtractMetrics) |
OLD | NEW |