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. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 if len(tombstones) == 1: | 163 if len(tombstones) == 1: |
164 data = [_ResolveTombstone(tombstones[0])] | 164 data = [_ResolveTombstone(tombstones[0])] |
165 else: | 165 else: |
166 pool = multiprocessing.Pool(processes=jobs) | 166 pool = multiprocessing.Pool(processes=jobs) |
167 data = pool.map(_ResolveTombstone, tombstones) | 167 data = pool.map(_ResolveTombstone, tombstones) |
168 for tombstone in data: | 168 for tombstone in data: |
169 for line in tombstone: | 169 for line in tombstone: |
170 logging.info(line) | 170 logging.info(line) |
171 | 171 |
172 | 172 |
173 def _GetTombstonesForDevice(device, args): | 173 def _GetTombstonesForDevice(device, resolve_all_tombstone, stack, |
174 wipe_tombstones): | |
174 """Returns a list of tombstones on a given device. | 175 """Returns a list of tombstones on a given device. |
175 | 176 |
176 Args: | 177 Args: |
177 device: An instance of DeviceUtils. | 178 device: An instance of DeviceUtils. |
178 args: command line arguments | 179 every_tombstone: Whether to resolve every tombstone. |
mikecase (-- gone --)
2016/08/02 00:48:30
update name
BigBossZhiling
2016/08/02 17:17:04
Done.
| |
180 stack: Stack. | |
mikecase (-- gone --)
2016/08/02 00:48:31
Same comment as before.
At least add the datatype
BigBossZhiling
2016/08/02 17:17:04
Done.
| |
181 wipe_tombstones: Whether to wipe tombstones. | |
179 """ | 182 """ |
180 ret = [] | 183 ret = [] |
181 all_tombstones = list(_ListTombstones(device)) | 184 all_tombstones = list(_ListTombstones(device)) |
182 if not all_tombstones: | 185 if not all_tombstones: |
183 logging.warning('No tombstones.') | 186 logging.warning('No tombstones.') |
184 return ret | 187 return ret |
185 | 188 |
186 # Sort the tombstones in date order, descending | 189 # Sort the tombstones in date order, descending |
187 all_tombstones.sort(cmp=lambda a, b: cmp(b[1], a[1])) | 190 all_tombstones.sort(cmp=lambda a, b: cmp(b[1], a[1])) |
188 | 191 |
189 # Only resolve the most recent unless --all-tombstones given. | 192 # Only resolve the most recent unless --all-tombstones given. |
190 tombstones = all_tombstones if args.all_tombstones else [all_tombstones[0]] | 193 tombstones = all_tombstones if resolve_all_tombstone else [all_tombstones[0]] |
191 | 194 |
192 device_now = _GetDeviceDateTime(device) | 195 device_now = _GetDeviceDateTime(device) |
193 try: | 196 try: |
194 for tombstone_file, tombstone_time in tombstones: | 197 for tombstone_file, tombstone_time in tombstones: |
195 ret += [{'serial': str(device), | 198 ret += [{'serial': str(device), |
196 'device_abi': device.product_cpu_abi, | 199 'device_abi': device.product_cpu_abi, |
197 'device_now': device_now, | 200 'device_now': device_now, |
198 'time': tombstone_time, | 201 'time': tombstone_time, |
199 'file': tombstone_file, | 202 'file': tombstone_file, |
200 'stack': args.stack, | 203 'stack': stack, |
201 'data': _GetTombstoneData(device, tombstone_file)}] | 204 'data': _GetTombstoneData(device, tombstone_file)}] |
202 except device_errors.CommandFailedError: | 205 except device_errors.CommandFailedError: |
203 for entry in device.StatDirectory( | 206 for entry in device.StatDirectory( |
204 '/data/tombstones', as_root=True, timeout=60): | 207 '/data/tombstones', as_root=True, timeout=60): |
205 logging.info('%s: %s', str(device), entry) | 208 logging.info('%s: %s', str(device), entry) |
206 raise | 209 raise |
207 | 210 |
208 # Erase all the tombstones if desired. | 211 # Erase all the tombstones if desired. |
209 if args.wipe_tombstones: | 212 if wipe_tombstones: |
210 for tombstone_file, _ in all_tombstones: | 213 for tombstone_file, _ in all_tombstones: |
211 _EraseTombstone(device, tombstone_file) | 214 _EraseTombstone(device, tombstone_file) |
212 | 215 |
213 return ret | 216 return ret |
214 | 217 |
218 def ClearAllTombstones(device): | |
219 """Clear all tombstones in the device. | |
220 | |
221 Args: | |
222 device: An instance of DeviceUtils. | |
223 """ | |
224 all_tombstones = list(_ListTombstones(device)) | |
225 if not all_tombstones: | |
226 logging.warning('No tombstones to clear.') | |
227 | |
228 for tombstone_file, _ in all_tombstones: | |
229 _EraseTombstone(device, tombstone_file) | |
230 | |
231 def ResolveAllTombstones(device, all_tombstones, stack, wipe_tombstones, | |
232 jobs=4): | |
233 return _ResolveTombstones(jobs, | |
234 _GetTombstonesForDevice(device, | |
235 all_tombstones, | |
236 stack, wipe_tombstones)) | |
215 | 237 |
216 def main(): | 238 def main(): |
217 custom_handler = logging.StreamHandler(sys.stdout) | 239 custom_handler = logging.StreamHandler(sys.stdout) |
218 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) | 240 custom_handler.setFormatter(run_tests_helper.CustomFormatter()) |
219 logging.getLogger().addHandler(custom_handler) | 241 logging.getLogger().addHandler(custom_handler) |
220 logging.getLogger().setLevel(logging.INFO) | 242 logging.getLogger().setLevel(logging.INFO) |
221 | 243 |
222 parser = argparse.ArgumentParser() | 244 parser = argparse.ArgumentParser() |
223 parser.add_argument('--device', | 245 parser.add_argument('--device', |
224 help='The serial number of the device. If not specified ' | 246 help='The serial number of the device. If not specified ' |
(...skipping 28 matching lines...) Expand all Loading... | |
253 constants.CheckOutputDirectory() | 275 constants.CheckOutputDirectory() |
254 | 276 |
255 if args.device: | 277 if args.device: |
256 devices = [device_utils.DeviceUtils(args.device)] | 278 devices = [device_utils.DeviceUtils(args.device)] |
257 else: | 279 else: |
258 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) | 280 devices = device_utils.DeviceUtils.HealthyDevices(blacklist) |
259 | 281 |
260 # This must be done serially because strptime can hit a race condition if | 282 # This must be done serially because strptime can hit a race condition if |
261 # used for the first time in a multithreaded environment. | 283 # used for the first time in a multithreaded environment. |
262 # http://bugs.python.org/issue7980 | 284 # http://bugs.python.org/issue7980 |
263 tombstones = [] | |
264 for device in devices: | 285 for device in devices: |
265 tombstones += _GetTombstonesForDevice(device, args) | 286 ResolveAllTombstones(device, args.all_tombstones, |
266 | 287 args.stack, args.wipe_tombstones, args.jobs) |
267 _ResolveTombstones(args.jobs, tombstones) | |
268 | |
269 | 288 |
270 if __name__ == '__main__': | 289 if __name__ == '__main__': |
271 sys.exit(main()) | 290 sys.exit(main()) |
OLD | NEW |