OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 """A tool to archive Chrome profiling data generated by perf buildbots. |
| 7 |
| 8 Pushes generated profiling data to Google Storage. |
| 9 |
| 10 For a list of command-line options, call this script with '--help'. |
| 11 """ |
| 12 |
| 13 |
| 14 import optparse |
| 15 import os |
| 16 import re |
| 17 import subprocess |
| 18 import sys |
| 19 |
| 20 |
| 21 FILENAME = 'task_profile.json' |
| 22 GOOGLE_STORAGE_BUCKET = 'chromium-browser-profiling-data' |
| 23 |
| 24 |
| 25 def CopyToGoogleStorage(src, dst): |
| 26 """Copies a file to the given Google Storage destination url. |
| 27 |
| 28 Args: |
| 29 src: path to file to be copied |
| 30 dst: Google Storage destination url (i.e., gs://...) |
| 31 Returns: |
| 32 whether the copy was successful |
| 33 """ |
| 34 if not os.path.exists(src): |
| 35 print 'No such file', src |
| 36 return False |
| 37 gsutil = os.environ.get('GSUTIL', 'gsutil') |
| 38 # gsutil will look in the $HOME directory for the config file. |
| 39 # Set $HOME to /b/build/site_config/ temporarily where .boto stays. |
| 40 old_env = os.environ.copy() |
| 41 # This script is under /b/build/scripts/slave/chromium/ |
| 42 os.environ['HOME'] = os.path.join('..', '..', '..', 'site_config') |
| 43 retcode = subprocess.call([gsutil, 'cp', '-a', 'public-read', src, dst]) |
| 44 os.environ = old_env |
| 45 if retcode == 0: |
| 46 return True |
| 47 return False |
| 48 |
| 49 |
| 50 def Archive(run_id, profiling_data_dir): |
| 51 """Archive the profiling data to Google Storage. |
| 52 |
| 53 Args: |
| 54 run_id: the unique identifier of this run |
| 55 profiling_data_dir: the path to the profiling data directory |
| 56 Returns: |
| 57 whether profiling data correctly uploaded or not |
| 58 """ |
| 59 if not os.path.exists(profiling_data_dir): |
| 60 print 'No data directory' |
| 61 return True |
| 62 |
| 63 profiling_file = os.path.join(profiling_data_dir, FILENAME) |
| 64 if not os.path.exists(profiling_file): |
| 65 print 'No profiling data file' |
| 66 return True |
| 67 |
| 68 run_id = re.sub('\W+', '_', run_id) |
| 69 |
| 70 view_url = 'http://%s.commondatastorage.googleapis.com/' \ |
| 71 'view_test_results.html?%s' % (GOOGLE_STORAGE_BUCKET, run_id) |
| 72 print 'See %s for this run\'s test results' % view_url |
| 73 run_url = 'gs://%s/runs/%s/' % (GOOGLE_STORAGE_BUCKET, run_id) |
| 74 print 'Pushing results to %s...' % run_url |
| 75 |
| 76 if not CopyToGoogleStorage(profiling_file, run_url + FILENAME): |
| 77 return False |
| 78 return True |
| 79 |
| 80 |
| 81 def main(): |
| 82 option_parser = optparse.OptionParser() |
| 83 option_parser.add_option('', '--run-id', default=None, |
| 84 help='unique id for this run') |
| 85 option_parser.add_option('', '--profiling-data-dir', default=None, |
| 86 help=('path to the directory holding the profiling' |
| 87 'data')) |
| 88 # --sw-profiling-data-dir is ignored. We keep it here so we don't have to |
| 89 # modify master side script. |
| 90 option_parser.add_option('', '--sw-profiling-data-dir', default=None, |
| 91 help=('path to the directory holding the profiling' |
| 92 'data generated by the software renderer')) |
| 93 options = option_parser.parse_args()[0] |
| 94 if (options.run_id is None or options.profiling_data_dir is None): |
| 95 print 'All command options are required. Use --help.' |
| 96 return 1 |
| 97 |
| 98 if Archive(options.run_id, options.profiling_data_dir): |
| 99 return 0 |
| 100 return 2 |
| 101 |
| 102 |
| 103 if '__main__' == __name__: |
| 104 sys.exit(main()) |
OLD | NEW |