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

Side by Side Diff: appengine/findit/crash/stacktrace.py

Issue 2518663002: Converting various classes to namedtuples (Closed)
Patch Set: addressing nits Created 4 years, 1 month 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
OLDNEW
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 import logging 6 import logging
6 import re 7 import re
7 8
8 from crash import parse_util 9 from crash import parse_util
9 from crash.type_enums import CallStackFormatType 10 from crash.type_enums import CallStackFormatType
10 from crash.type_enums import CallStackLanguageType 11 from crash.type_enums import CallStackLanguageType
11 12
12 # Used to parse a line into StackFrame of a Callstack. 13 # Used to parse a line into StackFrame of a Callstack.
13 CALLSTACK_FORMAT_TO_PATTERN = { 14 CALLSTACK_FORMAT_TO_PATTERN = {
14 CallStackFormatType.JAVA: re.compile( 15 CallStackFormatType.JAVA: re.compile(
15 r'at ([A-Za-z0-9$._<>]+)\(\w+(\.java)?:(\d+)\)'), 16 r'at ([A-Za-z0-9$._<>]+)\(\w+(\.java)?:(\d+)\)'),
16 CallStackFormatType.SYZYASAN: re.compile( 17 CallStackFormatType.SYZYASAN: re.compile(
17 r'(CF: )?(.*?)( \(FPO: .*\) )?( \(CONV: .*\) )?\[(.*) @ (\d+)\]'), 18 r'(CF: )?(.*?)( \(FPO: .*\) )?( \(CONV: .*\) )?\[(.*) @ (\d+)\]'),
18 CallStackFormatType.DEFAULT: re.compile( 19 CallStackFormatType.DEFAULT: re.compile(
19 r'(.*?):(\d+)(:\d+)?$') 20 r'(.*?):(\d+)(:\d+)?$')
20 } 21 }
21 22
22 FRAME_INDEX_PATTERN = re.compile(r'\s*#(\d+)\s.*') 23 FRAME_INDEX_PATTERN = re.compile(r'\s*#(\d+)\s.*')
23 24
24 25
25 class StackFrame(object): 26 class StackFrame(namedtuple('StackFrame',
27 ['index', 'dep_path', 'function', 'file_path', 'raw_file_path',
28 'crashed_line_numbers', 'repo_url'])):
26 """Represents a frame in a stacktrace. 29 """Represents a frame in a stacktrace.
27 30
28 Attributes: 31 Attributes:
29 index (int): Index shown in the stacktrace if a stackframe line looks like 32 index (int): Index shown in the stacktrace if a stackframe line looks like
30 this - '#0 ...', else use the index in the callstack list. 33 this - '#0 ...', else use the index in the callstack list.
31 dep_path (str): Path of the dep this frame represents, for example, 34 dep_path (str): Path of the dep this frame represents, for example,
32 'src/', 'src/v8', 'src/skia'...etc. 35 'src/', 'src/v8', 'src/skia'...etc.
33 function (str): Function that caused the crash. 36 function (str): Function that caused the crash.
34 file_path (str): Normalized path of the crashed file, with parts dep_path 37 file_path (str): Normalized path of the crashed file, with parts dep_path
35 and parts before it stripped, for example, api.cc. 38 and parts before it stripped, for example, api.cc.
36 raw_file_path (str): Normalized original path of the crashed file, 39 raw_file_path (str): Normalized original path of the crashed file,
37 for example, /b/build/slave/mac64/build/src/v8/src/heap/ 40 for example, /b/build/slave/mac64/build/src/v8/src/heap/
38 incremental-marking-job.cc. 41 incremental-marking-job.cc.
39 crashed_line_numbers (list): Line numbers of the file that caused the crash. 42 crashed_line_numbers (list): Line numbers of the file that caused the crash.
40 repo_url (str): Repo url of this frame. 43 repo_url (str): Repo url of this frame.
41 """ 44 """
42 def __init__(self, index, dep_path, function, 45 __slots__ = ()
43 file_path, raw_file_path, crashed_line_numbers, 46
44 repo_url=None): 47 def __new__(cls, index, dep_path, function, file_path, raw_file_path,
45 self.index = index 48 crashed_line_numbers, repo_url=None):
46 self.dep_path = dep_path 49 return super(cls, StackFrame).__new__(cls,
47 self.function = function 50 index, dep_path, function, file_path, raw_file_path,
48 self.file_path = file_path 51 crashed_line_numbers, repo_url)
49 self.raw_file_path = raw_file_path
50 self.crashed_line_numbers = crashed_line_numbers
51 self.repo_url = repo_url
52 52
53 def ToString(self): 53 def ToString(self):
54 frame_str = '#%d in %s @ %s' % (self.index, self.function, self.file_path) 54 frame_str = '#%d in %s @ %s' % (self.index, self.function, self.file_path)
55 if self.crashed_line_numbers: 55 if self.crashed_line_numbers:
56 frame_str += ':%d' % self.crashed_line_numbers[0] 56 frame_str += ':%d' % self.crashed_line_numbers[0]
57 57
58 # For example, if crashed_line_numbers is [61], returns '... f.cc:61', 58 # For example, if crashed_line_numbers is [61], returns '... f.cc:61',
59 # if is [61, 62], returns '... f.cc:61:1' 59 # if is [61, 62], returns '... f.cc:61:1'
60 if len(self.crashed_line_numbers) > 1: 60 if len(self.crashed_line_numbers) > 1:
61 frame_str += ':%d' % (len(self.crashed_line_numbers) - 1) 61 frame_str += ':%d' % (len(self.crashed_line_numbers) - 1)
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 callstack[:] = callstack[index:] 211 callstack[:] = callstack[index:]
212 self._crash_stack = callstack 212 self._crash_stack = callstack
213 break 213 break
214 214
215 # If there is no signature callstack, fall back to set crash stack using 215 # If there is no signature callstack, fall back to set crash stack using
216 # the first least priority callstack. 216 # the first least priority callstack.
217 if self._crash_stack is None: 217 if self._crash_stack is None:
218 self._crash_stack = sorted(self, key=lambda stack: stack.priority)[0] 218 self._crash_stack = sorted(self, key=lambda stack: stack.priority)[0]
219 219
220 return self._crash_stack 220 return self._crash_stack
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698