Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 # | 6 # |
| 7 # Find the most recent tombstone file(s) on all connected devices | 7 # Find the most recent tombstone file(s) on all connected devices |
| 8 # and prints their stacks. | 8 # and prints their stacks. |
| 9 # | 9 # |
| 10 # Assumes tombstone file was created with current symbols. | 10 # Assumes tombstone file was created with current symbols. |
| 11 | 11 |
| 12 import argparse | 12 import argparse |
| 13 import datetime | 13 import datetime |
| 14 import logging | 14 import logging |
| 15 import multiprocessing | 15 import multiprocessing |
| 16 import os | 16 import os |
| 17 import re | 17 import re |
| 18 import subprocess | 18 import subprocess |
| 19 import sys | 19 import sys |
| 20 | 20 |
| 21 import devil_chromium | 21 import devil_chromium |
| 22 | 22 |
| 23 from devil.android import device_blacklist | 23 from devil.android import device_blacklist |
| 24 from devil.android import device_errors | 24 from devil.android import device_errors |
| 25 from devil.android import device_utils | 25 from devil.android import device_utils |
| 26 from devil.utils import run_tests_helper | 26 from devil.utils import run_tests_helper |
| 27 from pylib import constants | 27 from pylib import constants |
| 28 | 28 |
| 29 sys.path.insert(0, os.path.abspath(os.path.join( | |
| 30 constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client'))) | |
| 31 from libs.logdog import bootstrap # pylint: disable=import-error | |
| 32 | |
| 29 | 33 |
| 30 _TZ_UTC = {'TZ': 'UTC'} | 34 _TZ_UTC = {'TZ': 'UTC'} |
| 31 | 35 |
| 32 | 36 |
| 33 def _ListTombstones(device): | 37 def _ListTombstones(device): |
| 34 """List the tombstone files on the device. | 38 """List the tombstone files on the device. |
| 35 | 39 |
| 36 Args: | 40 Args: |
| 37 device: An instance of DeviceUtils. | 41 device: An instance of DeviceUtils. |
| 38 | 42 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 device: An instance of DeviceUtils. | 227 device: An instance of DeviceUtils. |
| 224 """ | 228 """ |
| 225 all_tombstones = list(_ListTombstones(device)) | 229 all_tombstones = list(_ListTombstones(device)) |
| 226 if not all_tombstones: | 230 if not all_tombstones: |
| 227 logging.warning('No tombstones to clear.') | 231 logging.warning('No tombstones to clear.') |
| 228 | 232 |
| 229 for tombstone_file, _ in all_tombstones: | 233 for tombstone_file, _ in all_tombstones: |
| 230 _EraseTombstone(device, tombstone_file) | 234 _EraseTombstone(device, tombstone_file) |
| 231 | 235 |
| 232 def ResolveTombstones(device, resolve_all_tombstones, include_stack_symbols, | 236 def ResolveTombstones(device, resolve_all_tombstones, include_stack_symbols, |
| 233 wipe_tombstones, jobs=4): | 237 wipe_tombstones, jobs=4, save_to_logdog=False, |
| 238 stream_name=None): | |
| 234 """Resolve tombstones in the device. | 239 """Resolve tombstones in the device. |
| 235 | 240 |
| 236 Args: | 241 Args: |
| 237 device: An instance of DeviceUtils. | 242 device: An instance of DeviceUtils. |
| 238 resolve_all_tombstone: Whether to resolve every tombstone. | 243 resolve_all_tombstone: Whether to resolve every tombstone. |
| 239 include_stack_symbols: Whether to include symbols for stack data. | 244 include_stack_symbols: Whether to include symbols for stack data. |
| 240 wipe_tombstones: Whether to wipe tombstones. | 245 wipe_tombstones: Whether to wipe tombstones. |
| 241 jobs: Number of jobs to use when processing multiple crash stacks. | 246 jobs: Number of jobs to use when processing multiple crash stacks. |
| 247 save_to_logdog: Whether will save tombstones to logdog. | |
| 248 stream_name: The name of the logdog stream that records tombstones. | |
| 242 """ | 249 """ |
| 243 return _ResolveTombstones(jobs, | 250 tombstones = _ResolveTombstones(jobs, |
| 244 _GetTombstonesForDevice(device, | 251 _GetTombstonesForDevice( |
| 245 resolve_all_tombstones, | 252 device, |
| 246 include_stack_symbols, | 253 resolve_all_tombstones, |
| 247 wipe_tombstones)) | 254 include_stack_symbols, |
| 255 wipe_tombstones)) | |
| 256 if not save_to_logdog or not stream_name: | |
| 257 return tombstones | |
| 258 else: | |
|
jbudorick
2016/12/14 01:34:04
This should be handled by a separate function that
BigBossZhiling
2016/12/14 17:08:21
Done.
| |
| 259 try: | |
| 260 tombstones_url = '' | |
| 261 stream_client = bootstrap.ButlerBootstrap.probe().stream_client() | |
| 262 logdog_stream = stream_client.open_text(stream_name) | |
| 263 for tombstones_line in tombstones: | |
| 264 logdog_stream.write(tombstones_line + '\n') | |
| 265 tombstones_url = logdog_stream.get_viewer_url(stream_name) | |
| 266 logdog_stream.close() | |
| 267 except bootstrap.NotBootstrappedError: | |
| 268 logging.exception('Error not bootstrapped. Failed to start logdog') | |
| 269 except (KeyError, ValueError) as e: | |
| 270 logging.exception('Error when creating stream_client/stream: %s.', e) | |
| 271 except Exception as e: # pylint: disable=broad-except | |
| 272 logging.exception('Unknown Error: %s.', e) | |
| 273 return tombstones_url | |
| 248 | 274 |
| 249 def main(): | 275 def main(): |
| 250 custom_handler = logging.StreamHandler(sys.stdout) | 276 custom_handler = logging.StreamHandler(sys.stdout) |
| 251 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) | 277 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) |
| 252 logging.getLogger().addHandler(custom_handler) | 278 logging.getLogger().addHandler(custom_handler) |
| 253 logging.getLogger().setLevel(logging.INFO) | 279 logging.getLogger().setLevel(logging.INFO) |
| 254 | 280 |
| 255 parser = argparse.ArgumentParser() | 281 parser = argparse.ArgumentParser() |
| 256 parser.add_argument('--device', | 282 parser.add_argument('--device', |
| 257 help='The serial number of the device. If not specified ' | 283 help='The serial number of the device. If not specified ' |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 # http://bugs.python.org/issue7980 | 321 # http://bugs.python.org/issue7980 |
| 296 for device in devices: | 322 for device in devices: |
| 297 resolved_tombstones = ResolveTombstones( | 323 resolved_tombstones = ResolveTombstones( |
| 298 device, args.all_tombstones, | 324 device, args.all_tombstones, |
| 299 args.stack, args.wipe_tombstones, args.jobs) | 325 args.stack, args.wipe_tombstones, args.jobs) |
| 300 for line in resolved_tombstones: | 326 for line in resolved_tombstones: |
| 301 logging.info(line) | 327 logging.info(line) |
| 302 | 328 |
| 303 if __name__ == '__main__': | 329 if __name__ == '__main__': |
| 304 sys.exit(main()) | 330 sys.exit(main()) |
| OLD | NEW |