| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This module fetches and prints the dependencies given a benchmark.""" | 6 """This module fetches and prints the dependencies given a benchmark.""" |
| 7 | 7 |
| 8 import argparse |
| 8 import os | 9 import os |
| 9 import sys | 10 import sys |
| 10 | 11 |
| 12 from core import benchmark_finders |
| 11 from core import path_util | 13 from core import path_util |
| 12 | 14 |
| 13 path_util.AddPyUtilsToPath() | 15 path_util.AddPyUtilsToPath() |
| 14 from py_utils import cloud_storage | 16 from py_utils import cloud_storage |
| 15 | 17 |
| 16 path_util.AddTelemetryToPath() | 18 path_util.AddTelemetryToPath() |
| 17 from telemetry import benchmark_runner | 19 from telemetry import benchmark_runner |
| 18 | 20 |
| 19 from chrome_telemetry_build import chromium_config | 21 from chrome_telemetry_build import chromium_config |
| 20 | 22 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 path_name, extension = os.path.splitext( | 52 path_name, extension = os.path.splitext( |
| 51 os.path.join(dirpath, filename)) | 53 os.path.join(dirpath, filename)) |
| 52 if extension == '.sha1': | 54 if extension == '.sha1': |
| 53 deps.add(path_name) | 55 deps.add(path_name) |
| 54 | 56 |
| 55 # Return relative paths. | 57 # Return relative paths. |
| 56 prefix_len = len(os.path.realpath(path_util.GetChromiumSrcDir())) + 1 | 58 prefix_len = len(os.path.realpath(path_util.GetChromiumSrcDir())) + 1 |
| 57 return [dep[prefix_len:] for dep in deps if dep] | 59 return [dep[prefix_len:] for dep in deps if dep] |
| 58 | 60 |
| 59 | 61 |
| 60 def _show_usage(): | 62 def FetchDepsForBenchmark(benchmark, output): |
| 61 print ('Usage: %s benchmark_name\n' | |
| 62 'Fetch the dependencies of benchmark_name.' % sys.argv[0]) | |
| 63 | |
| 64 | |
| 65 def main(output=sys.stdout): | |
| 66 config = chromium_config.ChromiumConfig( | |
| 67 top_level_dir=path_util.GetPerfDir(), | |
| 68 benchmark_dirs=[os.path.join(path_util.GetPerfDir(), 'benchmarks')]) | |
| 69 | |
| 70 name = sys.argv[1] | |
| 71 benchmark = benchmark_runner.GetBenchmarkByName(name, config) | |
| 72 if not benchmark: | |
| 73 raise ValueError('No such benchmark: %s' % name) | |
| 74 | |
| 75 # Download files according to specified benchmark. | 63 # Download files according to specified benchmark. |
| 76 story_set = benchmark().CreateStorySet(None) | 64 story_set = benchmark().CreateStorySet(None) |
| 77 | 65 |
| 78 _FetchDependenciesIfNeeded(story_set) | 66 _FetchDependenciesIfNeeded(story_set) |
| 79 | 67 |
| 80 # Print files downloaded. | 68 # Print files downloaded. |
| 81 deps = _EnumerateDependencies(story_set) | 69 deps = _EnumerateDependencies(story_set) |
| 82 for dep in deps: | 70 for dep in deps: |
| 83 print >> output, dep | 71 print >> output, dep |
| 84 | 72 |
| 85 | 73 |
| 74 def main(args, output): |
| 75 parser = argparse.ArgumentParser( |
| 76 description='Fetch the dependencies of perf benchmark(s).') |
| 77 parser.add_argument('benchmark_name', type=str, nargs='?') |
| 78 parser.add_argument('--force', '-f', |
| 79 help=('Force fetching all the benchmarks when ' |
| 80 'benchmark_name is not specified'), |
| 81 action='store_true', default=False) |
| 82 |
| 83 options = parser.parse_args(args) |
| 84 |
| 85 if options.benchmark_name: |
| 86 config = chromium_config.ChromiumConfig( |
| 87 top_level_dir=path_util.GetPerfDir(), |
| 88 benchmark_dirs=[os.path.join(path_util.GetPerfDir(), 'benchmarks')]) |
| 89 benchmark = benchmark_runner.GetBenchmarkByName( |
| 90 options.benchmark_name, config) |
| 91 if not benchmark: |
| 92 raise ValueError('No such benchmark: %s' % options.benchmark_name) |
| 93 FetchDepsForBenchmark(benchmark, output) |
| 94 else: |
| 95 if not options.force: |
| 96 raw_input( |
| 97 'No benchmark name is specified. Fetching all benchmark deps. ' |
| 98 'Press enter to continue...') |
| 99 for b in benchmark_finders.GetAllBenchmarks(): |
| 100 print >> output, ('Fetch dependencies for benchmark %s:' |
| 101 % benchmark.Name()) |
| 102 FetchDepsForBenchmark(b, output) |
| 103 |
| 86 if __name__ == '__main__': | 104 if __name__ == '__main__': |
| 87 if len(sys.argv) != 2 or sys.argv[1][0] == '-': | 105 main(sys.argv[1:], sys.stdout) |
| 88 _show_usage() | |
| 89 else: | |
| 90 main() | |
| OLD | NEW |