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