Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: scripts/slave/goma_utils.py

Issue 2302453004: Add buildbot metadata to compiler_proxy log (Closed)
Patch Set: Use cloud storage metadata Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « scripts/slave/compile.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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( 81 def UploadToGomaLogGS(file_path, gs_filename,
82 file_path, gs_filename, text_to_append=None, override_gsutil=None): 82 text_to_append=None,
83 metadata=None,
84 override_gsutil=None):
83 """Upload a file to Google Cloud Storage (gs://chrome-goma-log). 85 """Upload a file to Google Cloud Storage (gs://chrome-goma-log).
84 86
85 Note that the uploaded file would automatically be gzip compressed. 87 Note that the uploaded file would automatically be gzip compressed.
86 88
87 Args: 89 Args:
88 file_path: a path of a file to be uploaded. 90 file_path: a path of a file to be uploaded.
89 gs_filename: a name of a file in Google Storage. 91 gs_filename: a name of a file in Google Storage.
92 metadata: (dict) A dictionary of string key/value metadata entries.
90 text_to_append: an addtional text to be added to a file in GS. 93 text_to_append: an addtional text to be added to a file in GS.
91 94
92 Returns: 95 Returns:
93 a stored path name without the bucket name in GS. 96 a stored path name without the bucket name in GS.
94 """ 97 """
95 hostname = GetShortHostname() 98 hostname = GetShortHostname()
96 today = datetime.datetime.utcnow().date() 99 today = datetime.datetime.utcnow().date()
97 log_path = '%s/%s/%s.gz' % ( 100 log_path = '%s/%s/%s.gz' % (
98 today.strftime('%Y/%m/%d'), hostname, gs_filename) 101 today.strftime('%Y/%m/%d'), hostname, gs_filename)
99 gs_path = 'gs://%s/%s' % (GOMA_LOG_GS_BUCKET, log_path) 102 gs_path = 'gs://%s/%s' % (GOMA_LOG_GS_BUCKET, log_path)
100 temp = tempfile.NamedTemporaryFile(delete=False) 103 temp = tempfile.NamedTemporaryFile(delete=False)
101 try: 104 try:
102 with temp as f_out: 105 with temp as f_out:
103 with gzip.GzipFile(fileobj=f_out) as gzipf_out: 106 with gzip.GzipFile(fileobj=f_out) as gzipf_out:
104 with open(file_path) as f_in: 107 with open(file_path) as f_in:
105 shutil.copyfileobj(f_in, gzipf_out) 108 shutil.copyfileobj(f_in, gzipf_out)
106 if text_to_append: 109 if text_to_append:
107 gzipf_out.write(text_to_append) 110 gzipf_out.write(text_to_append)
108 slave_utils.GSUtilCopy(temp.name, gs_path, override_gsutil=override_gsutil) 111 slave_utils.GSUtilCopy(temp.name, gs_path,
112 metadata=metadata, override_gsutil=override_gsutil)
109 print "Copied log file to %s" % gs_path 113 print "Copied log file to %s" % gs_path
110 finally: 114 finally:
111 os.remove(temp.name) 115 os.remove(temp.name)
112 return log_path 116 return log_path
113 117
114 118
115 def UploadGomaCompilerProxyInfo(override_gsutil=None): 119 def UploadGomaCompilerProxyInfo(override_gsutil=None, builder='unknown', master= 'unknown',
120 slave='unknown', clobber=''):
116 """Upload goma compiler_proxy.INFO to Google Storage.""" 121 """Upload goma compiler_proxy.INFO to Google Storage."""
117 latest_subproc_info = GetLatestGomaCompilerProxySubprocInfo() 122 latest_subproc_info = GetLatestGomaCompilerProxySubprocInfo()
123
124 metadata = {
Yoshisato Yanagisawa 2016/09/05 08:01:39 I thought you encode metadata with gzip+base64 and
shinyak 2016/09/06 02:30:33 Hmm, I'm OK with gzip. these name could be too gen
shinyak 2016/09/06 02:36:36 Since this is small, I feel it's ok to save as jso
Yoshisato Yanagisawa 2016/09/06 02:50:50 Other reviewers may think the other things but I f
shinyak 2016/09/06 02:59:22 Since this runs with python subprocess.Popen (fina
125 'builder': builder,
126 'master': master,
127 'slave': slave,
128 'clobber': '1' if clobber else '0',
129 'os': chromium_utils.PlatformName(),
130 }
131
118 if latest_subproc_info: 132 if latest_subproc_info:
119 UploadToGomaLogGS(latest_subproc_info, 133 UploadToGomaLogGS(latest_subproc_info,
120 os.path.basename(latest_subproc_info), 134 os.path.basename(latest_subproc_info),
135 metadata=metadata,
121 override_gsutil=override_gsutil) 136 override_gsutil=override_gsutil)
122 else: 137 else:
123 print 'No compiler_proxy-subproc.INFO to upload' 138 print 'No compiler_proxy-subproc.INFO to upload'
124 latest_info = GetLatestGomaCompilerProxyInfo() 139 latest_info = GetLatestGomaCompilerProxyInfo()
125 if not latest_info: 140 if not latest_info:
126 print 'No compiler_proxy.INFO to upload' 141 print 'No compiler_proxy.INFO to upload'
127 return 142 return
128 # Since a filename of compiler_proxy.INFO is fairly unique, 143 # Since a filename of compiler_proxy.INFO is fairly unique,
129 # we might be able to upload it as-is. 144 # we might be able to upload it as-is.
130 log_path = UploadToGomaLogGS( 145 log_path = UploadToGomaLogGS(
131 latest_info, os.path.basename(latest_info), 146 latest_info, os.path.basename(latest_info),
147 metadata=metadata,
132 override_gsutil=override_gsutil) 148 override_gsutil=override_gsutil)
133 viewer_url = ('http://chromium-build-stats.appspot.com/compiler_proxy_log/' 149 viewer_url = ('http://chromium-build-stats.appspot.com/compiler_proxy_log/'
134 + log_path) 150 + log_path)
135 print 'Visualization at %s' % viewer_url 151 print 'Visualization at %s' % viewer_url
136 152
137 153
138 def UploadNinjaLog( 154 def UploadNinjaLog(
139 outdir, compiler, command, exit_status, override_gsutil=None): 155 outdir, compiler, command, exit_status, override_gsutil=None):
140 """Upload .ninja_log to Google Cloud Storage (gs://chrome-goma-log), 156 """Upload .ninja_log to Google Cloud Storage (gs://chrome-goma-log),
141 in the same folder with goma's compiler_proxy.INFO. 157 in the same folder with goma's compiler_proxy.INFO.
(...skipping 29 matching lines...) Expand all
171 if compiler_proxy_info: 187 if compiler_proxy_info:
172 info['compiler_proxy_info'] = compiler_proxy_info 188 info['compiler_proxy_info'] = compiler_proxy_info
173 189
174 username = getpass.getuser() 190 username = getpass.getuser()
175 hostname = GetShortHostname() 191 hostname = GetShortHostname()
176 pid = os.getpid() 192 pid = os.getpid()
177 ninja_log_filename = 'ninja_log.%s.%s.%s.%d' % ( 193 ninja_log_filename = 'ninja_log.%s.%s.%s.%d' % (
178 hostname, username, mtime.strftime('%Y%m%d-%H%M%S'), pid) 194 hostname, username, mtime.strftime('%Y%m%d-%H%M%S'), pid)
179 additional_text = '# end of ninja log\n' + json.dumps(info) 195 additional_text = '# end of ninja log\n' + json.dumps(info)
180 log_path = UploadToGomaLogGS( 196 log_path = UploadToGomaLogGS(
181 ninja_log_path, ninja_log_filename, additional_text, 197 ninja_log_path, ninja_log_filename, text_to_append=additional_text,
182 override_gsutil=override_gsutil) 198 override_gsutil=override_gsutil)
183 viewer_url = 'http://chromium-build-stats.appspot.com/ninja_log/' + log_path 199 viewer_url = 'http://chromium-build-stats.appspot.com/ninja_log/' + log_path
184 print 'Visualization at %s' % viewer_url 200 print 'Visualization at %s' % viewer_url
185 201
186 202
187 def IsCompilerProxyKilledByFatalError(): 203 def IsCompilerProxyKilledByFatalError():
188 """Returns true if goma compiler_proxy is killed by CHECK or LOG(FATAL).""" 204 """Returns true if goma compiler_proxy is killed by CHECK or LOG(FATAL)."""
189 info_file = GetLatestGomaCompilerProxyInfo() 205 info_file = GetLatestGomaCompilerProxyInfo()
190 if not info_file: 206 if not info_file:
191 return False 207 return False
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 retcode = chromium_utils.RunCommand( 362 retcode = chromium_utils.RunCommand(
347 cmd, filter_obj=cmd_filter, 363 cmd, filter_obj=cmd_filter,
348 max_time=30) 364 max_time=30)
349 if retcode: 365 if retcode:
350 print('Execution of send_ts_mon_values failed with code %s' 366 print('Execution of send_ts_mon_values failed with code %s'
351 % retcode) 367 % retcode)
352 print '\n'.join(cmd_filter.text) 368 print '\n'.join(cmd_filter.text)
353 369
354 except Exception as ex: 370 except Exception as ex:
355 print('error while sending ts mon json_file=%s: %s' % (json_file, ex)) 371 print('error while sending ts mon json_file=%s: %s' % (json_file, ex))
OLDNEW
« no previous file with comments | « scripts/slave/compile.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698