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

Side by Side Diff: build/android/tombstones.py

Issue 2577463003: Enable writing to logdog for tombstones.py. (Closed)
Patch Set: fixes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 100
97 def _DeviceAbiToArch(device_abi): 101 def _DeviceAbiToArch(device_abi):
98 # The order of this list is significant to find the more specific match (e.g., 102 # The order of this list is significant to find the more specific match (e.g.,
99 # arm64) before the less specific (e.g., arm). 103 # arm64) before the less specific (e.g., arm).
100 arches = ['arm64', 'arm', 'x86_64', 'x86_64', 'x86', 'mips'] 104 arches = ['arm64', 'arm', 'x86_64', 'x86_64', 'x86', 'mips']
101 for arch in arches: 105 for arch in arches:
102 if arch in device_abi: 106 if arch in device_abi:
103 return arch 107 return arch
104 raise RuntimeError('Unknown device ABI: %s' % device_abi) 108 raise RuntimeError('Unknown device ABI: %s' % device_abi)
105 109
110
106 def _ResolveSymbols(tombstone_data, include_stack, device_abi): 111 def _ResolveSymbols(tombstone_data, include_stack, device_abi):
107 """Run the stack tool for given tombstone input. 112 """Run the stack tool for given tombstone input.
108 113
109 Args: 114 Args:
110 tombstone_data: a list of strings of tombstone data. 115 tombstone_data: a list of strings of tombstone data.
111 include_stack: boolean whether to include stack data in output. 116 include_stack: boolean whether to include stack data in output.
112 device_abi: the default ABI of the device which generated the tombstone. 117 device_abi: the default ABI of the device which generated the tombstone.
113 118
114 Yields: 119 Yields:
115 A string for each line of resolved stack output. 120 A string for each line of resolved stack output.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 if len(tombstones) == 1: 168 if len(tombstones) == 1:
164 data = [_ResolveTombstone(tombstones[0])] 169 data = [_ResolveTombstone(tombstones[0])]
165 else: 170 else:
166 pool = multiprocessing.Pool(processes=jobs) 171 pool = multiprocessing.Pool(processes=jobs)
167 data = pool.map(_ResolveTombstone, tombstones) 172 data = pool.map(_ResolveTombstone, tombstones)
168 resolved_tombstones = [] 173 resolved_tombstones = []
169 for tombstone in data: 174 for tombstone in data:
170 resolved_tombstones.extend(tombstone) 175 resolved_tombstones.extend(tombstone)
171 return resolved_tombstones 176 return resolved_tombstones
172 177
178
173 def _GetTombstonesForDevice(device, resolve_all_tombstones, 179 def _GetTombstonesForDevice(device, resolve_all_tombstones,
174 include_stack_symbols, 180 include_stack_symbols,
175 wipe_tombstones): 181 wipe_tombstones):
176 """Returns a list of tombstones on a given device. 182 """Returns a list of tombstones on a given device.
177 183
178 Args: 184 Args:
179 device: An instance of DeviceUtils. 185 device: An instance of DeviceUtils.
180 resolve_all_tombstone: Whether to resolve every tombstone. 186 resolve_all_tombstone: Whether to resolve every tombstone.
181 include_stack_symbols: Whether to include symbols for stack data. 187 include_stack_symbols: Whether to include symbols for stack data.
182 wipe_tombstones: Whether to wipe tombstones. 188 wipe_tombstones: Whether to wipe tombstones.
(...skipping 26 matching lines...) Expand all
209 logging.info('%s: %s', str(device), entry) 215 logging.info('%s: %s', str(device), entry)
210 raise 216 raise
211 217
212 # Erase all the tombstones if desired. 218 # Erase all the tombstones if desired.
213 if wipe_tombstones: 219 if wipe_tombstones:
214 for tombstone_file, _ in all_tombstones: 220 for tombstone_file, _ in all_tombstones:
215 _EraseTombstone(device, tombstone_file) 221 _EraseTombstone(device, tombstone_file)
216 222
217 return ret 223 return ret
218 224
225
219 def ClearAllTombstones(device): 226 def ClearAllTombstones(device):
220 """Clear all tombstones in the device. 227 """Clear all tombstones in the device.
221 228
222 Args: 229 Args:
223 device: An instance of DeviceUtils. 230 device: An instance of DeviceUtils.
224 """ 231 """
225 all_tombstones = list(_ListTombstones(device)) 232 all_tombstones = list(_ListTombstones(device))
226 if not all_tombstones: 233 if not all_tombstones:
227 logging.warning('No tombstones to clear.') 234 logging.warning('No tombstones to clear.')
228 235
229 for tombstone_file, _ in all_tombstones: 236 for tombstone_file, _ in all_tombstones:
230 _EraseTombstone(device, tombstone_file) 237 _EraseTombstone(device, tombstone_file)
231 238
239
232 def ResolveTombstones(device, resolve_all_tombstones, include_stack_symbols, 240 def ResolveTombstones(device, resolve_all_tombstones, include_stack_symbols,
233 wipe_tombstones, jobs=4): 241 wipe_tombstones, jobs=4):
234 """Resolve tombstones in the device. 242 """Resolve tombstones in the device.
235 243
236 Args: 244 Args:
237 device: An instance of DeviceUtils. 245 device: An instance of DeviceUtils.
238 resolve_all_tombstone: Whether to resolve every tombstone. 246 resolve_all_tombstone: Whether to resolve every tombstone.
239 include_stack_symbols: Whether to include symbols for stack data. 247 include_stack_symbols: Whether to include symbols for stack data.
240 wipe_tombstones: Whether to wipe tombstones. 248 wipe_tombstones: Whether to wipe tombstones.
241 jobs: Number of jobs to use when processing multiple crash stacks. 249 jobs: Number of jobs to use when processing multiple crash stacks.
250
251 Returns:
252 A list of resolved tombstones.
242 """ 253 """
243 return _ResolveTombstones(jobs, 254 return _ResolveTombstones(jobs,
244 _GetTombstonesForDevice(device, 255 _GetTombstonesForDevice(device,
245 resolve_all_tombstones, 256 resolve_all_tombstones,
246 include_stack_symbols, 257 include_stack_symbols,
247 wipe_tombstones)) 258 wipe_tombstones))
248 259
260
261 def LogdogTombstones(resolved_tombstones, stream_name):
262 """Save resolved tombstones to logdog and return the url.
263
264 Args:
265 stream_name: The name of the logdog stream that records tombstones.
266 resolved_tombstones: Resolved tombstones (output of ResolveTombstones).
267
268 Returns:
269 A url link to the recorded tombstones.
270 """
271 try:
272 tombstones_url = ''
273 stream_client = bootstrap.ButlerBootstrap.probe().stream_client()
274 with stream_client.open_text(stream_name) as logdog_stream:
jbudorick 2016/12/14 17:58:44 stream_client.text(stream_name), not stream_client
BigBossZhiling 2016/12/14 21:42:30 Done.
275 for tombstones_line in resolved_tombstones:
276 logdog_stream.write(tombstones_line + '\n')
277 tombstones_url = logdog_stream.get_viewer_url(stream_name)
278 except bootstrap.NotBootstrappedError:
279 logging.exception('Error not bootstrapped. Failed to start logdog')
280 except (KeyError, ValueError) as e:
281 logging.exception('Error when creating stream_client/stream: %s.', e)
282 except Exception as e: # pylint: disable=broad-except
283 logging.exception('Unknown Error: %s.', e)
284 return tombstones_url
285
286
249 def main(): 287 def main():
250 custom_handler = logging.StreamHandler(sys.stdout) 288 custom_handler = logging.StreamHandler(sys.stdout)
251 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) 289 custom_handler.setFormatter(run_tests_helper.CustomFormatter())
252 logging.getLogger().addHandler(custom_handler) 290 logging.getLogger().addHandler(custom_handler)
253 logging.getLogger().setLevel(logging.INFO) 291 logging.getLogger().setLevel(logging.INFO)
254 292
255 parser = argparse.ArgumentParser() 293 parser = argparse.ArgumentParser()
256 parser.add_argument('--device', 294 parser.add_argument('--device',
257 help='The serial number of the device. If not specified ' 295 help='The serial number of the device. If not specified '
258 'will use all devices.') 296 'will use all devices.')
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 # This must be done serially because strptime can hit a race condition if 331 # This must be done serially because strptime can hit a race condition if
294 # used for the first time in a multithreaded environment. 332 # used for the first time in a multithreaded environment.
295 # http://bugs.python.org/issue7980 333 # http://bugs.python.org/issue7980
296 for device in devices: 334 for device in devices:
297 resolved_tombstones = ResolveTombstones( 335 resolved_tombstones = ResolveTombstones(
298 device, args.all_tombstones, 336 device, args.all_tombstones,
299 args.stack, args.wipe_tombstones, args.jobs) 337 args.stack, args.wipe_tombstones, args.jobs)
300 for line in resolved_tombstones: 338 for line in resolved_tombstones:
301 logging.info(line) 339 logging.info(line)
302 340
341
303 if __name__ == '__main__': 342 if __name__ == '__main__':
304 sys.exit(main()) 343 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698