OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 """ Upload benchmark performance data results. """ | 6 """ Upload benchmark performance data results. """ |
7 | 7 |
8 import gzip | 8 import gzip |
9 import os | 9 import os |
10 import os.path | 10 import os.path |
(...skipping 11 matching lines...) Expand all Loading... |
22 now = datetime.utcnow() | 22 now = datetime.utcnow() |
23 gs_json_path = '/'.join((str(now.year).zfill(4), str(now.month).zfill(2), | 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))) | 24 str(now.day).zfill(2), str(now.hour).zfill(2))) |
25 gs_dir = '/'.join((gs_subdir, gs_json_path, builder_name)) | 25 gs_dir = '/'.join((gs_subdir, gs_json_path, builder_name)) |
26 if builder_name.endswith('-Trybot'): | 26 if builder_name.endswith('-Trybot'): |
27 if not issue_number: | 27 if not issue_number: |
28 raise Exception('issue_number build property is missing!') | 28 raise Exception('issue_number build property is missing!') |
29 gs_dir = '/'.join(('trybot', gs_dir, build_number, issue_number)) | 29 gs_dir = '/'.join(('trybot', gs_dir, build_number, issue_number)) |
30 full_path_to_upload = full_json_path | 30 full_path_to_upload = full_json_path |
31 file_to_upload = os.path.basename(full_path_to_upload) | 31 file_to_upload = os.path.basename(full_path_to_upload) |
32 http_header = ['Content-Type:application/json'] | 32 gzip_args = [] |
33 if gzipped: | 33 if gzipped: |
34 http_header.append('Content-Encoding:gzip') | 34 gzip_args = ['-z', 'json'] |
35 gzipped_file = os.path.join(tempfile.gettempdir(), file_to_upload) | 35 cmd = ['python', gsutil_path, 'cp', '-a', 'public-read'] |
36 # Apply gzip. | 36 cmd.extend(gzip_args) |
37 with open(full_path_to_upload, 'rb') as f_in: | 37 cmd.extend([full_path_to_upload, |
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))]) | 38 '/'.join((dest_gsbase, gs_dir, file_to_upload))]) |
46 print ' '.join(cmd) | 39 print ' '.join(cmd) |
47 subprocess.check_call(cmd) | 40 subprocess.check_call(cmd) |
48 | 41 |
49 | 42 |
50 def main(builder_name, build_number, perf_data_dir, got_revision, gsutil_path, | 43 def main(builder_name, build_number, perf_data_dir, got_revision, gsutil_path, |
51 issue_number=None): | 44 issue_number=None): |
52 """Uploads gzipped nanobench JSON data.""" | 45 """Uploads gzipped nanobench JSON data.""" |
53 # Find the nanobench JSON | 46 # Find the nanobench JSON |
54 file_list = os.listdir(perf_data_dir) | 47 file_list = os.listdir(perf_data_dir) |
(...skipping 11 matching lines...) Expand all Loading... |
66 nanobench_json_file = os.path.join(perf_data_dir, | 59 nanobench_json_file = os.path.join(perf_data_dir, |
67 nanobench_name) | 60 nanobench_name) |
68 _UploadJSONResults(builder_name, build_number, dest_gsbase, 'nano-json-v1', | 61 _UploadJSONResults(builder_name, build_number, dest_gsbase, 'nano-json-v1', |
69 nanobench_json_file, gsutil_path=gsutil_path, | 62 nanobench_json_file, gsutil_path=gsutil_path, |
70 issue_number=issue_number) | 63 issue_number=issue_number) |
71 | 64 |
72 | 65 |
73 if __name__ == '__main__': | 66 if __name__ == '__main__': |
74 main(*sys.argv[1:]) | 67 main(*sys.argv[1:]) |
75 | 68 |
OLD | NEW |