| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 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 """ Upload benchmark performance data results. """ | |
| 7 | |
| 8 import gzip | |
| 9 import os | |
| 10 import os.path | |
| 11 import re | |
| 12 import subprocess | |
| 13 import sys | |
| 14 import tempfile | |
| 15 | |
| 16 from datetime import datetime | |
| 17 | |
| 18 | |
| 19 def _UploadJSONResults(builder_name, build_number, dest_gsbase, gs_subdir, | |
| 20 full_json_path, gzipped=True, gsutil_path='gsutil', | |
| 21 issue_number=None): | |
| 22 now = datetime.utcnow() | |
| 23 gs_json_path = '/'.join((str(now.year).zfill(4), str(now.month).zfill(2), | |
| 24 str(now.day).zfill(2), str(now.hour).zfill(2))) | |
| 25 gs_dir = '/'.join((gs_subdir, gs_json_path, builder_name)) | |
| 26 if builder_name.endswith('-Trybot'): | |
| 27 if not issue_number: | |
| 28 raise Exception('issue_number build property is missing!') | |
| 29 gs_dir = '/'.join(('trybot', gs_dir, build_number, issue_number)) | |
| 30 full_path_to_upload = full_json_path | |
| 31 file_to_upload = os.path.basename(full_path_to_upload) | |
| 32 http_header = ['Content-Type:application/json'] | |
| 33 if gzipped: | |
| 34 http_header.append('Content-Encoding:gzip') | |
| 35 gzipped_file = os.path.join(tempfile.gettempdir(), file_to_upload) | |
| 36 # Apply gzip. | |
| 37 with open(full_path_to_upload, 'rb') as f_in: | |
| 38 with gzip.open(gzipped_file, 'wb') as f_out: | |
| 39 f_out.writelines(f_in) | |
| 40 full_path_to_upload = gzipped_file | |
| 41 cmd = ['python', gsutil_path] | |
| 42 for header in http_header: | |
| 43 cmd.extend(['-h', header]) | |
| 44 cmd.extend(['cp', '-a', 'public-read', full_path_to_upload, | |
| 45 '/'.join((dest_gsbase, gs_dir, file_to_upload))]) | |
| 46 print ' '.join(cmd) | |
| 47 subprocess.check_call(cmd) | |
| 48 | |
| 49 | |
| 50 def main(builder_name, build_number, perf_data_dir, got_revision, gsutil_path, | |
| 51 issue_number=None): | |
| 52 """Uploads gzipped nanobench JSON data.""" | |
| 53 # Find the nanobench JSON | |
| 54 file_list = os.listdir(perf_data_dir) | |
| 55 RE_FILE_SEARCH = re.compile( | |
| 56 'nanobench_({})_[0-9]+\.json'.format(got_revision)) | |
| 57 nanobench_name = None | |
| 58 | |
| 59 for file_name in file_list: | |
| 60 if RE_FILE_SEARCH.search(file_name): | |
| 61 nanobench_name = file_name | |
| 62 break | |
| 63 | |
| 64 if nanobench_name: | |
| 65 dest_gsbase = 'gs://skia-perf' | |
| 66 nanobench_json_file = os.path.join(perf_data_dir, | |
| 67 nanobench_name) | |
| 68 _UploadJSONResults(builder_name, build_number, dest_gsbase, 'nano-json-v1', | |
| 69 nanobench_json_file, gsutil_path=gsutil_path, | |
| 70 issue_number=issue_number) | |
| 71 | |
| 72 | |
| 73 if __name__ == '__main__': | |
| 74 main(*sys.argv[1:]) | |
| 75 | |
| OLD | NEW |