OLD | NEW |
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Functions specific to handle goma related info. | 5 """Functions specific to handle goma related info. |
6 """ | 6 """ |
7 | 7 |
8 import base64 | 8 import base64 |
9 import datetime | 9 import datetime |
10 import getpass | 10 import getpass |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 def GetLatestGomaCompilerProxyInfo(): | 71 def GetLatestGomaCompilerProxyInfo(): |
72 """Get a filename of the latest goma comiler_proxy.INFO.""" | 72 """Get a filename of the latest goma comiler_proxy.INFO.""" |
73 return GetLatestGlogInfoFile('compiler_proxy') | 73 return GetLatestGlogInfoFile('compiler_proxy') |
74 | 74 |
75 | 75 |
76 def GetLatestGomaCompilerProxySubprocInfo(): | 76 def GetLatestGomaCompilerProxySubprocInfo(): |
77 """Get a filename of the latest goma comiler_proxy-subproc.INFO.""" | 77 """Get a filename of the latest goma comiler_proxy-subproc.INFO.""" |
78 return GetLatestGlogInfoFile('compiler_proxy-subproc') | 78 return GetLatestGlogInfoFile('compiler_proxy-subproc') |
79 | 79 |
80 | 80 |
81 def UploadToGomaLogGS(file_path, gs_filename, text_to_append=None): | 81 def UploadToGomaLogGS( |
| 82 file_path, gs_filename, text_to_append=None, override_gsutil=None): |
82 """Upload a file to Google Cloud Storage (gs://chrome-goma-log). | 83 """Upload a file to Google Cloud Storage (gs://chrome-goma-log). |
83 | 84 |
84 Note that the uploaded file would automatically be gzip compressed. | 85 Note that the uploaded file would automatically be gzip compressed. |
85 | 86 |
86 Args: | 87 Args: |
87 file_path: a path of a file to be uploaded. | 88 file_path: a path of a file to be uploaded. |
88 gs_filename: a name of a file in Google Storage. | 89 gs_filename: a name of a file in Google Storage. |
89 text_to_append: an addtional text to be added to a file in GS. | 90 text_to_append: an addtional text to be added to a file in GS. |
90 | 91 |
91 Returns: | 92 Returns: |
92 a stored path name without the bucket name in GS. | 93 a stored path name without the bucket name in GS. |
93 """ | 94 """ |
94 hostname = GetShortHostname() | 95 hostname = GetShortHostname() |
95 today = datetime.datetime.utcnow().date() | 96 today = datetime.datetime.utcnow().date() |
96 log_path = '%s/%s/%s.gz' % ( | 97 log_path = '%s/%s/%s.gz' % ( |
97 today.strftime('%Y/%m/%d'), hostname, gs_filename) | 98 today.strftime('%Y/%m/%d'), hostname, gs_filename) |
98 gs_path = 'gs://%s/%s' % (GOMA_LOG_GS_BUCKET, log_path) | 99 gs_path = 'gs://%s/%s' % (GOMA_LOG_GS_BUCKET, log_path) |
99 temp = tempfile.NamedTemporaryFile(delete=False) | 100 temp = tempfile.NamedTemporaryFile(delete=False) |
100 try: | 101 try: |
101 with temp as f_out: | 102 with temp as f_out: |
102 with gzip.GzipFile(fileobj=f_out) as gzipf_out: | 103 with gzip.GzipFile(fileobj=f_out) as gzipf_out: |
103 with open(file_path) as f_in: | 104 with open(file_path) as f_in: |
104 shutil.copyfileobj(f_in, gzipf_out) | 105 shutil.copyfileobj(f_in, gzipf_out) |
105 if text_to_append: | 106 if text_to_append: |
106 gzipf_out.write(text_to_append) | 107 gzipf_out.write(text_to_append) |
107 slave_utils.GSUtilCopy(temp.name, gs_path) | 108 slave_utils.GSUtilCopy(temp.name, gs_path, override_gsutil=override_gsutil) |
108 print "Copied log file to %s" % gs_path | 109 print "Copied log file to %s" % gs_path |
109 finally: | 110 finally: |
110 os.remove(temp.name) | 111 os.remove(temp.name) |
111 return log_path | 112 return log_path |
112 | 113 |
113 | 114 |
114 def UploadGomaCompilerProxyInfo(): | 115 def UploadGomaCompilerProxyInfo(override_gsutil=None): |
115 """Upload goma compiler_proxy.INFO to Google Storage.""" | 116 """Upload goma compiler_proxy.INFO to Google Storage.""" |
116 latest_subproc_info = GetLatestGomaCompilerProxySubprocInfo() | 117 latest_subproc_info = GetLatestGomaCompilerProxySubprocInfo() |
117 if latest_subproc_info: | 118 if latest_subproc_info: |
118 UploadToGomaLogGS(latest_subproc_info, | 119 UploadToGomaLogGS(latest_subproc_info, |
119 os.path.basename(latest_subproc_info)) | 120 os.path.basename(latest_subproc_info)) |
120 else: | 121 else: |
121 print 'No compiler_proxy-subproc.INFO to upload' | 122 print 'No compiler_proxy-subproc.INFO to upload' |
122 latest_info = GetLatestGomaCompilerProxyInfo() | 123 latest_info = GetLatestGomaCompilerProxyInfo() |
123 if not latest_info: | 124 if not latest_info: |
124 print 'No compiler_proxy.INFO to upload' | 125 print 'No compiler_proxy.INFO to upload' |
125 return | 126 return |
126 # Since a filename of compiler_proxy.INFO is fairly unique, | 127 # Since a filename of compiler_proxy.INFO is fairly unique, |
127 # we might be able to upload it as-is. | 128 # we might be able to upload it as-is. |
128 log_path = UploadToGomaLogGS(latest_info, os.path.basename(latest_info)) | 129 log_path = UploadToGomaLogGS( |
| 130 latest_info, os.path.basename(latest_info), |
| 131 override_gsutil=override_gsutil) |
129 viewer_url = ('http://chromium-build-stats.appspot.com/compiler_proxy_log/' | 132 viewer_url = ('http://chromium-build-stats.appspot.com/compiler_proxy_log/' |
130 + log_path) | 133 + log_path) |
131 print 'Visualization at %s' % viewer_url | 134 print 'Visualization at %s' % viewer_url |
132 | 135 |
133 | 136 |
134 def UploadNinjaLog(outdir, compiler, command, exit_status): | 137 def UploadNinjaLog( |
| 138 outdir, compiler, command, exit_status, override_gsutil=None): |
135 """Upload .ninja_log to Google Cloud Storage (gs://chrome-goma-log), | 139 """Upload .ninja_log to Google Cloud Storage (gs://chrome-goma-log), |
136 in the same folder with goma's compiler_proxy.INFO. | 140 in the same folder with goma's compiler_proxy.INFO. |
137 | 141 |
138 Args: | 142 Args: |
139 outdir: a directory that contains .ninja_log. | 143 outdir: a directory that contains .ninja_log. |
140 compiler: compiler used for the build. | 144 compiler: compiler used for the build. |
141 command: command line. | 145 command: command line. |
142 exit_status: ninja's exit status. | 146 exit_status: ninja's exit status. |
143 """ | 147 """ |
144 ninja_log_path = os.path.join(outdir, '.ninja_log') | 148 ninja_log_path = os.path.join(outdir, '.ninja_log') |
(...skipping 21 matching lines...) Expand all Loading... |
166 if compiler_proxy_info: | 170 if compiler_proxy_info: |
167 info['compiler_proxy_info'] = compiler_proxy_info | 171 info['compiler_proxy_info'] = compiler_proxy_info |
168 | 172 |
169 username = getpass.getuser() | 173 username = getpass.getuser() |
170 hostname = GetShortHostname() | 174 hostname = GetShortHostname() |
171 pid = os.getpid() | 175 pid = os.getpid() |
172 ninja_log_filename = 'ninja_log.%s.%s.%s.%d' % ( | 176 ninja_log_filename = 'ninja_log.%s.%s.%s.%d' % ( |
173 hostname, username, mtime.strftime('%Y%m%d-%H%M%S'), pid) | 177 hostname, username, mtime.strftime('%Y%m%d-%H%M%S'), pid) |
174 additional_text = '# end of ninja log\n' + json.dumps(info) | 178 additional_text = '# end of ninja log\n' + json.dumps(info) |
175 log_path = UploadToGomaLogGS( | 179 log_path = UploadToGomaLogGS( |
176 ninja_log_path, ninja_log_filename, additional_text) | 180 ninja_log_path, ninja_log_filename, additional_text, |
| 181 override_gsutil=override_gsutil) |
177 viewer_url = 'http://chromium-build-stats.appspot.com/ninja_log/' + log_path | 182 viewer_url = 'http://chromium-build-stats.appspot.com/ninja_log/' + log_path |
178 print 'Visualization at %s' % viewer_url | 183 print 'Visualization at %s' % viewer_url |
179 | 184 |
180 | 185 |
181 def IsCompilerProxyKilledByFatalError(): | 186 def IsCompilerProxyKilledByFatalError(): |
182 """Returns true if goma compiler_proxy is killed by CHECK or LOG(FATAL).""" | 187 """Returns true if goma compiler_proxy is killed by CHECK or LOG(FATAL).""" |
183 info_file = GetLatestGomaCompilerProxyInfo() | 188 info_file = GetLatestGomaCompilerProxyInfo() |
184 if not info_file: | 189 if not info_file: |
185 return False | 190 return False |
186 fatal_pattern = re.compile(r'^F\d{4} \d{2}:\d{2}:\d{2}\.\d{6} ') | 191 fatal_pattern = re.compile(r'^F\d{4} \d{2}:\d{2}:\d{2}\.\d{6} ') |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 retcode = chromium_utils.RunCommand( | 347 retcode = chromium_utils.RunCommand( |
343 cmd, filter_obj=cmd_filter, | 348 cmd, filter_obj=cmd_filter, |
344 max_time=30) | 349 max_time=30) |
345 if retcode: | 350 if retcode: |
346 print('Execution of send_ts_mon_values failed with code %s' | 351 print('Execution of send_ts_mon_values failed with code %s' |
347 % retcode) | 352 % retcode) |
348 print '\n'.join(cmd_filter.text) | 353 print '\n'.join(cmd_filter.text) |
349 | 354 |
350 except Exception as ex: | 355 except Exception as ex: |
351 print('error while sending ts mon json_file=%s: %s' % (json_file, ex)) | 356 print('error while sending ts mon json_file=%s: %s' % (json_file, ex)) |
OLD | NEW |