Index: scripts/slave/archive_profiling_data.py |
=================================================================== |
--- scripts/slave/archive_profiling_data.py (revision 0) |
+++ scripts/slave/archive_profiling_data.py (revision 0) |
@@ -0,0 +1,94 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""A tool to archive Chrome profiling data generated by perf buildbots. |
+ |
+Pushes generated profiling data to Google Storage. |
+ |
+For a list of command-line options, call this script with '--help'. |
+""" |
+ |
+ |
+import optparse |
+import os |
+import re |
+import sys |
+ |
+from slave import slave_utils |
+ |
+FILENAME = 'task_profile.json' |
+GOOGLE_STORAGE_BUCKET = 'chromium-browser-profiling-data' |
+ |
+ |
+def CopyToGoogleStorage(src, dst): |
+ """Copies a file to the given Google Storage destination url. |
+ |
+ Args: |
+ src: path to file to be copied |
+ dst: Google Storage destination url (i.e., gs://...) |
+ Returns: |
+ whether the copy was successful |
+ """ |
+ if not os.path.exists(src): |
+ print 'No such file', src |
+ return False |
+ return slave_utils.GSUtilCopy(src, dst, None, 'public-read') |
+ |
+ |
+def Archive(run_id, build_dir): |
+ """Archive the profiling data to Google Storage. |
+ |
+ Args: |
+ run_id: the unique identifier of this run |
+ build_dir: the path to the build directory |
+ Returns: |
+ whether profiling data correctly uploaded or not |
+ """ |
+ if not os.path.exists(build_dir): |
+ print 'No build directory' |
+ return True |
+ |
+ # Profiling data is in /b/build/slave/SLAVE_NAME/build/src/chrome/test/data |
+ profiling_data_dir = os.path.join(build_dir, 'src', 'chrome', 'test', 'data') |
+ if not os.path.exists(profiling_data_dir): |
+ print 'No profiling_data_dir: ', profiling_data_dir |
+ return True |
+ |
+ profiling_file = os.path.join(profiling_data_dir, 'task_profile.json') |
+ if not os.path.exists(profiling_file): |
+ print 'No profiling_file: ', profiling_file |
+ return True |
+ |
+ run_id = re.sub('\W+', '_', run_id) |
+ |
+ view_url = 'http://%s.commondatastorage.googleapis.com/' \ |
+ 'view_test_results.html?%s' % (GOOGLE_STORAGE_BUCKET, run_id) |
+ print 'See %s for this run\'s test results' % view_url |
+ run_url = 'gs://%s/runs/%s/' % (GOOGLE_STORAGE_BUCKET, run_id) |
+ print 'Pushing results to %s...' % run_url |
+ |
+ if not CopyToGoogleStorage(profiling_file, run_url + FILENAME): |
+ return False |
+ return True |
+ |
+ |
+def main(): |
+ option_parser = optparse.OptionParser() |
+ option_parser.add_option('', '--run-id', default=None, |
+ help='unique id for this run') |
+ option_parser.add_option('', '--build-dir', default=None, |
+ help=('path to the build directory')) |
+ options = option_parser.parse_args()[0] |
+ if (options.run_id is None or options.build_dir is None): |
+ print 'All command options are required. Use --help.' |
+ return 1 |
+ |
+ if Archive(options.run_id, options.build_dir): |
+ return 0 |
+ return 2 |
+ |
+ |
+if '__main__' == __name__: |
+ sys.exit(main()) |