| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from collections import namedtuple | 5 from collections import namedtuple |
| 6 import copy | 6 import copy |
| 7 import logging | 7 import logging |
| 8 import math | 8 import math |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 """Converts ``CallStackBuffer`` object to ``CallStack`` object. | 268 """Converts ``CallStackBuffer`` object to ``CallStack`` object. |
| 269 | 269 |
| 270 Note, some metadata will be discarded after the conversion. | 270 Note, some metadata will be discarded after the conversion. |
| 271 """ | 271 """ |
| 272 if not self: | 272 if not self: |
| 273 return None | 273 return None |
| 274 | 274 |
| 275 return CallStack(self.priority, tuple(self.frames), | 275 return CallStack(self.priority, tuple(self.frames), |
| 276 self.format_type, self.language_type) | 276 self.format_type, self.language_type) |
| 277 | 277 |
| 278 @staticmethod |
| 279 def FromStartOfCallStack(start_of_callstack): |
| 280 """Constructs a ``CallStackBuffer`` from a ``StartOfCallStack``.""" |
| 281 if not start_of_callstack: |
| 282 return None |
| 283 |
| 284 return CallStackBuffer( |
| 285 priority=start_of_callstack.priority, |
| 286 format_type=start_of_callstack.format_type, |
| 287 language_type=start_of_callstack.language_type, |
| 288 metadata=start_of_callstack.metadata) |
| 289 |
| 278 | 290 |
| 279 # N.B., because ``list`` is mutable it isn't hashable, thus cannot be | 291 # N.B., because ``list`` is mutable it isn't hashable, thus cannot be |
| 280 # used as a key in a dict. Because we want to usecallstacks as keys (for | 292 # used as a key in a dict. Because we want to usecallstacks as keys (for |
| 281 # memoization) we has-a tuple rather than is-a list. | 293 # memoization) we has-a tuple rather than is-a list. |
| 282 # TODO(http://crbug.com/644476): this class needs a better name. | 294 # TODO(http://crbug.com/644476): this class needs a better name. |
| 283 class Stacktrace(namedtuple('Stacktrace', ['stacks', 'crash_stack'])): | 295 class Stacktrace(namedtuple('Stacktrace', ['stacks', 'crash_stack'])): |
| 284 """A collection of callstacks which together provide a trace of what happened. | 296 """A collection of callstacks which together provide a trace of what happened. |
| 285 | 297 |
| 286 For instance, when doing memory debugging we will have callstacks for | 298 For instance, when doing memory debugging we will have callstacks for |
| 287 (1) when the crash occurred, (2) when the object causing the crash | 299 (1) when the crash occurred, (2) when the object causing the crash |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 for stack_buffer in self.stacks] | 399 for stack_buffer in self.stacks] |
| 388 | 400 |
| 389 if crash_stack_index is None: | 401 if crash_stack_index is None: |
| 390 # If there is no signature callstack, fall back to set crash stack using | 402 # If there is no signature callstack, fall back to set crash stack using |
| 391 # the first least priority callstack. | 403 # the first least priority callstack. |
| 392 crash_stack = min(callstacks, key=lambda stack: stack.priority) | 404 crash_stack = min(callstacks, key=lambda stack: stack.priority) |
| 393 else: | 405 else: |
| 394 crash_stack = callstacks[crash_stack_index] | 406 crash_stack = callstacks[crash_stack_index] |
| 395 | 407 |
| 396 return Stacktrace(tuple(callstacks), crash_stack) | 408 return Stacktrace(tuple(callstacks), crash_stack) |
| OLD | NEW |