| 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 os | 8 import os |
| 9 import sys | 9 import sys |
| 10 | 10 |
| 11 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'telemetry')) | 11 from core import path_util |
| 12 |
| 13 sys.path.insert(1, path_util.GetTelemetryDir()) |
| 12 | 14 |
| 13 from catapult_base import cloud_storage | 15 from catapult_base import cloud_storage |
| 14 from telemetry import benchmark_runner | 16 from telemetry import benchmark_runner |
| 15 | 17 |
| 16 | 18 |
| 17 def _GetPerfDir(*subdirs): | |
| 18 perf_dir = os.path.realpath(os.path.dirname(__file__)) | |
| 19 return os.path.join(perf_dir, *subdirs) | |
| 20 | |
| 21 | |
| 22 def GetChromiumDir(): | |
| 23 return _GetPerfDir(os.path.pardir, os.path.pardir, os.path.pardir) | |
| 24 | |
| 25 | |
| 26 def _FetchDependenciesIfNeeded(story_set): | 19 def _FetchDependenciesIfNeeded(story_set): |
| 27 """ Download files needed by a user story set. """ | 20 """ Download files needed by a user story set. """ |
| 28 # Download files in serving_dirs. | 21 # Download files in serving_dirs. |
| 29 serving_dirs = story_set.serving_dirs | 22 serving_dirs = story_set.serving_dirs |
| 30 for directory in serving_dirs: | 23 for directory in serving_dirs: |
| 31 cloud_storage.GetFilesInDirectoryIfChanged(directory, story_set.bucket) | 24 cloud_storage.GetFilesInDirectoryIfChanged(directory, story_set.bucket) |
| 32 | 25 |
| 33 # Download WPR files. | 26 # Download WPR files. |
| 34 if any(not story.is_local for story in story_set): | 27 if any(not story.is_local for story in story_set): |
| 35 story_set.wpr_archive_info.DownloadArchivesIfNeeded() | 28 story_set.wpr_archive_info.DownloadArchivesIfNeeded() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 if directory == os.path.abspath(os.sep): | 43 if directory == os.path.abspath(os.sep): |
| 51 raise ValueError('Trying to serve root directory from HTTP server.') | 44 raise ValueError('Trying to serve root directory from HTTP server.') |
| 52 for dirpath, _, filenames in os.walk(directory): | 45 for dirpath, _, filenames in os.walk(directory): |
| 53 for filename in filenames: | 46 for filename in filenames: |
| 54 path_name, extension = os.path.splitext( | 47 path_name, extension = os.path.splitext( |
| 55 os.path.join(dirpath, filename)) | 48 os.path.join(dirpath, filename)) |
| 56 if extension == '.sha1': | 49 if extension == '.sha1': |
| 57 deps.add(path_name) | 50 deps.add(path_name) |
| 58 | 51 |
| 59 # Return relative paths. | 52 # Return relative paths. |
| 60 prefix_len = len(os.path.realpath(GetChromiumDir())) + 1 | 53 prefix_len = len(os.path.realpath(path_util.GetChromiumSrcDir())) + 1 |
| 61 return [dep[prefix_len:] for dep in deps if dep] | 54 return [dep[prefix_len:] for dep in deps if dep] |
| 62 | 55 |
| 63 | 56 |
| 64 def _show_usage(): | 57 def _show_usage(): |
| 65 print ('Usage: %s benchmark_name\n' | 58 print ('Usage: %s benchmark_name\n' |
| 66 'Fetch the dependencies of benchmark_name.' % sys.argv[0]) | 59 'Fetch the dependencies of benchmark_name.' % sys.argv[0]) |
| 67 | 60 |
| 68 | 61 |
| 69 def main(output=sys.stdout): | 62 def main(output=sys.stdout): |
| 70 config = benchmark_runner.ProjectConfig( | 63 config = benchmark_runner.ProjectConfig( |
| 71 top_level_dir=_GetPerfDir(), | 64 top_level_dir=path_util.GetPerfDir(), |
| 72 benchmark_dirs=[_GetPerfDir('benchmarks')]) | 65 benchmark_dirs=[path_util.GetPerfBenchmarksDir()], |
| 66 client_config=path_util.GetPerfClientConfigPath()) |
| 73 | 67 |
| 74 name = sys.argv[1] | 68 name = sys.argv[1] |
| 75 benchmark = benchmark_runner.GetBenchmarkByName(name, config) | 69 benchmark = benchmark_runner.GetBenchmarkByName(name, config) |
| 76 if not benchmark: | 70 if not benchmark: |
| 77 raise ValueError('No such benchmark: %s' % name) | 71 raise ValueError('No such benchmark: %s' % name) |
| 78 | 72 |
| 79 # Download files according to specified benchmark. | 73 # Download files according to specified benchmark. |
| 80 story_set = benchmark().CreateStorySet(None) | 74 story_set = benchmark().CreateStorySet(None) |
| 81 | 75 |
| 82 _FetchDependenciesIfNeeded(story_set) | 76 _FetchDependenciesIfNeeded(story_set) |
| 83 | 77 |
| 84 # Print files downloaded. | 78 # Print files downloaded. |
| 85 deps = _EnumerateDependencies(story_set) | 79 deps = _EnumerateDependencies(story_set) |
| 86 for dep in deps: | 80 for dep in deps: |
| 87 print >> output, dep | 81 print >> output, dep |
| 88 | 82 |
| 89 | 83 |
| 90 if __name__ == '__main__': | 84 if __name__ == '__main__': |
| 91 if len(sys.argv) != 2 or sys.argv[1][0] == '-': | 85 if len(sys.argv) != 2 or sys.argv[1][0] == '-': |
| 92 _show_usage() | 86 _show_usage() |
| 93 else: | 87 else: |
| 94 main() | 88 main() |
| OLD | NEW |