Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Upload all debug symbols required for crash reporting purposes. |
| 6 | |
| 7 | This script need only be used to upload release builds symbols or to debug |
| 8 | crashes on non-release builds (in which case try to only upload the symbols |
Mike Frysinger | 02e1e07 | 2013-11-10 22:11:34 -0500 | [diff] [blame] | 9 | for those executables involved). |
| 10 | """ |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 11 | |
Mike Frysinger | a4fa1e8 | 2014-01-15 01:45:56 -0500 | [diff] [blame] | 12 | from __future__ import print_function |
| 13 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 14 | import ctypes |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 15 | import datetime |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 16 | import functools |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 17 | import hashlib |
Mike Frysinger | a4fa1e8 | 2014-01-15 01:45:56 -0500 | [diff] [blame] | 18 | import httplib |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 19 | import multiprocessing |
| 20 | import os |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 21 | import poster |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 22 | import random |
Mike Frysinger | fd35565 | 2014-01-23 02:57:48 -0500 | [diff] [blame] | 23 | import socket |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 24 | import textwrap |
| 25 | import tempfile |
| 26 | import time |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 27 | import urllib2 |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 28 | import urlparse |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 29 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 30 | from chromite.buildbot import constants |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 31 | from chromite.lib import cache |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 32 | from chromite.lib import commandline |
| 33 | from chromite.lib import cros_build_lib |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 34 | from chromite.lib import gs |
| 35 | from chromite.lib import osutils |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 36 | from chromite.lib import parallel |
David James | c93e6a4d | 2014-01-13 11:37:36 -0800 | [diff] [blame] | 37 | from chromite.lib import retry_util |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 38 | from chromite.lib import timeout_util |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 39 | from chromite.scripts import cros_generate_breakpad_symbols |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 40 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 41 | # Needs to be after chromite imports. |
| 42 | # TODO(build): When doing the initial buildbot bootstrap, we won't have any |
| 43 | # other repos available. So ignore isolateserver imports. But buildbot will |
| 44 | # re-exec itself once it has done a full repo sync and then the module will |
| 45 | # be available -- it isn't needed that early. http://crbug.com/341152 |
| 46 | try: |
| 47 | import isolateserver |
| 48 | except ImportError: |
| 49 | isolateserver = None |
| 50 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 51 | |
| 52 | # URLs used for uploading symbols. |
| 53 | OFFICIAL_UPLOAD_URL = 'http://clients2.google.com/cr/symbol' |
| 54 | STAGING_UPLOAD_URL = 'http://clients2.google.com/cr/staging_symbol' |
| 55 | |
| 56 | |
| 57 | # The crash server rejects files that are this big. |
| 58 | CRASH_SERVER_FILE_LIMIT = 350 * 1024 * 1024 |
| 59 | # Give ourselves a little breathing room from what the server expects. |
| 60 | DEFAULT_FILE_LIMIT = CRASH_SERVER_FILE_LIMIT - (10 * 1024 * 1024) |
| 61 | |
| 62 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 63 | # The batch limit when talking to the dedup server. We avoid sending one at a |
| 64 | # time as the round trip overhead will dominate. Conversely, we avoid sending |
| 65 | # all at once so we can start uploading symbols asap -- the symbol server is a |
| 66 | # bit slow and will take longer than anything else. |
| 67 | # TODO: A better algorithm would be adaptive. If we have more than one symbol |
| 68 | # in the upload queue waiting, we could send more symbols to the dedupe server |
| 69 | # at a time. |
| 70 | DEDUPE_LIMIT = 100 |
| 71 | |
| 72 | # How long to wait for the server to respond with the results. Note that the |
| 73 | # larger the limit above, the larger this will need to be. So we give it ~1 |
| 74 | # second per item max. |
| 75 | DEDUPE_TIMEOUT = DEDUPE_LIMIT |
| 76 | |
| 77 | # The unique namespace in the dedupe server that only we use. Helps avoid |
| 78 | # collisions with all the hashed values and unrelated content. |
| 79 | OFFICIAL_DEDUPE_NAMESPACE = 'chromium-os-upload-symbols' |
| 80 | STAGING_DEDUPE_NAMESPACE = '%s-staging' % OFFICIAL_DEDUPE_NAMESPACE |
| 81 | |
| 82 | |
Mike Frysinger | cd78a08 | 2013-06-26 17:13:04 -0400 | [diff] [blame] | 83 | # How long to wait (in seconds) for a single upload to complete. This has |
| 84 | # to allow for symbols that are up to CRASH_SERVER_FILE_LIMIT in size. |
| 85 | UPLOAD_TIMEOUT = 30 * 60 |
| 86 | |
| 87 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 88 | # Sleep for 200ms in between uploads to avoid DoS'ing symbol server. |
| 89 | DEFAULT_SLEEP_DELAY = 0.2 |
| 90 | |
| 91 | |
| 92 | # Number of seconds to wait before retrying an upload. The delay will double |
| 93 | # for each subsequent retry of the same symbol file. |
| 94 | INITIAL_RETRY_DELAY = 1 |
| 95 | |
| 96 | # Allow up to 7 attempts to upload a symbol file (total delay may be |
| 97 | # 1+2+4+8+16+32=63 seconds). |
| 98 | MAX_RETRIES = 6 |
| 99 | |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 100 | # Number of total errors, before uploads are no longer attempted. |
| 101 | # This is used to avoid lots of errors causing unreasonable delays. |
| 102 | # See the related, but independent, error values below. |
| 103 | MAX_TOTAL_ERRORS_FOR_RETRY = 30 |
| 104 | |
| 105 | # A watermark of transient errors which we allow recovery from. If we hit |
| 106 | # errors infrequently, overall we're probably doing fine. For example, if |
| 107 | # we have one failure every 100 passes, then we probably don't want to fail |
| 108 | # right away. But if we hit a string of failures in a row, we want to abort. |
| 109 | # |
| 110 | # The watermark starts at 0 (and can never go below that). When this error |
| 111 | # level is exceeded, we stop uploading. When a failure happens, we add the |
| 112 | # fail adjustment, and when an upload succeeds, we add the pass adjustment. |
| 113 | # We want to penalize failures more so that we ramp up when there is a string |
| 114 | # of them, but then slowly back off as things start working. |
| 115 | # |
| 116 | # A quick example: |
| 117 | # 0.0: Starting point. |
| 118 | # 0.0: Upload works, so add -0.5, and then clamp to 0. |
| 119 | # 1.0: Upload fails, so add 1.0. |
| 120 | # 2.0: Upload fails, so add 1.0. |
| 121 | # 1.5: Upload works, so add -0.5. |
| 122 | # 1.0: Upload works, so add -0.5. |
| 123 | ERROR_WATERMARK = 3.0 |
| 124 | ERROR_ADJUST_FAIL = 1.0 |
| 125 | ERROR_ADJUST_PASS = -0.5 |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 126 | |
| 127 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 128 | def SymUpload(upload_url, sym_item): |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 129 | """Upload a symbol file to a HTTP server |
| 130 | |
| 131 | The upload is a multipart/form-data POST with the following parameters: |
| 132 | code_file: the basename of the module, e.g. "app" |
| 133 | code_identifier: the module file's identifier |
| 134 | debug_file: the basename of the debugging file, e.g. "app" |
| 135 | debug_identifier: the debug file's identifier, usually consisting of |
| 136 | the guid and age embedded in the pdb, e.g. |
| 137 | "11111111BBBB3333DDDD555555555555F" |
| 138 | version: the file version of the module, e.g. "1.2.3.4" |
| 139 | product: HTTP-friendly product name |
| 140 | os: the operating system that the module was built for |
| 141 | cpu: the CPU that the module was built for |
| 142 | symbol_file: the contents of the breakpad-format symbol file |
| 143 | |
| 144 | Args: |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 145 | upload_url: The crash URL to POST the |sym_file| to |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 146 | sym_item: A SymbolItem containing the path to the breakpad symbol to upload |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 147 | """ |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 148 | sym_header = sym_item.sym_header |
| 149 | sym_file = sym_item.sym_file |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 150 | |
| 151 | fields = ( |
| 152 | ('code_file', sym_header.name), |
| 153 | ('debug_file', sym_header.name), |
| 154 | ('debug_identifier', sym_header.id.replace('-', '')), |
Mike Frysinger | b8a966b | 2014-03-19 17:36:18 -0400 | [diff] [blame] | 155 | # The product/version fields are used by the server only for statistic |
| 156 | # purposes. They do not impact symbolization, so they're safe to set |
| 157 | # to any value all the time. |
| 158 | # In this case, we use it to help see the load our build system is |
| 159 | # placing on the server. |
| 160 | # Not sure what to set for the version. Maybe the git sha1 of this file. |
| 161 | # Note: the server restricts this to 30 chars. |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 162 | #('version', None), |
Mike Frysinger | b8a966b | 2014-03-19 17:36:18 -0400 | [diff] [blame] | 163 | ('product', 'ChromeOS'), |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 164 | ('os', sym_header.os), |
| 165 | ('cpu', sym_header.cpu), |
| 166 | poster.encode.MultipartParam.from_file('symbol_file', sym_file), |
| 167 | ) |
| 168 | |
| 169 | data, headers = poster.encode.multipart_encode(fields) |
| 170 | request = urllib2.Request(upload_url, data, headers) |
| 171 | request.add_header('User-agent', 'chromite.upload_symbols') |
| 172 | urllib2.urlopen(request, timeout=UPLOAD_TIMEOUT) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 173 | |
| 174 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 175 | def TestingSymUpload(upload_url, sym_item): |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 176 | """A stub version of SymUpload for --testing usage""" |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 177 | cmd = ['sym_upload', sym_item.sym_file, upload_url] |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 178 | # Randomly fail 80% of the time (the retry logic makes this 80%/3 per file). |
| 179 | returncode = random.randint(1, 100) <= 80 |
| 180 | cros_build_lib.Debug('would run (and return %i): %s', returncode, |
Matt Tennant | 7feda35 | 2013-12-20 14:03:40 -0800 | [diff] [blame] | 181 | cros_build_lib.CmdToStr(cmd)) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 182 | if returncode: |
| 183 | output = 'Failed to send the symbol file.' |
| 184 | else: |
| 185 | output = 'Successfully sent the symbol file.' |
| 186 | result = cros_build_lib.CommandResult(cmd=cmd, error=None, output=output, |
| 187 | returncode=returncode) |
| 188 | if returncode: |
Mike Frysinger | a4fa1e8 | 2014-01-15 01:45:56 -0500 | [diff] [blame] | 189 | exceptions = ( |
Mike Frysinger | fd35565 | 2014-01-23 02:57:48 -0500 | [diff] [blame] | 190 | socket.error('[socket.error] forced test fail'), |
Mike Frysinger | a4fa1e8 | 2014-01-15 01:45:56 -0500 | [diff] [blame] | 191 | httplib.BadStatusLine('[BadStatusLine] forced test fail'), |
| 192 | urllib2.HTTPError(upload_url, 400, '[HTTPError] forced test fail', |
| 193 | {}, None), |
| 194 | urllib2.URLError('[URLError] forced test fail'), |
| 195 | ) |
| 196 | raise random.choice(exceptions) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 197 | else: |
| 198 | return result |
| 199 | |
| 200 | |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 201 | def ErrorLimitHit(num_errors, watermark_errors): |
| 202 | """See if our error limit has been hit |
| 203 | |
| 204 | Args: |
| 205 | num_errors: A multiprocessing.Value of the raw number of failures. |
| 206 | watermark_errors: A multiprocessing.Value of the current rate of failures. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 207 | |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 208 | Returns: |
| 209 | True if our error limits have been exceeded. |
| 210 | """ |
| 211 | return ((num_errors is not None and |
| 212 | num_errors.value > MAX_TOTAL_ERRORS_FOR_RETRY) or |
| 213 | (watermark_errors is not None and |
| 214 | watermark_errors.value > ERROR_WATERMARK)) |
| 215 | |
| 216 | |
| 217 | def _UpdateCounter(counter, adj): |
| 218 | """Update |counter| by |adj| |
| 219 | |
| 220 | Handle atomic updates of |counter|. Also make sure it does not |
| 221 | fall below 0. |
| 222 | |
| 223 | Args: |
| 224 | counter: A multiprocessing.Value to update |
| 225 | adj: The value to add to |counter| |
| 226 | """ |
| 227 | def _Update(): |
| 228 | clamp = 0 if type(adj) is int else 0.0 |
| 229 | counter.value = max(clamp, counter.value + adj) |
| 230 | |
| 231 | if hasattr(counter, 'get_lock'): |
| 232 | with counter.get_lock(): |
| 233 | _Update() |
| 234 | elif counter is not None: |
| 235 | _Update() |
| 236 | |
| 237 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 238 | def UploadSymbol(upload_url, sym_item, file_limit=DEFAULT_FILE_LIMIT, |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 239 | sleep=0, num_errors=None, watermark_errors=None, |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 240 | failed_queue=None, passed_queue=None): |
| 241 | """Upload |sym_item| to |upload_url| |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 242 | |
| 243 | Args: |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 244 | upload_url: The crash server to upload things to |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 245 | sym_item: A SymbolItem containing the path to the breakpad symbol to upload |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 246 | file_limit: The max file size of a symbol file before we try to strip it |
| 247 | sleep: Number of seconds to sleep before running |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 248 | num_errors: An object to update with the error count (needs a .value member) |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 249 | watermark_errors: An object to track current error behavior (needs a .value) |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 250 | failed_queue: When a symbol fails, add it to this queue |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 251 | passed_queue: When a symbol passes, add it to this queue |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 252 | |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 253 | Returns: |
| 254 | The number of errors that were encountered. |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 255 | """ |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 256 | sym_file = sym_item.sym_file |
| 257 | upload_item = sym_item |
| 258 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 259 | if num_errors is None: |
| 260 | num_errors = ctypes.c_int() |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 261 | if ErrorLimitHit(num_errors, watermark_errors): |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 262 | # Abandon ship! It's on fire! NOoooooooooooOOOoooooo. |
Mike Frysinger | 7f9be14 | 2014-01-15 02:16:42 -0500 | [diff] [blame] | 263 | if failed_queue: |
| 264 | failed_queue.put(sym_file) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 265 | return 0 |
| 266 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 267 | if sleep: |
| 268 | # Keeps us from DoS-ing the symbol server. |
| 269 | time.sleep(sleep) |
| 270 | |
| 271 | cros_build_lib.Debug('uploading %s' % sym_file) |
| 272 | |
| 273 | # Ideally there'd be a tempfile.SpooledNamedTemporaryFile that we could use. |
| 274 | with tempfile.NamedTemporaryFile(prefix='upload_symbols', |
| 275 | bufsize=0) as temp_sym_file: |
| 276 | if file_limit: |
| 277 | # If the symbols size is too big, strip out the call frame info. The CFI |
| 278 | # is unnecessary for 32bit x86 targets where the frame pointer is used (as |
| 279 | # all of ours have) and it accounts for over half the size of the symbols |
| 280 | # uploaded. |
| 281 | file_size = os.path.getsize(sym_file) |
| 282 | if file_size > file_limit: |
| 283 | cros_build_lib.Warning('stripping CFI from %s due to size %s > %s', |
| 284 | sym_file, file_size, file_limit) |
| 285 | temp_sym_file.writelines([x for x in open(sym_file, 'rb').readlines() |
| 286 | if not x.startswith('STACK CFI')]) |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 287 | |
| 288 | upload_item = FakeItem(sym_file=temp_sym_file.name, |
| 289 | sym_header=sym_item.sym_header) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 290 | |
| 291 | # Hopefully the crash server will let it through. But it probably won't. |
| 292 | # Not sure what the best answer is in this case. |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 293 | file_size = os.path.getsize(upload_item.sym_file) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 294 | if file_size > CRASH_SERVER_FILE_LIMIT: |
| 295 | cros_build_lib.PrintBuildbotStepWarnings() |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 296 | cros_build_lib.Warning('upload file %s is awfully large, risking ' |
| 297 | 'rejection by the symbol server (%s > %s)', |
| 298 | sym_file, file_size, CRASH_SERVER_FILE_LIMIT) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 299 | |
| 300 | # Upload the symbol file. |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 301 | success = False |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 302 | try: |
Mike Frysinger | 9adcfd2 | 2013-10-24 12:01:40 -0400 | [diff] [blame] | 303 | cros_build_lib.TimedCommand( |
David James | c93e6a4d | 2014-01-13 11:37:36 -0800 | [diff] [blame] | 304 | retry_util.RetryException, |
Mike Frysinger | 9adcfd2 | 2013-10-24 12:01:40 -0400 | [diff] [blame] | 305 | (urllib2.HTTPError, urllib2.URLError), MAX_RETRIES, SymUpload, |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 306 | upload_url, upload_item, sleep=INITIAL_RETRY_DELAY, |
Mike Frysinger | 9adcfd2 | 2013-10-24 12:01:40 -0400 | [diff] [blame] | 307 | timed_log_msg='upload of %10i bytes took %%s: %s' % |
| 308 | (file_size, os.path.basename(sym_file))) |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 309 | success = True |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 310 | |
| 311 | if passed_queue: |
| 312 | passed_queue.put(sym_item) |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 313 | except urllib2.HTTPError as e: |
| 314 | cros_build_lib.Warning('could not upload: %s: HTTP %s: %s', |
| 315 | os.path.basename(sym_file), e.code, e.reason) |
Mike Frysinger | fd35565 | 2014-01-23 02:57:48 -0500 | [diff] [blame] | 316 | except (urllib2.URLError, httplib.HTTPException, socket.error) as e: |
Mike Frysinger | c4ab578 | 2013-10-02 18:14:22 -0400 | [diff] [blame] | 317 | cros_build_lib.Warning('could not upload: %s: %s', |
| 318 | os.path.basename(sym_file), e) |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 319 | finally: |
| 320 | if success: |
| 321 | _UpdateCounter(watermark_errors, ERROR_ADJUST_PASS) |
| 322 | else: |
| 323 | _UpdateCounter(num_errors, 1) |
| 324 | _UpdateCounter(watermark_errors, ERROR_ADJUST_FAIL) |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 325 | if failed_queue: |
| 326 | failed_queue.put(sym_file) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 327 | |
| 328 | return num_errors.value |
| 329 | |
| 330 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 331 | # A dummy class that allows for stubbing in tests and SymUpload. |
| 332 | FakeItem = cros_build_lib.Collection( |
| 333 | 'FakeItem', sym_file=None, sym_header=None, content=lambda x: '') |
| 334 | |
| 335 | |
| 336 | # TODO(build): Delete this if check. http://crbug.com/341152 |
| 337 | if isolateserver: |
| 338 | class SymbolItem(isolateserver.BufferItem): |
| 339 | """Turn a sym_file into an isolateserver.Item""" |
| 340 | |
| 341 | ALGO = hashlib.sha1 |
| 342 | |
| 343 | def __init__(self, sym_file): |
| 344 | sym_header = cros_generate_breakpad_symbols.ReadSymsHeader(sym_file) |
| 345 | super(SymbolItem, self).__init__(str(sym_header), self.ALGO) |
| 346 | self.sym_header = sym_header |
| 347 | self.sym_file = sym_file |
| 348 | |
| 349 | |
| 350 | def SymbolDeduplicatorNotify(dedupe_namespace, dedupe_queue): |
| 351 | """Send a symbol file to the swarming service |
| 352 | |
| 353 | Notify the swarming service of a successful upload. If the notification fails |
| 354 | for any reason, we ignore it. We don't care as it just means we'll upload it |
| 355 | again later on, and the symbol server will handle that graciously. |
| 356 | |
| 357 | This func runs in a different process from the main one, so we cannot share |
| 358 | the storage object. Instead, we create our own. This func stays alive for |
| 359 | the life of the process, so we only create one here overall. |
| 360 | |
| 361 | Args: |
| 362 | dedupe_namespace: The isolateserver namespace to dedupe uploaded symbols. |
| 363 | dedupe_queue: The queue to read SymbolItems from |
| 364 | """ |
| 365 | if dedupe_queue is None: |
| 366 | return |
| 367 | |
| 368 | item = None |
| 369 | try: |
| 370 | storage = isolateserver.get_storage_api(constants.ISOLATESERVER, |
| 371 | dedupe_namespace) |
| 372 | for item in iter(dedupe_queue.get, None): |
| 373 | with timeout_util.Timeout(DEDUPE_TIMEOUT): |
| 374 | storage.push(item, item.content(0)) |
Mike Frysinger | ae29845 | 2014-03-24 22:45:23 -0400 | [diff] [blame^] | 375 | cros_build_lib.Info('dedupe notification finished; exiting') |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 376 | except Exception: |
| 377 | sym_file = item.sym_file if (item and item.sym_file) else '' |
| 378 | cros_build_lib.Warning('posting %s to dedupe server failed', |
| 379 | os.path.basename(sym_file), exc_info=True) |
| 380 | |
Mike Frysinger | 58312e9 | 2014-03-18 04:18:36 -0400 | [diff] [blame] | 381 | # Keep draining the queue though so it doesn't fill up. |
| 382 | while dedupe_queue.get() is not None: |
| 383 | continue |
| 384 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 385 | |
| 386 | def SymbolDeduplicator(storage, sym_paths): |
| 387 | """Filter out symbol files that we've already uploaded |
| 388 | |
| 389 | Using the swarming service, ask it to tell us which symbol files we've already |
| 390 | uploaded in previous runs and/or by other bots. If the query fails for any |
| 391 | reason, we'll just upload all symbols. This is fine as the symbol server will |
| 392 | do the right thing and this phase is purely an optimization. |
| 393 | |
| 394 | This code runs in the main thread which is why we can re-use the existing |
| 395 | storage object. Saves us from having to recreate one all the time. |
| 396 | |
| 397 | Args: |
| 398 | storage: An isolateserver.StorageApi object |
| 399 | sym_paths: List of symbol files to check against the dedupe server |
| 400 | |
| 401 | Returns: |
| 402 | List of symbol files that have not been uploaded before |
| 403 | """ |
| 404 | if not sym_paths: |
| 405 | return sym_paths |
| 406 | |
| 407 | items = [SymbolItem(x) for x in sym_paths] |
| 408 | if storage: |
| 409 | try: |
| 410 | with timeout_util.Timeout(DEDUPE_TIMEOUT): |
| 411 | items = storage.contains(items) |
| 412 | except Exception: |
| 413 | cros_build_lib.Warning('talking to dedupe server failed', exc_info=True) |
| 414 | |
| 415 | return items |
| 416 | |
| 417 | |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 418 | def IsTarball(path): |
| 419 | """Guess if this is a tarball based on the filename.""" |
| 420 | parts = path.split('.') |
| 421 | if len(parts) <= 1: |
| 422 | return False |
| 423 | |
| 424 | if parts[-1] == 'tar': |
| 425 | return True |
| 426 | |
| 427 | if parts[-2] == 'tar': |
| 428 | return parts[-1] in ('bz2', 'gz', 'xz') |
| 429 | |
| 430 | return parts[-1] in ('tbz2', 'tbz', 'tgz', 'txz') |
| 431 | |
| 432 | |
| 433 | def SymbolFinder(tempdir, paths): |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 434 | """Locate symbol files in |paths| |
| 435 | |
| 436 | Args: |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 437 | tempdir: Path to use for temporary files (caller will clean up). |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 438 | paths: A list of input paths to walk. Files are returned w/out any checks. |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 439 | Dirs are searched for files that end in ".sym". Urls are fetched and then |
| 440 | processed. Tarballs are unpacked and walked. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 441 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 442 | Returns: |
| 443 | Yield every viable sym file. |
| 444 | """ |
| 445 | for p in paths: |
Don Garrett | 25f309a | 2014-03-19 14:02:12 -0700 | [diff] [blame] | 446 | # Pylint is confused about members of ParseResult. |
Don Garrett | f8bf784 | 2014-03-20 17:03:42 -0700 | [diff] [blame] | 447 | |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 448 | o = urlparse.urlparse(p) |
Don Garrett | f8bf784 | 2014-03-20 17:03:42 -0700 | [diff] [blame] | 449 | if o.scheme: # pylint: disable=E1101 |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 450 | # Support globs of filenames. |
| 451 | ctx = gs.GSContext() |
| 452 | for p in ctx.LS(p): |
| 453 | cros_build_lib.Info('processing files inside %s', p) |
| 454 | o = urlparse.urlparse(p) |
| 455 | cache_dir = commandline.GetCacheDir() |
| 456 | common_path = os.path.join(cache_dir, constants.COMMON_CACHE) |
| 457 | tar_cache = cache.TarballCache(common_path) |
Don Garrett | f8bf784 | 2014-03-20 17:03:42 -0700 | [diff] [blame] | 458 | key = ('%s%s' % (o.netloc, o.path)).split('/') # pylint: disable=E1101 |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 459 | # The common cache will not be LRU, removing the need to hold a read |
| 460 | # lock on the cached gsutil. |
| 461 | ref = tar_cache.Lookup(key) |
| 462 | try: |
| 463 | ref.SetDefault(p) |
| 464 | except cros_build_lib.RunCommandError as e: |
| 465 | cros_build_lib.Warning('ignoring %s\n%s', p, e) |
| 466 | continue |
| 467 | for p in SymbolFinder(tempdir, [ref.path]): |
| 468 | yield p |
| 469 | |
| 470 | elif os.path.isdir(p): |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 471 | for root, _, files in os.walk(p): |
| 472 | for f in files: |
| 473 | if f.endswith('.sym'): |
| 474 | yield os.path.join(root, f) |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 475 | |
| 476 | elif IsTarball(p): |
| 477 | cros_build_lib.Info('processing files inside %s', p) |
| 478 | tardir = tempfile.mkdtemp(dir=tempdir) |
| 479 | cache.Untar(os.path.realpath(p), tardir) |
| 480 | for p in SymbolFinder(tardir, [tardir]): |
| 481 | yield p |
| 482 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 483 | else: |
| 484 | yield p |
| 485 | |
| 486 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 487 | def WriteQueueToFile(listing, queue, relpath=None): |
| 488 | """Write all the items in |queue| to the |listing|. |
| 489 | |
Mike Frysinger | 5e6dd71 | 2014-03-07 22:21:17 -0500 | [diff] [blame] | 490 | Note: The queue must have a sentinel None appended to the end. |
| 491 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 492 | Args: |
| 493 | listing: Where to write out the list of files. |
| 494 | queue: The queue of paths to drain. |
| 495 | relpath: If set, write out paths relative to this one. |
| 496 | """ |
| 497 | if not listing: |
Mike Frysinger | a0ddac6 | 2014-03-14 10:30:25 -0400 | [diff] [blame] | 498 | # Still drain the queue so we make sure the producer has finished |
| 499 | # before we return. Otherwise, the queue might get destroyed too |
| 500 | # quickly which will trigger a traceback in the producer. |
| 501 | while queue.get() is not None: |
| 502 | continue |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 503 | return |
| 504 | |
| 505 | with cros_build_lib.Open(listing, 'wb+') as f: |
Mike Frysinger | 5e6dd71 | 2014-03-07 22:21:17 -0500 | [diff] [blame] | 506 | while True: |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 507 | path = queue.get() |
Mike Frysinger | 5e6dd71 | 2014-03-07 22:21:17 -0500 | [diff] [blame] | 508 | if path is None: |
| 509 | return |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 510 | if relpath: |
| 511 | path = os.path.relpath(path, relpath) |
| 512 | f.write('%s\n' % path) |
| 513 | |
| 514 | |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 515 | def UploadSymbols(board=None, official=False, breakpad_dir=None, |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 516 | file_limit=DEFAULT_FILE_LIMIT, sleep=DEFAULT_SLEEP_DELAY, |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 517 | upload_limit=None, sym_paths=None, failed_list=None, |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 518 | root=None, retry=True, dedupe_namespace=None): |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 519 | """Upload all the generated symbols for |board| to the crash server |
| 520 | |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 521 | You can use in a few ways: |
| 522 | * pass |board| to locate all of its symbols |
| 523 | * pass |breakpad_dir| to upload all the symbols in there |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 524 | * pass |sym_paths| to upload specific symbols (or dirs of symbols) |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 525 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 526 | Args: |
| 527 | board: The board whose symbols we wish to upload |
| 528 | official: Use the official symbol server rather than the staging one |
| 529 | breakpad_dir: The full path to the breakpad directory where symbols live |
| 530 | file_limit: The max file size of a symbol file before we try to strip it |
| 531 | sleep: How long to sleep in between uploads |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 532 | upload_limit: If set, only upload this many symbols (meant for testing) |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 533 | sym_paths: Specific symbol files (or dirs of sym files) to upload, |
| 534 | otherwise search |breakpad_dir| |
Mike Frysinger | 7f9be14 | 2014-01-15 02:16:42 -0500 | [diff] [blame] | 535 | failed_list: Write the names of all sym files we did not upload; can be a |
| 536 | filename or file-like object. |
Mike Frysinger | 118d250 | 2013-08-19 03:36:56 -0400 | [diff] [blame] | 537 | root: The tree to prefix to |breakpad_dir| (if |breakpad_dir| is not set) |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 538 | retry: Whether we should retry failures. |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 539 | dedupe_namespace: The isolateserver namespace to dedupe uploaded symbols. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 540 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 541 | Returns: |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 542 | The number of errors that were encountered. |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 543 | """ |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 544 | # TODO(build): Delete this assert. |
| 545 | assert isolateserver, 'Missing isolateserver import http://crbug.com/341152' |
| 546 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 547 | if official: |
| 548 | upload_url = OFFICIAL_UPLOAD_URL |
| 549 | else: |
| 550 | cros_build_lib.Warning('unofficial builds upload to the staging server') |
| 551 | upload_url = STAGING_UPLOAD_URL |
| 552 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 553 | if sym_paths: |
| 554 | cros_build_lib.Info('uploading specified symbols to %s', upload_url) |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 555 | else: |
| 556 | if breakpad_dir is None: |
Mike Frysinger | 118d250 | 2013-08-19 03:36:56 -0400 | [diff] [blame] | 557 | breakpad_dir = os.path.join( |
| 558 | root, |
| 559 | cros_generate_breakpad_symbols.FindBreakpadDir(board).lstrip('/')) |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 560 | cros_build_lib.Info('uploading all symbols to %s from %s', upload_url, |
| 561 | breakpad_dir) |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 562 | sym_paths = [breakpad_dir] |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 563 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 564 | # We use storage_query to ask the server about existing symbols. The |
| 565 | # storage_notify_proc process is used to post updates to the server. We |
| 566 | # cannot safely share the storage object between threads/processes, but |
| 567 | # we also want to minimize creating new ones as each object has to init |
| 568 | # new state (like server connections). |
| 569 | if dedupe_namespace: |
| 570 | dedupe_limit = DEDUPE_LIMIT |
| 571 | dedupe_queue = multiprocessing.Queue() |
| 572 | storage_query = isolateserver.get_storage_api(constants.ISOLATESERVER, |
| 573 | dedupe_namespace) |
| 574 | else: |
| 575 | dedupe_limit = 1 |
| 576 | dedupe_queue = storage_query = None |
| 577 | # Can't use parallel.BackgroundTaskRunner because that'll create multiple |
| 578 | # processes and we want only one the whole time (see comment above). |
| 579 | storage_notify_proc = multiprocessing.Process( |
| 580 | target=SymbolDeduplicatorNotify, args=(dedupe_namespace, dedupe_queue)) |
| 581 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 582 | bg_errors = multiprocessing.Value('i') |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 583 | watermark_errors = multiprocessing.Value('f') |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 584 | failed_queue = multiprocessing.Queue() |
| 585 | uploader = functools.partial( |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 586 | UploadSymbol, upload_url, file_limit=file_limit, sleep=sleep, |
| 587 | num_errors=bg_errors, watermark_errors=watermark_errors, |
| 588 | failed_queue=failed_queue, passed_queue=dedupe_queue) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 589 | |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 590 | start_time = datetime.datetime.now() |
| 591 | Counters = cros_build_lib.Collection( |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 592 | 'Counters', upload_limit=upload_limit, uploaded_count=0, deduped_count=0) |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 593 | counters = Counters() |
| 594 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 595 | def _Upload(queue, counters, files): |
| 596 | if not files: |
| 597 | return |
| 598 | |
| 599 | missing_count = 0 |
| 600 | for item in SymbolDeduplicator(storage_query, files): |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 601 | missing_count += 1 |
Mike Frysinger | d42e5f0 | 2014-03-14 11:19:37 -0400 | [diff] [blame] | 602 | |
| 603 | if counters.upload_limit == 0: |
| 604 | continue |
| 605 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 606 | queue.put((item,)) |
| 607 | counters.uploaded_count += 1 |
| 608 | if counters.upload_limit is not None: |
| 609 | counters.upload_limit -= 1 |
| 610 | |
| 611 | counters.deduped_count += (len(files) - missing_count) |
| 612 | |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 613 | try: |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 614 | storage_notify_proc.start() |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 615 | |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 616 | with osutils.TempDir(prefix='upload_symbols.') as tempdir: |
| 617 | # For the first run, we collect the symbols that failed. If the |
| 618 | # overall failure rate was low, we'll retry them on the second run. |
| 619 | for retry in (retry, False): |
| 620 | # We need to limit ourselves to one upload at a time to avoid the server |
| 621 | # kicking in DoS protection. See these bugs for more details: |
| 622 | # http://crbug.com/209442 |
| 623 | # http://crbug.com/212496 |
| 624 | with parallel.BackgroundTaskRunner(uploader, processes=1) as queue: |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 625 | dedupe_list = [] |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 626 | for sym_file in SymbolFinder(tempdir, sym_paths): |
| 627 | dedupe_list.append(sym_file) |
| 628 | dedupe_len = len(dedupe_list) |
| 629 | if dedupe_len < dedupe_limit: |
| 630 | if (counters.upload_limit is None or |
| 631 | dedupe_len < counters.upload_limit): |
| 632 | continue |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 633 | |
Mike Frysinger | 1010a89 | 2014-03-14 11:24:17 -0400 | [diff] [blame] | 634 | # We check the counter before _Upload so that we don't keep talking |
| 635 | # to the dedupe server. Otherwise, we end up sending one symbol at |
| 636 | # a time to it and that slows things down a lot. |
| 637 | if counters.upload_limit == 0: |
| 638 | break |
| 639 | |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 640 | _Upload(queue, counters, dedupe_list) |
| 641 | dedupe_list = [] |
| 642 | _Upload(queue, counters, dedupe_list) |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 643 | |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 644 | # See if we need to retry, and if we haven't failed too many times yet. |
| 645 | if not retry or ErrorLimitHit(bg_errors, watermark_errors): |
Mike Frysinger | 5e6dd71 | 2014-03-07 22:21:17 -0500 | [diff] [blame] | 646 | break |
Mike Frysinger | 5e6dd71 | 2014-03-07 22:21:17 -0500 | [diff] [blame] | 647 | |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 648 | sym_paths = [] |
| 649 | failed_queue.put(None) |
| 650 | while True: |
| 651 | sym_path = failed_queue.get() |
| 652 | if sym_path is None: |
| 653 | break |
| 654 | sym_paths.append(sym_path) |
Mike Frysinger | 02e9240 | 2013-11-22 16:22:02 -0500 | [diff] [blame] | 655 | |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 656 | if sym_paths: |
| 657 | cros_build_lib.Warning('retrying %i symbols', len(sym_paths)) |
| 658 | if counters.upload_limit is not None: |
| 659 | counters.upload_limit += len(sym_paths) |
| 660 | # Decrement the error count in case we recover in the second pass. |
| 661 | assert bg_errors.value >= len(sym_paths), \ |
| 662 | 'more failed files than errors?' |
| 663 | bg_errors.value -= len(sym_paths) |
| 664 | else: |
| 665 | # No failed symbols, so just return now. |
| 666 | break |
Mike Frysinger | 7f9be14 | 2014-01-15 02:16:42 -0500 | [diff] [blame] | 667 | |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 668 | # If the user has requested it, save all the symbol files that we failed to |
| 669 | # upload to a listing file. This should help with recovery efforts later. |
| 670 | failed_queue.put(None) |
| 671 | WriteQueueToFile(failed_list, failed_queue, breakpad_dir) |
| 672 | |
| 673 | finally: |
Mike Frysinger | ae29845 | 2014-03-24 22:45:23 -0400 | [diff] [blame^] | 674 | cros_build_lib.Info('finished uploading; joining background process') |
Mike Frysinger | 1387008 | 2014-03-14 10:41:20 -0400 | [diff] [blame] | 675 | if dedupe_queue: |
| 676 | dedupe_queue.put(None) |
| 677 | storage_notify_proc.join() |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 678 | |
| 679 | cros_build_lib.Info('uploaded %i symbols (%i were deduped) which took: %s', |
| 680 | counters.uploaded_count, counters.deduped_count, |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 681 | datetime.datetime.now() - start_time) |
| 682 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 683 | return bg_errors.value |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 684 | |
| 685 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 686 | def main(argv): |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 687 | # TODO(build): Delete this assert. |
| 688 | assert isolateserver, 'Missing isolateserver import http://crbug.com/341152' |
| 689 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 690 | parser = commandline.ArgumentParser(description=__doc__) |
| 691 | |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 692 | parser.add_argument('sym_paths', type='path_or_uri', nargs='*', default=None, |
| 693 | help='symbol file or directory or URL or tarball') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 694 | parser.add_argument('--board', default=None, |
| 695 | help='board to build packages for') |
| 696 | parser.add_argument('--breakpad_root', type='path', default=None, |
| 697 | help='root directory for breakpad symbols') |
| 698 | parser.add_argument('--official_build', action='store_true', default=False, |
| 699 | help='point to official symbol server') |
| 700 | parser.add_argument('--regenerate', action='store_true', default=False, |
| 701 | help='regenerate all symbols') |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 702 | parser.add_argument('--upload-limit', type=int, default=None, |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 703 | help='only upload # number of symbols') |
| 704 | parser.add_argument('--strip_cfi', type=int, |
| 705 | default=CRASH_SERVER_FILE_LIMIT - (10 * 1024 * 1024), |
| 706 | help='strip CFI data for files above this size') |
Mike Frysinger | 7f9be14 | 2014-01-15 02:16:42 -0500 | [diff] [blame] | 707 | parser.add_argument('--failed-list', type='path', |
| 708 | help='where to save a list of failed symbols') |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 709 | parser.add_argument('--dedupe', action='store_true', default=False, |
| 710 | help='use the swarming service to avoid re-uploading') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 711 | parser.add_argument('--testing', action='store_true', default=False, |
| 712 | help='run in testing mode') |
| 713 | parser.add_argument('--yes', action='store_true', default=False, |
| 714 | help='answer yes to all prompts') |
| 715 | |
| 716 | opts = parser.parse_args(argv) |
Mike Frysinger | 90e49ca | 2014-01-14 14:42:07 -0500 | [diff] [blame] | 717 | opts.Freeze() |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 718 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 719 | if opts.sym_paths: |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 720 | if opts.regenerate: |
| 721 | cros_build_lib.Die('--regenerate may not be used with specific files') |
| 722 | else: |
| 723 | if opts.board is None: |
| 724 | cros_build_lib.Die('--board is required') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 725 | |
| 726 | if opts.breakpad_root and opts.regenerate: |
| 727 | cros_build_lib.Die('--regenerate may not be used with --breakpad_root') |
| 728 | |
| 729 | if opts.testing: |
| 730 | # TODO(build): Kill off --testing mode once unittests are up-to-snuff. |
| 731 | cros_build_lib.Info('running in testing mode') |
| 732 | # pylint: disable=W0601,W0603 |
| 733 | global INITIAL_RETRY_DELAY, SymUpload, DEFAULT_SLEEP_DELAY |
| 734 | INITIAL_RETRY_DELAY = DEFAULT_SLEEP_DELAY = 0 |
| 735 | SymUpload = TestingSymUpload |
| 736 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 737 | dedupe_namespace = None |
| 738 | if opts.dedupe: |
| 739 | if opts.official_build and not opts.testing: |
| 740 | dedupe_namespace = OFFICIAL_DEDUPE_NAMESPACE |
| 741 | else: |
| 742 | dedupe_namespace = STAGING_DEDUPE_NAMESPACE |
| 743 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 744 | if not opts.yes: |
Mike Frysinger | c5de960 | 2014-02-09 02:42:36 -0500 | [diff] [blame] | 745 | prolog = '\n'.join(textwrap.wrap(textwrap.dedent(""" |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 746 | Uploading symbols for an entire Chromium OS build is really only |
| 747 | necessary for release builds and in a few cases for developers |
| 748 | to debug problems. It will take considerable time to run. For |
| 749 | developer debugging purposes, consider instead passing specific |
| 750 | files to upload. |
Mike Frysinger | c5de960 | 2014-02-09 02:42:36 -0500 | [diff] [blame] | 751 | """), 80)).strip() |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 752 | if not cros_build_lib.BooleanPrompt( |
| 753 | prompt='Are you sure you want to upload all build symbols', |
Mike Frysinger | c5de960 | 2014-02-09 02:42:36 -0500 | [diff] [blame] | 754 | default=False, prolog=prolog): |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 755 | cros_build_lib.Die('better safe than sorry') |
| 756 | |
| 757 | ret = 0 |
| 758 | if opts.regenerate: |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 759 | ret += cros_generate_breakpad_symbols.GenerateBreakpadSymbols( |
| 760 | opts.board, breakpad_dir=opts.breakpad_root) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 761 | |
| 762 | ret += UploadSymbols(opts.board, official=opts.official_build, |
| 763 | breakpad_dir=opts.breakpad_root, |
| 764 | file_limit=opts.strip_cfi, sleep=DEFAULT_SLEEP_DELAY, |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 765 | upload_limit=opts.upload_limit, sym_paths=opts.sym_paths, |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 766 | failed_list=opts.failed_list, |
| 767 | dedupe_namespace=dedupe_namespace) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 768 | if ret: |
| 769 | cros_build_lib.Error('encountered %i problem(s)', ret) |
| 770 | # Since exit(status) gets masked, clamp it to 1 so we don't inadvertently |
| 771 | # return 0 in case we are a multiple of the mask. |
| 772 | ret = 1 |
| 773 | |
| 774 | return ret |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 775 | |
| 776 | |
| 777 | # We need this to run once per process. Do it at module import time as that |
| 778 | # will let us avoid doing it inline at function call time (see SymUpload) as |
| 779 | # that func might be called by the multiprocessing module which means we'll |
| 780 | # do the opener logic multiple times overall. Plus, if you're importing this |
| 781 | # module, it's a pretty good chance that you're going to need this. |
| 782 | poster.streaminghttp.register_openers() |