Chromium Code Reviews| 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 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 emulation | 12 import emulation |
| 13 import sandwich_metrics | 13 import sandwich_metrics |
| 14 import sandwich_misc | 14 import sandwich_misc |
| 15 import sandwich_runner | 15 import sandwich_runner |
| 16 import task_manager | 16 import task_manager |
| 17 | 17 |
| 18 | 18 |
| 19 def NetworkSimulationTransformer(network_condition): | 19 def NetworkSimulationTransformer(network_condition, |
| 20 parent_transformer=lambda _: None): | |
|
pasko
2016/04/28 15:04:59
default arg value is not needed, please remove
gabadie
2016/04/28 15:56:22
Done.
| |
| 20 """Creates a function that accepts a SandwichRunner as a parameter and sets | 21 """Creates a function that accepts a SandwichRunner as a parameter and sets |
| 21 network emulation options on it. | 22 network emulation options on it. |
| 22 | 23 |
| 23 Args: | 24 Args: |
| 24 network_condition: The network condition to apply to the sandwich runner. | 25 network_condition: The network condition to apply to the sandwich runner. |
| 26 parent_transformer: An optional SandwichRunner transformer to use BEFORE | |
| 27 the network condition setup. | |
| 25 | 28 |
| 26 Returns: | 29 Returns: |
| 27 A callback transforming the SandwichRunner given in argument accordingly | 30 A callback transforming the SandwichRunner given in argument accordingly |
| 28 """ | 31 """ |
| 29 assert network_condition in emulation.NETWORK_CONDITIONS | 32 assert network_condition in emulation.NETWORK_CONDITIONS |
| 30 def Transformer(runner): | 33 def Transformer(runner): |
| 31 assert isinstance(runner, sandwich_runner.SandwichRunner) | 34 assert isinstance(runner, sandwich_runner.SandwichRunner) |
| 35 parent_transformer(runner) | |
| 32 runner.network_condition = network_condition | 36 runner.network_condition = network_condition |
| 33 return Transformer | 37 return Transformer |
| 34 | 38 |
| 35 | 39 |
| 36 class SandwichTaskBuilder(task_manager.Builder): | 40 class SandwichTaskBuilder(task_manager.Builder): |
| 37 """A builder for a graph of tasks, each prepares or invokes a SandwichRunner. | 41 """A builder for a graph of tasks, each prepares or invokes a SandwichRunner. |
| 38 """ | 42 """ |
| 39 | 43 |
| 40 def __init__(self, output_directory, android_device, job_path, url_repeat): | 44 def __init__(self, output_directory, android_device, job_path): |
| 41 """Constructor. | 45 """Constructor. |
| 42 | 46 |
| 43 Args: | 47 Args: |
| 44 output_directory: As in task_manager.Builder.__init__ | 48 output_directory: As in task_manager.Builder.__init__ |
| 45 android_device: The android DeviceUtils to run sandwich on or None to run | 49 android_device: The android DeviceUtils to run sandwich on or None to run |
| 46 it locally. | 50 it locally. |
| 47 job_path: Path of the sandwich's job. | 51 job_path: Path of the sandwich's job. |
| 48 url_repeat: Non null integer controlling how many times the URLs should be | |
| 49 repeated in the benchmarks. | |
| 50 """ | 52 """ |
| 51 task_manager.Builder.__init__(self, output_directory) | 53 task_manager.Builder.__init__(self, output_directory) |
| 52 self._android_device = android_device | 54 self._android_device = android_device |
| 53 self._job_path = job_path | 55 self._job_path = job_path |
| 54 self._url_repeat = url_repeat | |
| 55 self._default_final_tasks = [] | 56 self._default_final_tasks = [] |
| 56 | 57 |
| 57 self._original_wpr_task = None | 58 self._original_wpr_task = None |
| 58 self._patched_wpr_task = None | 59 self._patched_wpr_task = None |
| 59 self._reference_cache_task = None | 60 self._reference_cache_task = None |
| 60 self._subresources_for_urls_run_task = None | 61 self._subresources_for_urls_run_task = None |
| 61 self._subresources_for_urls_task = None | 62 self._subresources_for_urls_task = None |
| 62 | 63 |
| 63 @property | 64 @property |
| 64 def default_final_tasks(self): | 65 def default_final_tasks(self): |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 setup = json.load(open(SetupBenchmark.path)) | 215 setup = json.load(open(SetupBenchmark.path)) |
| 215 chrome_cache.ApplyUrlWhitelistToCacheArchive( | 216 chrome_cache.ApplyUrlWhitelistToCacheArchive( |
| 216 cache_archive_path=self._reference_cache_task.path, | 217 cache_archive_path=self._reference_cache_task.path, |
| 217 whitelisted_urls=setup['cache_whitelist'], | 218 whitelisted_urls=setup['cache_whitelist'], |
| 218 output_cache_archive_path=BuildBenchmarkCacheArchive.path) | 219 output_cache_archive_path=BuildBenchmarkCacheArchive.path) |
| 219 | 220 |
| 220 @self.RegisterTask(task_prefix + '-run/', | 221 @self.RegisterTask(task_prefix + '-run/', |
| 221 dependencies=[BuildBenchmarkCacheArchive]) | 222 dependencies=[BuildBenchmarkCacheArchive]) |
| 222 def RunBenchmark(): | 223 def RunBenchmark(): |
| 223 runner = self._CreateSandwichRunner() | 224 runner = self._CreateSandwichRunner() |
| 224 # runner.record_video = True | |
| 225 runner.job_repeat = self._url_repeat | |
| 226 runner_transformer(runner) | 225 runner_transformer(runner) |
| 227 runner.wpr_archive_path = self._patched_wpr_task.path | 226 runner.wpr_archive_path = self._patched_wpr_task.path |
| 228 runner.wpr_out_log_path = os.path.join(RunBenchmark.path, 'wpr.log') | 227 runner.wpr_out_log_path = os.path.join(RunBenchmark.path, 'wpr.log') |
| 229 runner.cache_archive_path = BuildBenchmarkCacheArchive.path | 228 runner.cache_archive_path = BuildBenchmarkCacheArchive.path |
| 230 runner.cache_operation = 'push' | 229 runner.cache_operation = 'push' |
| 231 runner.trace_output_directory = RunBenchmark.path | 230 runner.trace_output_directory = RunBenchmark.path |
| 232 runner.Run() | 231 runner.Run() |
| 233 | 232 |
| 234 @self.RegisterTask(task_prefix + '-metrics.csv', | 233 @self.RegisterTask(task_prefix + '-metrics.csv', |
| 235 dependencies=[RunBenchmark]) | 234 dependencies=[RunBenchmark]) |
| 236 def ExtractMetrics(): | 235 def ExtractMetrics(): |
| 237 sandwich_misc.VerifyBenchmarkOutputDirectory( | 236 sandwich_misc.VerifyBenchmarkOutputDirectory( |
| 238 SetupBenchmark.path, RunBenchmark.path) | 237 SetupBenchmark.path, RunBenchmark.path) |
| 239 trace_metrics_list = \ | 238 trace_metrics_list = \ |
| 240 sandwich_metrics.ExtractMetricsFromRunnerOutputDirectory( | 239 sandwich_metrics.ExtractMetricsFromRunnerOutputDirectory( |
| 241 RunBenchmark.path) | 240 RunBenchmark.path) |
| 242 trace_metrics_list.sort(key=lambda e: e['repeat_id']) | 241 trace_metrics_list.sort(key=lambda e: e['repeat_id']) |
| 243 with open(ExtractMetrics.path, 'w') as csv_file: | 242 with open(ExtractMetrics.path, 'w') as csv_file: |
| 244 writer = csv.DictWriter(csv_file, | 243 writer = csv.DictWriter(csv_file, |
| 245 fieldnames=sandwich_metrics.CSV_FIELD_NAMES) | 244 fieldnames=sandwich_metrics.CSV_FIELD_NAMES) |
| 246 writer.writeheader() | 245 writer.writeheader() |
| 247 for trace_metrics in trace_metrics_list: | 246 for trace_metrics in trace_metrics_list: |
| 248 writer.writerow(trace_metrics) | 247 writer.writerow(trace_metrics) |
| 249 | 248 |
| 250 self._default_final_tasks.append(ExtractMetrics) | 249 self._default_final_tasks.append(ExtractMetrics) |
| 251 return ExtractMetrics | 250 return ExtractMetrics |
| OLD | NEW |