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 | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 14 | import hashlib |
Mike Frysinger | a4fa1e8 | 2014-01-15 01:45:56 -0500 | [diff] [blame] | 15 | import httplib |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 16 | import itertools |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 17 | import os |
Mike Frysinger | fd35565 | 2014-01-23 02:57:48 -0500 | [diff] [blame] | 18 | import socket |
Mike Frysinger | c5597f2 | 2014-11-27 15:39:15 -0500 | [diff] [blame] | 19 | import sys |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 20 | import textwrap |
| 21 | import tempfile |
| 22 | import time |
Mike Frysinger | 094a217 | 2013-08-14 12:54:35 -0400 | [diff] [blame] | 23 | import urllib2 |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 24 | import urlparse |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 25 | |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame] | 26 | from chromite.cbuildbot import constants |
Mike Frysinger | bbd1f11 | 2016-09-08 18:25:11 -0400 | [diff] [blame] | 27 | |
| 28 | # The isolateserver includes a bunch of third_party python packages that clash |
| 29 | # with chromite's bundled third_party python packages (like oauth2client). |
| 30 | # Since upload_symbols is not imported in to other parts of chromite, and there |
| 31 | # are no deps in third_party we care about, purge the chromite copy. This way |
| 32 | # we can use isolateserver for deduping. |
| 33 | # TODO: If we ever sort out third_party/ handling and make it per-script opt-in, |
| 34 | # we can purge this logic. |
| 35 | third_party = os.path.join(constants.CHROMITE_DIR, 'third_party') |
| 36 | while True: |
| 37 | try: |
| 38 | sys.path.remove(third_party) |
| 39 | except ValueError: |
| 40 | break |
| 41 | sys.path.insert(0, os.path.join(third_party, 'swarming.client')) |
| 42 | sys.path.insert(0, os.path.join(third_party, 'upload_symbols')) |
| 43 | del third_party |
| 44 | |
| 45 | # Has to be after sys.path manipulation above. |
| 46 | # And our sys.path muckery confuses pylint. |
| 47 | import poster # pylint: disable=import-error |
| 48 | |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 49 | from chromite.lib import cache |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 50 | from chromite.lib import commandline |
| 51 | from chromite.lib import cros_build_lib |
Ralph Nathan | 5a582ff | 2015-03-20 18:18:30 -0700 | [diff] [blame] | 52 | from chromite.lib import cros_logging as logging |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 53 | from chromite.lib import gs |
| 54 | from chromite.lib import osutils |
Gilad Arnold | 83233ed | 2015-05-08 12:12:13 -0700 | [diff] [blame] | 55 | from chromite.lib import path_util |
David James | c93e6a4d | 2014-01-13 11:37:36 -0800 | [diff] [blame] | 56 | from chromite.lib import retry_util |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 57 | from chromite.lib import timeout_util |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 58 | from chromite.scripts import cros_generate_breakpad_symbols |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 59 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 60 | # Needs to be after chromite imports. |
Mike Frysinger | c5597f2 | 2014-11-27 15:39:15 -0500 | [diff] [blame] | 61 | # We don't want to import the general keyring module as that will implicitly |
| 62 | # try to import & connect to a dbus server. That's a waste of time. |
| 63 | sys.modules['keyring'] = None |
Mike Frysinger | bbd1f11 | 2016-09-08 18:25:11 -0400 | [diff] [blame] | 64 | # And our sys.path muckery confuses pylint. |
| 65 | import isolateserver # pylint: disable=import-error |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 66 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 67 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 68 | # We need this to run once per process. Do it at module import time as that |
| 69 | # will let us avoid doing it inline at function call time (see UploadSymbolFile) |
| 70 | # as that func might be called by the multiprocessing module which means we'll |
| 71 | # do the opener logic multiple times overall. Plus, if you're importing this |
| 72 | # module, it's a pretty good chance that you're going to need this. |
| 73 | poster.streaminghttp.register_openers() |
| 74 | |
| 75 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 76 | # URLs used for uploading symbols. |
| 77 | OFFICIAL_UPLOAD_URL = 'http://clients2.google.com/cr/symbol' |
| 78 | STAGING_UPLOAD_URL = 'http://clients2.google.com/cr/staging_symbol' |
| 79 | |
| 80 | |
| 81 | # The crash server rejects files that are this big. |
Ryo Hashimoto | f66d8ca | 2016-09-07 15:45:13 +0900 | [diff] [blame] | 82 | CRASH_SERVER_FILE_LIMIT = 500 * 1024 * 1024 |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 83 | # Give ourselves a little breathing room from what the server expects. |
| 84 | DEFAULT_FILE_LIMIT = CRASH_SERVER_FILE_LIMIT - (10 * 1024 * 1024) |
| 85 | |
| 86 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 87 | # The batch limit when talking to the dedup server. We avoid sending one at a |
| 88 | # time as the round trip overhead will dominate. Conversely, we avoid sending |
| 89 | # all at once so we can start uploading symbols asap -- the symbol server is a |
| 90 | # bit slow and will take longer than anything else. |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 91 | DEDUPE_LIMIT = 100 |
| 92 | |
| 93 | # How long to wait for the server to respond with the results. Note that the |
| 94 | # larger the limit above, the larger this will need to be. So we give it ~1 |
| 95 | # second per item max. |
| 96 | DEDUPE_TIMEOUT = DEDUPE_LIMIT |
| 97 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 98 | # How long to wait for the notification to finish (in seconds). |
| 99 | DEDUPE_NOTIFY_TIMEOUT = 240 |
Mike Frysinger | 4dd462e | 2014-04-30 16:21:51 -0400 | [diff] [blame] | 100 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 101 | # The unique namespace in the dedupe server that only we use. Helps avoid |
| 102 | # collisions with all the hashed values and unrelated content. |
Don Garrett | 747cc4b | 2015-10-07 14:48:48 -0700 | [diff] [blame] | 103 | OFFICIAL_DEDUPE_NAMESPACE_TMPL = '%s-upload-symbols' |
| 104 | STAGING_DEDUPE_NAMESPACE_TMPL = '%s-staging' % OFFICIAL_DEDUPE_NAMESPACE_TMPL |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 105 | |
| 106 | |
Mike Frysinger | 7104666 | 2014-09-12 18:15:15 -0700 | [diff] [blame] | 107 | # The minimum average rate (in bytes per second) that we expect to maintain |
| 108 | # when uploading symbols. This has to allow for symbols that are up to |
| 109 | # CRASH_SERVER_FILE_LIMIT in size. |
| 110 | UPLOAD_MIN_RATE = CRASH_SERVER_FILE_LIMIT / (30 * 60) |
| 111 | |
| 112 | # The lowest timeout (in seconds) we'll allow. If the server is overloaded, |
| 113 | # then there might be a delay in setting up the connection, not just with the |
| 114 | # transfer. So even a small file might need a larger value. |
| 115 | UPLOAD_MIN_TIMEOUT = 2 * 60 |
Mike Frysinger | cd78a08 | 2013-06-26 17:13:04 -0400 | [diff] [blame] | 116 | |
| 117 | |
Don Garrett | 7a79309 | 2016-07-06 16:50:27 -0700 | [diff] [blame] | 118 | # Sleep for 500ms in between uploads to avoid DoS'ing symbol server. |
| 119 | SLEEP_DELAY = 0.5 |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 120 | |
| 121 | |
| 122 | # Number of seconds to wait before retrying an upload. The delay will double |
| 123 | # for each subsequent retry of the same symbol file. |
| 124 | INITIAL_RETRY_DELAY = 1 |
| 125 | |
| 126 | # Allow up to 7 attempts to upload a symbol file (total delay may be |
| 127 | # 1+2+4+8+16+32=63 seconds). |
| 128 | MAX_RETRIES = 6 |
| 129 | |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 130 | # Number of total errors, before uploads are no longer attempted. |
| 131 | # This is used to avoid lots of errors causing unreasonable delays. |
Mike Frysinger | eb753bf | 2013-11-22 16:05:35 -0500 | [diff] [blame] | 132 | MAX_TOTAL_ERRORS_FOR_RETRY = 30 |
| 133 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 134 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 135 | def BatchGenerator(iterator, batch_size): |
| 136 | """Given an iterator, break into lists of size batch_size. |
Fang Deng | ba68046 | 2015-08-16 20:34:11 -0700 | [diff] [blame] | 137 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 138 | The result is a generator, that will only read in as many inputs as needed for |
| 139 | the current batch. The final result can be smaller than batch_size. |
Mike Frysinger | 0a2fd92 | 2014-09-12 20:23:42 -0700 | [diff] [blame] | 140 | """ |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 141 | batch = [] |
| 142 | for i in iterator: |
| 143 | batch.append(i) |
| 144 | if len(batch) >= batch_size: |
| 145 | yield batch |
| 146 | batch = [] |
Mike Frysinger | 0a2fd92 | 2014-09-12 20:23:42 -0700 | [diff] [blame] | 147 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 148 | if batch: |
| 149 | # if there was anything left in the final batch, yield it. |
| 150 | yield batch |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 151 | |
| 152 | |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 153 | def IsTarball(path): |
| 154 | """Guess if this is a tarball based on the filename.""" |
| 155 | parts = path.split('.') |
| 156 | if len(parts) <= 1: |
| 157 | return False |
| 158 | |
| 159 | if parts[-1] == 'tar': |
| 160 | return True |
| 161 | |
| 162 | if parts[-2] == 'tar': |
| 163 | return parts[-1] in ('bz2', 'gz', 'xz') |
| 164 | |
| 165 | return parts[-1] in ('tbz2', 'tbz', 'tgz', 'txz') |
| 166 | |
| 167 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 168 | class SymbolFile(object): |
| 169 | """This class represents the state of a symbol file during processing. |
| 170 | |
| 171 | Properties: |
| 172 | display_path: Name of symbol file that should be consistent between builds. |
| 173 | file_name: Transient path of the symbol file. |
| 174 | header: ReadSymsHeader output. Dict with assorted meta-data. |
| 175 | status: INITIAL, DUPLICATE, or UPLOADED based on status of processing. |
| 176 | dedupe_item: None or instance of DedupeItem for this symbol file. |
| 177 | dedupe_push_state: Opaque value to return to dedupe code for file. |
| 178 | display_name: Read only friendly (short) file name for logging. |
| 179 | file_size: Read only size of the symbol file. |
| 180 | """ |
| 181 | INITIAL = 'initial' |
| 182 | DUPLICATE = 'duplicate' |
| 183 | UPLOADED = 'uploaded' |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 184 | ERROR = 'error' |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 185 | |
| 186 | def __init__(self, display_path, file_name): |
| 187 | """An instance of this class represents a symbol file over time. |
| 188 | |
| 189 | Args: |
| 190 | display_path: A unique/persistent between builds name to present to the |
| 191 | crash server. It is the file name, relative to where it |
| 192 | came from (tarball, breakpad dir, etc). |
| 193 | file_name: A the current location of the symbol file. |
| 194 | """ |
| 195 | self.display_path = display_path |
| 196 | self.file_name = file_name |
| 197 | self.header = cros_generate_breakpad_symbols.ReadSymsHeader(file_name) |
| 198 | self.status = SymbolFile.INITIAL |
| 199 | self.dedupe_item = None |
| 200 | self.dedupe_push_state = None |
| 201 | |
| 202 | @property |
| 203 | def display_name(self): |
| 204 | return os.path.basename(self.display_path) |
| 205 | |
| 206 | def FileSize(self): |
| 207 | return os.path.getsize(self.file_name) |
| 208 | |
| 209 | |
| 210 | class DedupeItem(isolateserver.BufferItem): |
| 211 | """Turn a SymbolFile into an isolateserver.Item""" |
| 212 | |
| 213 | ALGO = hashlib.sha1 |
| 214 | |
| 215 | def __init__(self, symbol): |
Mike Frysinger | bbd1f11 | 2016-09-08 18:25:11 -0400 | [diff] [blame] | 216 | isolateserver.BufferItem.__init__(self, str(symbol.header), self.ALGO) |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 217 | self.symbol = symbol |
| 218 | |
| 219 | |
| 220 | def FindSymbolFiles(tempdir, paths): |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 221 | """Locate symbol files in |paths| |
| 222 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 223 | This returns SymbolFile objects that contain file references which are valid |
| 224 | after this exits. Those files may exist externally, or be created in the |
| 225 | tempdir (say, when expanding tarballs). The caller must not consider |
| 226 | SymbolFile's valid after tempdir is cleaned up. |
| 227 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 228 | Args: |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 229 | tempdir: Path to use for temporary files. |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 230 | 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] | 231 | Dirs are searched for files that end in ".sym". Urls are fetched and then |
| 232 | processed. Tarballs are unpacked and walked. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 233 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 234 | Yields: |
| 235 | A SymbolFile for every symbol file found in paths. |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 236 | """ |
Gilad Arnold | 83233ed | 2015-05-08 12:12:13 -0700 | [diff] [blame] | 237 | cache_dir = path_util.GetCacheDir() |
Mike Frysinger | e847efd | 2015-01-08 03:57:24 -0500 | [diff] [blame] | 238 | common_path = os.path.join(cache_dir, constants.COMMON_CACHE) |
| 239 | tar_cache = cache.TarballCache(common_path) |
| 240 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 241 | for p in paths: |
Don Garrett | 25f309a | 2014-03-19 14:02:12 -0700 | [diff] [blame] | 242 | # Pylint is confused about members of ParseResult. |
Don Garrett | f8bf784 | 2014-03-20 17:03:42 -0700 | [diff] [blame] | 243 | |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 244 | o = urlparse.urlparse(p) |
Don Garrett | f8bf784 | 2014-03-20 17:03:42 -0700 | [diff] [blame] | 245 | if o.scheme: # pylint: disable=E1101 |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 246 | # Support globs of filenames. |
| 247 | ctx = gs.GSContext() |
| 248 | for p in ctx.LS(p): |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 249 | logging.info('processing files inside %s', p) |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 250 | o = urlparse.urlparse(p) |
Don Garrett | f8bf784 | 2014-03-20 17:03:42 -0700 | [diff] [blame] | 251 | key = ('%s%s' % (o.netloc, o.path)).split('/') # pylint: disable=E1101 |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 252 | # The common cache will not be LRU, removing the need to hold a read |
| 253 | # lock on the cached gsutil. |
| 254 | ref = tar_cache.Lookup(key) |
| 255 | try: |
| 256 | ref.SetDefault(p) |
| 257 | except cros_build_lib.RunCommandError as e: |
Ralph Nathan | 446aee9 | 2015-03-23 14:44:56 -0700 | [diff] [blame] | 258 | logging.warning('ignoring %s\n%s', p, e) |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 259 | continue |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 260 | for p in FindSymbolFiles(tempdir, [ref.path]): |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 261 | yield p |
| 262 | |
| 263 | elif os.path.isdir(p): |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 264 | for root, _, files in os.walk(p): |
| 265 | for f in files: |
| 266 | if f.endswith('.sym'): |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 267 | # If p is '/tmp/foo' and filename is '/tmp/foo/bar/bar.sym', |
| 268 | # display_path = 'bar/bar.sym' |
| 269 | filename = os.path.join(root, f) |
| 270 | yield SymbolFile(display_path=filename[len(p):].lstrip('/'), |
| 271 | file_name=filename) |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 272 | |
| 273 | elif IsTarball(p): |
Ralph Nathan | 0304728 | 2015-03-23 11:09:32 -0700 | [diff] [blame] | 274 | logging.info('processing files inside %s', p) |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 275 | tardir = tempfile.mkdtemp(dir=tempdir) |
| 276 | cache.Untar(os.path.realpath(p), tardir) |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 277 | for p in FindSymbolFiles(tardir, [tardir]): |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 278 | yield p |
| 279 | |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 280 | else: |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 281 | yield SymbolFile(display_path=p, file_name=p) |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 282 | |
| 283 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 284 | def AdjustSymbolFileSize(symbol, tempdir, file_limit): |
| 285 | """Examine symbols files for size problems, and reduce if needed. |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 286 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 287 | If the symbols size is too big, strip out the call frame info. The CFI |
| 288 | is unnecessary for 32bit x86 targets where the frame pointer is used (as |
| 289 | all of ours have) and it accounts for over half the size of the symbols |
| 290 | uploaded. |
| 291 | |
| 292 | Stripped files will be created inside tempdir, and will be the callers |
| 293 | responsibility to clean up. |
| 294 | |
| 295 | We also warn, if a symbols file is still too large after stripping. |
Mike Frysinger | 5e6dd71 | 2014-03-07 22:21:17 -0500 | [diff] [blame] | 296 | |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 297 | Args: |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 298 | symbol: SymbolFile instance to be examined and modified as needed.. |
| 299 | tempdir: A temporary directory we can create files in that the caller will |
| 300 | clean up. |
| 301 | file_limit: We only strip files which are larger than this limit. |
| 302 | |
| 303 | Returns: |
| 304 | SymbolFile instance (original or modified as needed) |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 305 | """ |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 306 | file_size = symbol.FileSize() |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 307 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 308 | if file_limit and symbol.FileSize() > file_limit: |
| 309 | with tempfile.NamedTemporaryFile( |
| 310 | prefix='upload_symbols', bufsize=0, |
| 311 | dir=tempdir, delete=False) as temp_sym_file: |
| 312 | |
| 313 | temp_sym_file.writelines( |
| 314 | [x for x in open(symbol.file_name, 'rb').readlines() |
| 315 | if not x.startswith('STACK CFI')] |
| 316 | ) |
| 317 | |
| 318 | original_file_size = file_size |
| 319 | symbol.file_name = temp_sym_file.name |
| 320 | file_size = symbol.FileSize() |
| 321 | |
| 322 | logging.warning('stripped CFI for %s reducing size %s > %s', |
| 323 | symbol.display_name, original_file_size, file_size) |
| 324 | |
| 325 | # Hopefully the crash server will let it through. But it probably won't. |
| 326 | # Not sure what the best answer is in this case. |
| 327 | if file_size >= CRASH_SERVER_FILE_LIMIT: |
| 328 | logging.PrintBuildbotStepWarnings() |
| 329 | logging.warning('upload file %s is awfully large, risking rejection by ' |
| 330 | 'the symbol server (%s > %s)', symbol.display_path, |
| 331 | file_size, CRASH_SERVER_FILE_LIMIT) |
| 332 | |
| 333 | return symbol |
| 334 | |
| 335 | def OpenDeduplicateConnection(dedupe_namespace): |
| 336 | """Open a connection to the isolate server for Dedupe use. |
| 337 | |
| 338 | Args: |
| 339 | dedupe_namespace: String id for the comparison namespace. |
| 340 | |
| 341 | Returns: |
| 342 | Connection proxy, or None on failure. |
| 343 | """ |
| 344 | try: |
| 345 | with timeout_util.Timeout(DEDUPE_TIMEOUT): |
| 346 | return isolateserver.get_storage_api(constants.ISOLATESERVER, |
| 347 | dedupe_namespace) |
| 348 | except Exception: |
| 349 | logging.warning('initializing isolate server connection failed', |
| 350 | exc_info=True) |
| 351 | return None |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 352 | |
| 353 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 354 | def FindDuplicates(symbols, dedupe_namespace): |
| 355 | """Mark symbol files we've already uploaded as duplicates. |
| 356 | |
| 357 | Using the swarming service, ask it to tell us which symbol files we've already |
| 358 | uploaded in previous runs and/or by other bots. If the query fails for any |
| 359 | reason, we'll just upload all symbols. This is fine as the symbol server will |
| 360 | do the right thing and this phase is purely an optimization. |
| 361 | |
| 362 | Args: |
| 363 | symbols: An iterable of SymbolFiles to be uploaded. |
| 364 | dedupe_namespace: String id for the comparison namespace. |
| 365 | |
| 366 | Yields: |
| 367 | All SymbolFiles from symbols, but duplicates have status updated to |
| 368 | DUPLICATE. |
| 369 | """ |
| 370 | storage_query = OpenDeduplicateConnection(dedupe_namespace) |
| 371 | |
| 372 | # We query isolate in batches, to reduce the number of network queries. |
| 373 | for batch in BatchGenerator(symbols, DEDUPE_LIMIT): |
| 374 | query_results = None |
| 375 | |
| 376 | if storage_query: |
| 377 | # Convert SymbolFiles into DedupeItems. |
| 378 | items = [DedupeItem(x) for x in batch] |
| 379 | for item in items: |
| 380 | item.prepare(DedupeItem.ALGO) |
| 381 | |
| 382 | # Look for duplicates. |
| 383 | try: |
| 384 | with timeout_util.Timeout(DEDUPE_TIMEOUT): |
| 385 | query_results = storage_query.contains(items) |
| 386 | except Exception: |
| 387 | logging.warning('talking to dedupe server failed', exc_info=True) |
| 388 | storage_query = None |
| 389 | |
| 390 | if query_results is not None: |
| 391 | for b in batch: |
| 392 | b.status = SymbolFile.DUPLICATE |
| 393 | |
| 394 | # Only the non-duplicates appear in the query_results. |
| 395 | for item, push_state in query_results.iteritems(): |
| 396 | # Remember the dedupe state, so we can mark the symbol as uploaded |
| 397 | # later on. |
| 398 | item.symbol.status = SymbolFile.INITIAL |
| 399 | item.symbol.dedupe_item = item |
| 400 | item.symbol.dedupe_push_state = push_state |
| 401 | |
| 402 | # Yield all symbols we haven't shown to be duplicates. |
| 403 | for b in batch: |
| 404 | if b.status == SymbolFile.DUPLICATE: |
| 405 | logging.debug('Found duplicate: %s', b.display_name) |
| 406 | yield b |
| 407 | |
| 408 | |
| 409 | def PostForDeduplication(symbols, dedupe_namespace): |
| 410 | """Send a symbol file to the swarming service |
| 411 | |
| 412 | Notify the isolate service of a successful upload. If the notification fails |
| 413 | for any reason, we ignore it. We don't care as it just means we'll upload it |
| 414 | again later on, and the symbol server will handle that graciously. |
| 415 | |
| 416 | Args: |
| 417 | symbols: An iterable of SymbolFiles to be uploaded. |
| 418 | dedupe_namespace: String id for the comparison namespace. |
| 419 | |
| 420 | Yields: |
| 421 | Each symbol from symbols, unmodified. |
| 422 | """ |
| 423 | storage_query = OpenDeduplicateConnection(dedupe_namespace) |
| 424 | |
| 425 | for s in symbols: |
| 426 | # If we can talk to isolate, and we uploaded this symbol, and we |
| 427 | # queried for it's presence before, upload to isolate now. |
| 428 | |
| 429 | if storage_query and s.status == SymbolFile.UPLOADED and s.dedupe_item: |
| 430 | s.dedupe_item.prepare(DedupeItem.ALGO) |
| 431 | try: |
| 432 | with timeout_util.Timeout(DEDUPE_NOTIFY_TIMEOUT): |
| 433 | storage_query.push(s.dedupe_item, s.dedupe_push_state, |
| 434 | s.dedupe_item.content()) |
| 435 | logging.info('sent %s', s.display_name) |
| 436 | except Exception: |
| 437 | logging.warning('posting %s to dedupe server failed', |
| 438 | os.path.basename(s.display_path), exc_info=True) |
| 439 | storage_query = None |
| 440 | |
| 441 | yield s |
| 442 | |
| 443 | |
| 444 | def GetUploadTimeout(symbol): |
| 445 | """How long to wait for a specific file to upload to the crash server. |
| 446 | |
| 447 | This is a function largely to make unittesting easier. |
| 448 | |
| 449 | Args: |
| 450 | symbol: A SymbolFile instance. |
| 451 | |
| 452 | Returns: |
| 453 | Timeout length (in seconds) |
| 454 | """ |
| 455 | # Scale the timeout based on the filesize. |
| 456 | return max(symbol.FileSize() / UPLOAD_MIN_RATE, UPLOAD_MIN_TIMEOUT) |
| 457 | |
| 458 | |
| 459 | def UploadSymbolFile(upload_url, symbol, product_name): |
| 460 | """Upload a symbol file to the crash server. |
| 461 | |
| 462 | The upload is a multipart/form-data POST with the following parameters: |
| 463 | code_file: the basename of the module, e.g. "app" |
| 464 | code_identifier: the module file's identifier |
| 465 | debug_file: the basename of the debugging file, e.g. "app" |
| 466 | debug_identifier: the debug file's identifier, usually consisting of |
| 467 | the guid and age embedded in the pdb, e.g. |
| 468 | "11111111BBBB3333DDDD555555555555F" |
| 469 | version: the file version of the module, e.g. "1.2.3.4" |
| 470 | product: HTTP-friendly product name |
| 471 | os: the operating system that the module was built for |
| 472 | cpu: the CPU that the module was built for |
| 473 | symbol_file: the contents of the breakpad-format symbol file |
| 474 | |
| 475 | Args: |
| 476 | upload_url: The crash URL to POST the |sym_file| to |
| 477 | symbol: A SymbolFile instance. |
| 478 | product_name: A string for stats purposes. Usually 'ChromeOS' or 'Android'. |
| 479 | """ |
| 480 | fields = ( |
| 481 | ('code_file', symbol.header.name), |
| 482 | ('debug_file', symbol.header.name), |
| 483 | ('debug_identifier', symbol.header.id.replace('-', '')), |
| 484 | # The product/version fields are used by the server only for statistic |
| 485 | # purposes. They do not impact symbolization, so they're safe to set |
| 486 | # to any value all the time. |
| 487 | # In this case, we use it to help see the load our build system is |
| 488 | # placing on the server. |
| 489 | # Not sure what to set for the version. Maybe the git sha1 of this file. |
| 490 | # Note: the server restricts this to 30 chars. |
| 491 | #('version', None), |
| 492 | ('product', product_name), |
| 493 | ('os', symbol.header.os), |
| 494 | ('cpu', symbol.header.cpu), |
| 495 | poster.encode.MultipartParam.from_file('symbol_file', symbol.file_name), |
| 496 | ) |
| 497 | |
| 498 | data, headers = poster.encode.multipart_encode(fields) |
| 499 | request = urllib2.Request(upload_url, data, headers) |
| 500 | request.add_header('User-agent', 'chromite.upload_symbols') |
| 501 | urllib2.urlopen(request, timeout=GetUploadTimeout(symbol)) |
| 502 | |
| 503 | |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 504 | def PerformSymbolsFileUpload(symbols, upload_url, product_name='ChromeOS'): |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 505 | """Upload the symbols to the crash server |
| 506 | |
| 507 | Args: |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 508 | symbols: An iterable of SymbolFiles to be uploaded. |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 509 | upload_url: URL of crash server to upload too. |
| 510 | failures: Tracker for total upload failures. |
| 511 | product_name: A string for stats purposes. Usually 'ChromeOS' or 'Android'. |
| 512 | |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 513 | Yields: |
| 514 | Each symbol from symbols, perhaps modified. |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 515 | """ |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 516 | failures = 0 |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 517 | |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 518 | for s in symbols: |
| 519 | if (failures < MAX_TOTAL_ERRORS_FOR_RETRY and |
| 520 | s.status in (SymbolFile.INITIAL, SymbolFile.ERROR)): |
| 521 | # Keeps us from DoS-ing the symbol server. |
| 522 | time.sleep(SLEEP_DELAY) |
| 523 | logging.info('Uploading symbol_file: %s', s.display_path) |
| 524 | try: |
| 525 | # This command retries the upload multiple times with growing delays. We |
| 526 | # only consider the upload a failure if these retries fail. |
| 527 | cros_build_lib.TimedCommand( |
| 528 | retry_util.RetryException, |
| 529 | (urllib2.HTTPError, urllib2.URLError), MAX_RETRIES, |
| 530 | UploadSymbolFile, |
| 531 | upload_url, s, product_name, |
| 532 | sleep=INITIAL_RETRY_DELAY, |
| 533 | timed_log_msg=('upload of %10i bytes took %%(delta)s' % |
| 534 | s.FileSize())) |
| 535 | s.status = SymbolFile.UPLOADED |
| 536 | except urllib2.HTTPError as e: |
| 537 | logging.warning('could not upload: %s: HTTP %s: %s', |
| 538 | s.display_name, e.code, e.reason) |
| 539 | s.status = SymbolFile.ERROR |
| 540 | failures += 1 |
| 541 | except (urllib2.URLError, httplib.HTTPException, socket.error) as e: |
| 542 | logging.warning('could not upload: %s: %s', s.display_name, e) |
| 543 | s.status = SymbolFile.ERROR |
| 544 | failures += 1 |
| 545 | |
| 546 | # We pass the symbol along, on both success and failure. |
| 547 | yield s |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 548 | |
| 549 | |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 550 | def ReportResults(symbols, failed_list): |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 551 | """Log a summary of the symbol uploading. |
| 552 | |
| 553 | This has the side effect of fully consuming the symbols iterator. |
| 554 | |
| 555 | Args: |
| 556 | symbols: An iterator of SymbolFiles to be uploaded. |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 557 | failed_list: A filename at which to write out a list of our failed uploads. |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 558 | |
| 559 | Returns: |
| 560 | The number of symbols not uploaded. |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 561 | """ |
| 562 | upload_failures = [] |
| 563 | result_counts = { |
| 564 | SymbolFile.INITIAL: 0, |
| 565 | SymbolFile.UPLOADED: 0, |
| 566 | SymbolFile.DUPLICATE: 0, |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 567 | SymbolFile.ERROR: 0, |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | for s in symbols: |
| 571 | result_counts[s.status] += 1 |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 572 | if s.status in [SymbolFile.INITIAL, SymbolFile.ERROR]: |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 573 | upload_failures.append(s) |
| 574 | |
| 575 | logging.info('Uploaded %(uploaded)d, Skipped %(duplicate)d duplicates.', |
| 576 | result_counts) |
| 577 | |
Chris Ching | 9190803 | 2016-09-27 16:55:33 -0600 | [diff] [blame^] | 578 | if result_counts[SymbolFile.ERROR]: |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 579 | logging.PrintBuildbotStepWarnings() |
Chris Ching | 9190803 | 2016-09-27 16:55:33 -0600 | [diff] [blame^] | 580 | logging.warning('%d non-recoverable upload errors', |
| 581 | result_counts[SymbolFile.ERROR]) |
| 582 | |
| 583 | if result_counts[SymbolFile.INITIAL]: |
| 584 | logging.PrintBuildbotStepWarnings() |
| 585 | logging.warning('%d upload(s) were skipped because of excessive errors', |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 586 | result_counts[SymbolFile.INITIAL]) |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 587 | |
| 588 | if failed_list is not None: |
| 589 | with open(failed_list, 'w') as fl: |
| 590 | for s in upload_failures: |
| 591 | fl.write('%s\n' % s.display_path) |
| 592 | |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 593 | return result_counts[SymbolFile.INITIAL] + result_counts[SymbolFile.ERROR] |
| 594 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 595 | |
| 596 | def UploadSymbols(sym_paths, upload_url, product_name, dedupe_namespace=None, |
| 597 | failed_list=None, upload_limit=None, strip_cfi=None): |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 598 | """Upload all the generated symbols for |board| to the crash server |
| 599 | |
| 600 | Args: |
Mike Frysinger | 9b2ff5c | 2013-11-22 10:01:12 -0500 | [diff] [blame] | 601 | sym_paths: Specific symbol files (or dirs of sym files) to upload, |
| 602 | otherwise search |breakpad_dir| |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 603 | upload_url: URL of crash server to upload too. |
| 604 | product_name: A string for crash server stats purposes. |
| 605 | Usually 'ChromeOS' or 'Android'. |
| 606 | dedupe_namespace: None for no deduping, or string namespace in isolate. |
| 607 | failed_list: A filename at which to write out a list of our failed uploads. |
| 608 | upload_limit: Integer listing how many files to upload. None for no limit. |
| 609 | strip_cfi: File size at which we strip out CFI data. None for no limit. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 610 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 611 | Returns: |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 612 | The number of errors that were encountered. |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 613 | """ |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 614 | # Note: This method looks like each step of processing is performed |
| 615 | # sequentially for all SymbolFiles, but instead each step is a generator that |
| 616 | # produces the next iteration only when it's read. This means that (except for |
| 617 | # some batching) each SymbolFile goes through all of these steps before the |
| 618 | # next one is processed at all. |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 619 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 620 | # This is used to hold striped |
| 621 | with osutils.TempDir(prefix='upload_symbols.') as tempdir: |
| 622 | symbols = FindSymbolFiles(tempdir, sym_paths) |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 623 | |
Don Garrett | 1bc1e10 | 2016-07-06 17:06:10 -0700 | [diff] [blame] | 624 | # Sort all of our symbols so the largest ones (probably the most important) |
| 625 | # are processed first. |
| 626 | symbols = list(symbols) |
| 627 | symbols.sort(key=lambda s: s.FileSize(), reverse=True) |
| 628 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 629 | if upload_limit is not None: |
| 630 | # Restrict symbols processed to the limit. |
| 631 | symbols = itertools.islice(symbols, None, upload_limit) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 632 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 633 | # Strip CFI, if needed. |
| 634 | symbols = (AdjustSymbolFileSize(s, tempdir, strip_cfi) for s in symbols) |
Mike Frysinger | 8ec8c50 | 2014-02-10 00:19:13 -0500 | [diff] [blame] | 635 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 636 | # Skip duplicates. |
| 637 | if dedupe_namespace: |
| 638 | symbols = FindDuplicates(symbols, dedupe_namespace) |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 639 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 640 | # Perform uploads |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 641 | symbols = PerformSymbolsFileUpload(symbols, upload_url, product_name) |
Mike Frysinger | d42e5f0 | 2014-03-14 11:19:37 -0400 | [diff] [blame] | 642 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 643 | # Record for future deduping. |
| 644 | if dedupe_namespace: |
| 645 | symbols = PostForDeduplication(symbols, dedupe_namespace) |
Mike Frysinger | d42e5f0 | 2014-03-14 11:19:37 -0400 | [diff] [blame] | 646 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 647 | # Log the final results, and consume the symbols generator fully. |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 648 | failures = ReportResults(symbols, failed_list) |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 649 | |
Don Garrett | deb2e03 | 2016-07-06 16:44:14 -0700 | [diff] [blame] | 650 | return failures |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 651 | |
| 652 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 653 | def main(argv): |
| 654 | parser = commandline.ArgumentParser(description=__doc__) |
| 655 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 656 | # TODO: Make sym_paths, breakpad_root, and root exclusive. |
| 657 | |
Mike Frysinger | d41938e | 2014-02-10 06:37:55 -0500 | [diff] [blame] | 658 | parser.add_argument('sym_paths', type='path_or_uri', nargs='*', default=None, |
| 659 | help='symbol file or directory or URL or tarball') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 660 | parser.add_argument('--board', default=None, |
Don Garrett | 747cc4b | 2015-10-07 14:48:48 -0700 | [diff] [blame] | 661 | help='Used to find default breakpad_root.') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 662 | parser.add_argument('--breakpad_root', type='path', default=None, |
Mike Frysinger | c5597f2 | 2014-11-27 15:39:15 -0500 | [diff] [blame] | 663 | help='full path to the breakpad symbol directory') |
| 664 | parser.add_argument('--root', type='path', default=None, |
| 665 | help='full path to the chroot dir') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 666 | parser.add_argument('--official_build', action='store_true', default=False, |
| 667 | help='point to official symbol server') |
Mike Frysinger | 3864754 | 2014-09-12 18:15:39 -0700 | [diff] [blame] | 668 | parser.add_argument('--server', type=str, default=None, |
| 669 | help='URI for custom symbol server') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 670 | parser.add_argument('--regenerate', action='store_true', default=False, |
| 671 | help='regenerate all symbols') |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 672 | parser.add_argument('--upload-limit', type=int, |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 673 | help='only upload # number of symbols') |
| 674 | parser.add_argument('--strip_cfi', type=int, |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 675 | default=DEFAULT_FILE_LIMIT, |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 676 | help='strip CFI data for files above this size') |
Mike Frysinger | 7f9be14 | 2014-01-15 02:16:42 -0500 | [diff] [blame] | 677 | parser.add_argument('--failed-list', type='path', |
| 678 | help='where to save a list of failed symbols') |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 679 | parser.add_argument('--dedupe', action='store_true', default=False, |
| 680 | help='use the swarming service to avoid re-uploading') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 681 | parser.add_argument('--yes', action='store_true', default=False, |
| 682 | help='answer yes to all prompts') |
Don Garrett | 747cc4b | 2015-10-07 14:48:48 -0700 | [diff] [blame] | 683 | parser.add_argument('--product_name', type=str, default='ChromeOS', |
| 684 | help='Produce Name for breakpad stats.') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 685 | |
| 686 | opts = parser.parse_args(argv) |
Mike Frysinger | 90e49ca | 2014-01-14 14:42:07 -0500 | [diff] [blame] | 687 | opts.Freeze() |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 688 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 689 | # Figure out the symbol files/directories to upload. |
| 690 | if opts.sym_paths: |
| 691 | sym_paths = opts.sym_paths |
| 692 | elif opts.breakpad_root: |
| 693 | sym_paths = [opts.breakpad_root] |
| 694 | elif opts.root: |
| 695 | if not opts.board: |
| 696 | raise ValueError('--board must be set if --root is used.') |
| 697 | breakpad_dir = cros_generate_breakpad_symbols.FindBreakpadDir(opts.board) |
| 698 | sym_paths = [os.path.join(opts.root, breakpad_dir.lstrip('/'))] |
| 699 | else: |
| 700 | raise ValueError('--sym_paths, --breakpad_root, or --root must be set.') |
| 701 | |
Don Garrett | 747cc4b | 2015-10-07 14:48:48 -0700 | [diff] [blame] | 702 | if opts.sym_paths or opts.breakpad_root: |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 703 | if opts.regenerate: |
Don Garrett | 747cc4b | 2015-10-07 14:48:48 -0700 | [diff] [blame] | 704 | cros_build_lib.Die('--regenerate may not be used with specific files, ' |
| 705 | 'or breakpad_root') |
Mike Frysinger | 9dcf9ae | 2013-08-10 15:17:09 -0400 | [diff] [blame] | 706 | else: |
| 707 | if opts.board is None: |
| 708 | cros_build_lib.Die('--board is required') |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 709 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 710 | # Figure out the dedupe namespace. |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 711 | dedupe_namespace = None |
| 712 | if opts.dedupe: |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 713 | if opts.official_build: |
Don Garrett | 747cc4b | 2015-10-07 14:48:48 -0700 | [diff] [blame] | 714 | dedupe_namespace = OFFICIAL_DEDUPE_NAMESPACE_TMPL % opts.product_name |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 715 | else: |
Don Garrett | 747cc4b | 2015-10-07 14:48:48 -0700 | [diff] [blame] | 716 | dedupe_namespace = STAGING_DEDUPE_NAMESPACE_TMPL % opts.product_name |
Mike Frysinger | 0c0efa2 | 2014-02-09 23:32:23 -0500 | [diff] [blame] | 717 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 718 | # Figure out which crash server to upload too. |
| 719 | upload_url = opts.server |
| 720 | if not upload_url: |
| 721 | if opts.official_build: |
| 722 | upload_url = OFFICIAL_UPLOAD_URL |
| 723 | else: |
| 724 | logging.warning('unofficial builds upload to the staging server') |
| 725 | upload_url = STAGING_UPLOAD_URL |
| 726 | |
| 727 | # Confirm we really want the long upload. |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 728 | if not opts.yes: |
Mike Frysinger | c5de960 | 2014-02-09 02:42:36 -0500 | [diff] [blame] | 729 | prolog = '\n'.join(textwrap.wrap(textwrap.dedent(""" |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 730 | Uploading symbols for an entire Chromium OS build is really only |
| 731 | necessary for release builds and in a few cases for developers |
| 732 | to debug problems. It will take considerable time to run. For |
| 733 | developer debugging purposes, consider instead passing specific |
| 734 | files to upload. |
Mike Frysinger | c5de960 | 2014-02-09 02:42:36 -0500 | [diff] [blame] | 735 | """), 80)).strip() |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 736 | if not cros_build_lib.BooleanPrompt( |
| 737 | prompt='Are you sure you want to upload all build symbols', |
Mike Frysinger | c5de960 | 2014-02-09 02:42:36 -0500 | [diff] [blame] | 738 | default=False, prolog=prolog): |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 739 | cros_build_lib.Die('better safe than sorry') |
| 740 | |
| 741 | ret = 0 |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 742 | |
| 743 | # Regenerate symbols from binaries. |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 744 | if opts.regenerate: |
Mike Frysinger | 69cb41d | 2013-08-11 20:08:19 -0400 | [diff] [blame] | 745 | ret += cros_generate_breakpad_symbols.GenerateBreakpadSymbols( |
| 746 | opts.board, breakpad_dir=opts.breakpad_root) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 747 | |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 748 | # Do the upload. |
| 749 | ret += UploadSymbols( |
| 750 | sym_paths=sym_paths, |
| 751 | upload_url=upload_url, |
| 752 | product_name=opts.product_name, |
| 753 | dedupe_namespace=dedupe_namespace, |
| 754 | failed_list=opts.failed_list, |
| 755 | upload_limit=opts.upload_limit, |
| 756 | strip_cfi=opts.strip_cfi) |
| 757 | |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 758 | if ret: |
Ralph Nathan | 5990042 | 2015-03-24 10:41:17 -0700 | [diff] [blame] | 759 | logging.error('encountered %i problem(s)', ret) |
Mike Frysinger | d5fcb3a | 2013-05-30 21:10:50 -0400 | [diff] [blame] | 760 | # Since exit(status) gets masked, clamp it to 1 so we don't inadvertently |
| 761 | # return 0 in case we are a multiple of the mask. |
Don Garrett | a28be6d | 2016-06-16 18:09:35 -0700 | [diff] [blame] | 762 | return 1 |