| 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 """ Upload benchmark performance data results. """ | |
| 7 | |
| 8 from build_step import BuildStep | |
| 9 from utils import sync_bucket_subdir | |
| 10 from utils import old_gs_utils as gs_utils | |
| 11 | |
| 12 import gzip | |
| 13 import os | |
| 14 import os.path | |
| 15 import re | |
| 16 import sys | |
| 17 import tempfile | |
| 18 from datetime import datetime | |
| 19 | |
| 20 | |
| 21 class UploadBenchResults(BuildStep): | |
| 22 | |
| 23 def __init__(self, attempts=5, **kwargs): | |
| 24 super(UploadBenchResults, self).__init__(attempts=attempts, **kwargs) | |
| 25 | |
| 26 def _UploadJSONResults(self, dest_gsbase, gs_subdir, full_json_path, | |
| 27 gzipped=False): | |
| 28 now = datetime.utcnow() | |
| 29 gs_json_path = '/'.join((str(now.year).zfill(4), str(now.month).zfill(2), | |
| 30 str(now.day).zfill(2), str(now.hour).zfill(2))) | |
| 31 gs_dir = '/'.join((gs_subdir, gs_json_path, self._builder_name)) | |
| 32 if self._is_try: | |
| 33 if (not self._args.get('issue_number') or | |
| 34 self._args['issue_number'] == 'None'): | |
| 35 raise Exception('issue_number build property is missing!') | |
| 36 gs_dir = '/'.join(('trybot', gs_dir, self._build_number, | |
| 37 self._args['issue_number'])) | |
| 38 full_path_to_upload = full_json_path | |
| 39 file_to_upload = os.path.basename(full_path_to_upload) | |
| 40 http_header = ['Content-Type:application/json'] | |
| 41 if gzipped: | |
| 42 http_header.append('Content-Encoding:gzip') | |
| 43 gzipped_file = os.path.join(tempfile.gettempdir(), file_to_upload) | |
| 44 # Apply gzip. | |
| 45 with open(full_path_to_upload, 'rb') as f_in: | |
| 46 with gzip.open(gzipped_file, 'wb') as f_out: | |
| 47 f_out.writelines(f_in) | |
| 48 full_path_to_upload = gzipped_file | |
| 49 #TODO(bensong): switch to new gs_utils once it supports http headers. | |
| 50 gs_utils.upload_file( | |
| 51 full_path_to_upload, | |
| 52 '/'.join((dest_gsbase, gs_dir, file_to_upload)), | |
| 53 gs_acl='public-read', | |
| 54 http_header_lines=http_header) | |
| 55 | |
| 56 def _RunNanoBenchJSONUpload(self, dest_gsbase): | |
| 57 """Uploads gzipped nanobench JSON data.""" | |
| 58 # Find the nanobench JSON | |
| 59 file_list = os.listdir(self._perf_data_dir) | |
| 60 RE_FILE_SEARCH = re.compile( | |
| 61 'nanobench_({})_[0-9]+\.json'.format(self._got_revision)) | |
| 62 nanobench_name = None | |
| 63 | |
| 64 for file_name in file_list: | |
| 65 if RE_FILE_SEARCH.search(file_name): | |
| 66 nanobench_name = file_name | |
| 67 break | |
| 68 | |
| 69 if nanobench_name: | |
| 70 nanobench_json_file = os.path.join(self._perf_data_dir, | |
| 71 nanobench_name) | |
| 72 | |
| 73 self._UploadJSONResults(dest_gsbase, 'nano-json-v1', nanobench_json_file, | |
| 74 gzipped=True) | |
| 75 | |
| 76 def _Run(self): | |
| 77 dest_gsbase = (self._args.get('dest_gsbase') or | |
| 78 sync_bucket_subdir.DEFAULT_PERFDATA_GS_BASE) | |
| 79 self._RunNanoBenchJSONUpload(dest_gsbase) | |
| 80 | |
| 81 | |
| 82 if '__main__' == __name__: | |
| 83 sys.exit(BuildStep.RunBuildStep(UploadBenchResults)) | |
| OLD | NEW |