OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 | |
6 class ComponentDictionary(object): | |
7 """Represents a file dictionary. | |
8 | |
9 It maps each component (blink, chrome, etc) to a component dictionary. | |
stgao
2014/07/31 01:52:24
component dictionary? or should be file dictionary
jeun
2014/07/31 18:41:14
Done.
| |
10 """ | |
11 | |
12 def __init__(self, components): | |
13 """Initializes the dictionary with given components.""" | |
14 self.component_dic = {} | |
15 self.components = components | |
stgao
2014/07/31 01:52:23
Do we need to save |components| here?
It could be
jeun
2014/07/31 18:41:14
Done.
| |
16 | |
17 # Create file dictionary for all the components | |
18 for component in components: | |
19 self.component_dic[component] = FileDictionary() | |
stgao
2014/07/31 01:52:23
As FileDictionary is used by ComponentDictionary,
jeun
2014/07/31 18:41:14
Done.
| |
20 | |
21 def __iter__(self): | |
22 return iter(self.component_dic) | |
23 | |
24 def GetFileDic(self, component): | |
25 """Returns a component dictionary for a given component.""" | |
stgao
2014/07/31 01:52:24
FileDictionary or component dictionary?
jeun
2014/07/31 18:41:14
Done.
| |
26 return self.component_dic[component] | |
27 | |
28 def FromStacktrace(self, stack_list): | |
stgao
2014/07/31 01:52:24
|stack_list| is misleading here.
Should it be |sta
jeun
2014/07/31 18:41:14
Done.
| |
29 """Parses stacktrace, given an instance of StacktraceLine list.""" | |
30 # Iterate through the list of stacktrace line objects | |
31 for stacktrace_line in stack_list: | |
32 | |
stgao
2014/07/31 01:52:23
This empty line could be removed.
jeun
2014/07/31 18:41:14
Done.
| |
33 # If the component of this line is not believed to have caused the | |
34 # crash, ignore this line | |
stgao
2014/07/31 01:52:24
How do you know this here?
jeun
2014/07/31 18:41:14
Updated the comment to explain this in a better wa
| |
35 component = stacktrace_line.component | |
36 if component not in self.components: | |
stgao
2014/07/31 01:52:24
we could do below instead:
if component not in se
jeun
2014/07/31 18:41:14
Done.
| |
37 continue | |
38 | |
39 # Get values of the variables | |
40 file_name = stacktrace_line.file_name | |
41 file_path = stacktrace_line.file_path | |
42 crashed_line = stacktrace_line.crashed_line | |
43 stack_frame_index = stacktrace_line.stack_frame_index | |
44 function = stacktrace_line.function | |
45 | |
46 # Add the file to this component's dictionary of files | |
47 file_dic = self.component_dic[component] | |
48 file_dic.AddFile(file_name, file_path, crashed_line, stack_frame_index, | |
49 function) | |
50 | |
51 | |
52 class FileDictionary(object): | |
53 """Maps file in a stacktrace to its crash information. | |
54 | |
55 It maps file to another dictionary, which maps the file's path to crashed | |
56 lines, stack frame indices and crashed functions. | |
57 """ | |
58 | |
59 def __init__(self): | |
60 """Initializes the component dictionary.""" | |
61 self.file_dic = {} | |
62 | |
63 def AddFile(self, file_name, file_path, crashed_line, | |
64 stack_frame_index, function): | |
65 """Adds file and its crash information to the map. | |
66 | |
67 Args: | |
68 file_name: name of the crashed file | |
stgao
2014/07/31 01:52:23
I think file_name is not needed, as it could be de
jeun
2014/07/31 18:41:14
I think because stacktrace line already has file_n
stgao
2014/08/01 17:22:20
OK, that's fine. It is a problem of time and memor
| |
69 file_path: path of the crashed file | |
70 crashed_line: crashed line of the file | |
71 stack_frame_index: the file's position in the stack frame | |
72 function: name of the crashed function | |
73 """ | |
74 | |
stgao
2014/07/31 01:52:23
Empty line is not needed.
jeun
2014/07/31 18:41:14
Done.
| |
75 # Populate the dictionary if this file/path has not been added before | |
76 if file_name not in self.file_dic: | |
77 self.file_dic[file_name] = {} | |
78 | |
79 if file_path not in self.file_dic[file_name]: | |
80 self.file_dic[file_name][file_path] = {} | |
81 | |
82 if 'lines' not in self.file_dic[file_name][file_path]: | |
83 self.file_dic[file_name][file_path]['lines'] = [] | |
84 | |
85 if 'stack_frame_index' not in self.file_dic[file_name][file_path]: | |
86 self.file_dic[file_name][file_path]['stack_frame_index'] = [] | |
87 | |
88 if 'function' not in self.file_dic[file_name][file_path]: | |
89 self.file_dic[file_name][file_path]['function'] = [] | |
90 | |
91 # Add the crashed line, frame index and function name | |
92 self.file_dic[file_name][file_path]['lines'].append(crashed_line) | |
93 self.file_dic[file_name][file_path]['stack_frame_index'].append( | |
94 stack_frame_index) | |
95 self.file_dic[file_name][file_path]['function'].append(function) | |
96 | |
97 def GetPathDic(self, file_name): | |
stgao
2014/07/31 01:52:23
For these Get functions here, could we just use fi
jeun
2014/07/31 18:41:14
Done.
| |
98 """Returns file's path and crash information.""" | |
99 return self.file_dic[file_name] | |
100 | |
101 def GetCrashedLines(self, file_name, file_path): | |
102 """Returns crashed lines given a file name and path.""" | |
103 return self.file_dic[file_name][file_path]['lines'] | |
104 | |
105 def GetCrashStackFrameindex(self, file_name, file_path): | |
106 """Returns stack frame indices given a file name and path.""" | |
107 return self.file_dic[file_name][file_path]['stack_frame_index'] | |
108 | |
109 def GetCrashFunction(self, file_name, file_path): | |
110 """Returns list of crashed functions given a file name and path.""" | |
111 return self.file_dic[file_name][file_path]['function'] | |
112 | |
113 def __iter__(self): | |
114 return iter(self.file_dic) | |
OLD | NEW |