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: appengine/findit/crash/chromecrash_parser.py

Issue 2562623004: Making CallStack immutable, so it can be hashable (Closed)
Patch Set: Addressing nits 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
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 import math
5 import re 6 import re
6 7
7 from crash.callstack_filters import FilterInlineFunctionFrames 8 from crash.callstack_filters import FilterInlineFunctionFrames
8 from crash.stacktrace import CallStack 9 from crash.stacktrace import CallStack
10 from crash.stacktrace import StackFrame
9 from crash.stacktrace import Stacktrace 11 from crash.stacktrace import Stacktrace
10 from crash.stacktrace_parser import StacktraceParser 12 from crash.stacktrace_parser import StacktraceParser
11 from crash.type_enums import CallStackFormatType, CallStackLanguageType 13 from crash.type_enums import CallStackFormatType, CallStackLanguageType
12 14
13 15
14 FRACAS_CALLSTACK_START_PATTERN = re.compile(r'CRASHED \[(.*) @ 0x(.*)\]') 16 FRACAS_CALLSTACK_START_PATTERN = re.compile(r'CRASHED \[(.*) @ 0x(.*)\]')
15 JAVA_CALLSTACK_START_PATTERN = re.compile(r'\(JAVA\) CRASHED \[(.*) @ 0x(.*)\]') 17 JAVA_CALLSTACK_START_PATTERN = re.compile(r'\(JAVA\) CRASHED \[(.*) @ 0x(.*)\]')
16 18
17 19
18 class ChromeCrashParser(StacktraceParser): 20 class ChromeCrashParser(StacktraceParser):
19 21
20 def Parse(self, stacktrace_string, deps, signature=None): 22 def Parse(self, stacktrace_string, deps, signature=None):
21 """Parse fracas stacktrace string into Stacktrace instance.""" 23 """Parse fracas stacktrace string into Stacktrace instance."""
22 stacktrace = Stacktrace() 24 callstacks = []
23 # TODO(http://crbug.com/644441): testing against infinity is confusing. 25 # TODO(http://crbug.com/644441): testing against infinity is confusing.
24 callstack = CallStack(float('inf')) 26 stack_priority = float('inf')
27 format_type = None
28 language_type = None
29 frame_list = []
25 30
26 for line in stacktrace_string.splitlines(): 31 for line in stacktrace_string.splitlines():
27 is_new_callstack, stack_priority, format_type, language_type = ( 32 is_new_callstack, this_priority, this_format_type, this_language_type = (
28 self._IsStartOfNewCallStack(line)) 33 self._IsStartOfNewCallStack(line))
29 34
30 if is_new_callstack: 35 if is_new_callstack:
31 # If the callstack is not the initial one or empty, add it 36 # If the callstack is not the initial one or empty, add it
32 # to stacktrace. 37 # to stacktrace.
33 if callstack.priority != float('inf') and callstack: 38 if not math.isinf(stack_priority) and frame_list:
34 stacktrace.append(callstack) 39 callstacks.append(CallStack(stack_priority, format_type=format_type,
40 language_type=language_type, frame_list=frame_list))
35 41
36 callstack = CallStack(stack_priority, format_type, language_type) 42 stack_priority = this_priority
43 format_type = this_format_type
44 language_type = this_language_type
45 frame_list = []
37 else: 46 else:
38 callstack.ParseLine(line, deps) 47 frame = StackFrame.Parse(language_type, format_type, line, deps,
48 len(frame_list))
49 if frame is not None:
50 frame_list.append(frame)
39 51
40 if callstack.priority != float('inf') and callstack: 52 if not math.isinf(stack_priority) and frame_list:
41 stacktrace.append(callstack) 53 callstacks.append(CallStack(stack_priority, format_type=format_type,
54 language_type=language_type, frame_list=frame_list))
42 55
43 # Filter all the frames before signature frame. 56 # Filter all the frames before signature frame.
44 if stacktrace: 57 return Stacktrace(map(FilterInlineFunctionFrames, callstacks))
45 stacktrace = Stacktrace(map(FilterInlineFunctionFrames, stacktrace))
46
47 return stacktrace
48 58
49 def _IsStartOfNewCallStack(self, line): 59 def _IsStartOfNewCallStack(self, line):
50 """Determine whether a line is a start of a callstack or not. 60 """Determine whether a line is a start of a callstack or not.
51 Returns a tuple - (is_new_callstack, stack_priority, format_type, 61 Returns a tuple - (is_new_callstack, stack_priority, format_type,
52 language type). 62 language type).
53 """ 63 """
54 if FRACAS_CALLSTACK_START_PATTERN.match(line): 64 if FRACAS_CALLSTACK_START_PATTERN.match(line):
55 #Fracas only provide magic signature stack (crash stack). 65 #Fracas only provide magic signature stack (crash stack).
56 return True, 0, CallStackFormatType.DEFAULT, CallStackLanguageType.CPP 66 return True, 0, CallStackFormatType.DEFAULT, CallStackLanguageType.CPP
57 67
58 if JAVA_CALLSTACK_START_PATTERN.match(line): 68 if JAVA_CALLSTACK_START_PATTERN.match(line):
59 return True, 0, CallStackFormatType.DEFAULT, CallStackLanguageType.JAVA 69 return True, 0, CallStackFormatType.DEFAULT, CallStackLanguageType.JAVA
60 70
61 return False, None, None, None 71 return False, None, None, None
OLDNEW
« no previous file with comments | « appengine/findit/crash/changelist_classifier.py ('k') | appengine/findit/crash/component_classifier.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698