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 import os | |
6 | |
7 | |
8 class FileDictionary(object): | |
9 """Maps file in a stacktrace to its crash information. | |
10 | |
11 It maps file to another dictionary, which maps the file's path to crashed | |
12 lines, stack frame indices and crashed functions. | |
13 """ | |
14 | |
15 def __init__(self): | |
16 """Initializes the file dictionary.""" | |
17 self.file_dic = {} | |
aarya
2014/08/07 15:38:47
s/dic/dict everywhere.
jeun
2014/08/07 18:43:19
Done.
| |
18 | |
19 def AddFile(self, file_name, file_path, crashed_line_number, | |
20 stack_frame_index, function): | |
21 """Adds file and its crash information to the map. | |
22 | |
23 Args: | |
24 file_name: The name of the crashed file. | |
25 file_path: The path of the crashed file. | |
26 crashed_line_number: The crashed line of the file. | |
27 stack_frame_index: The file's position in the callstack. | |
28 function: The name of the crashed function. | |
29 """ | |
30 # Populate the dictionary if this file/path has not been added before. | |
31 if file_name not in self.file_dic: | |
32 self.file_dic[file_name] = {} | |
aarya
2014/08/07 15:38:46
I don't understand why you use file_name as key. f
jeun
2014/08/07 18:43:19
It is easier and faster to check if a crashing fil
| |
33 | |
34 if file_path not in self.file_dic[file_name]: | |
aarya
2014/08/07 15:38:47
Why all these seperate ifs. All this initializatio
jeun
2014/08/07 18:43:19
Done.
| |
35 self.file_dic[file_name][file_path] = {} | |
36 | |
37 if 'lines' not in self.file_dic[file_name][file_path]: | |
38 self.file_dic[file_name][file_path]['lines'] = [] | |
aarya
2014/08/07 15:38:46
s/lines/stack_frames
jeun
2014/08/07 18:43:19
changed to line_numbers (the first name was a bit
| |
39 | |
40 if 'stack_frame_index' not in self.file_dic[file_name][file_path]: | |
41 self.file_dic[file_name][file_path]['stack_frame_index'] = [] | |
aarya
2014/08/07 15:38:46
s/stack_frame_index/stack_frame_indices. it is not
jeun
2014/08/07 18:43:19
Done.
| |
42 | |
43 if 'function' not in self.file_dic[file_name][file_path]: | |
44 self.file_dic[file_name][file_path]['function'] = [] | |
45 | |
46 # Add the crashed line, frame index and function name. | |
47 self.file_dic[file_name][file_path]['lines'].append(crashed_line_number) | |
48 self.file_dic[file_name][file_path]['stack_frame_index'].append( | |
49 stack_frame_index) | |
50 self.file_dic[file_name][file_path]['function'].append(function) | |
51 | |
52 def GetPathDic(self, file_name): | |
53 """Returns file's path and crash information.""" | |
54 return self.file_dic[file_name] | |
55 | |
56 def GetCrashedLines(self, file_path): | |
57 """Returns crashed lines given a file name and path.""" | |
58 file_name = os.path.basename(file_path) | |
59 return self.file_dic[file_name][file_path]['lines'] | |
60 | |
61 def GetCrashStackFrameindex(self, file_path): | |
62 """Returns stack frame indices given a file name and path.""" | |
63 file_name = os.path.basename(file_path) | |
64 return self.file_dic[file_name][file_path]['stack_frame_index'] | |
65 | |
66 def GetCrashFunction(self, file_path): | |
67 """Returns list of crashed functions given a file name and path.""" | |
68 file_name = os.path.basename(file_path) | |
69 return self.file_dic[file_name][file_path]['function'] | |
70 | |
71 def __iter__(self): | |
72 return iter(self.file_dic) | |
73 | |
74 | |
75 class ComponentDictionary(object): | |
76 """Represents a file dictionary. | |
77 | |
78 It maps each component (blink, chrome, etc) to a file dictionary. | |
79 """ | |
80 | |
81 def __init__(self, components): | |
82 """Initializes the dictionary with given components.""" | |
83 self.component_dic = {} | |
aarya
2014/08/07 15:38:47
s/component_dic/component_dict
jeun
2014/08/07 18:43:19
Done.
| |
84 | |
85 # Create file dictionary for all the components. | |
86 for component in components: | |
87 self.component_dic[component] = FileDictionary() | |
88 | |
89 def __iter__(self): | |
90 return iter(self.component_dic) | |
91 | |
92 def GetFileDic(self, component): | |
aarya
2014/08/07 15:38:47
s/Dic(/Dict( everywhere please
jeun
2014/08/07 18:43:19
Done.
| |
93 """Returns a file dictionary for a given component.""" | |
94 return self.component_dic[component] | |
95 | |
96 def GenerateFileDic(self, stack_frame_list): | |
97 """Generates file dictionary, given an instance of StackFrame list.""" | |
98 # Iterate through the list of stackframe objects. | |
99 for stack_frame in stack_frame_list: | |
100 # If the component of this line is not in the list of components to | |
101 # look for, ignore this line. | |
102 component = stack_frame.component | |
103 if component not in self.component_dic: | |
104 continue | |
105 | |
106 # Get values of the variables | |
107 file_name = stack_frame.file_name | |
108 file_path = stack_frame.file_path | |
109 crashed_line_number = stack_frame.crashed_line_number | |
110 stack_frame_index = stack_frame.index | |
111 function = stack_frame.function | |
112 | |
113 # Add the file to this component's dictionary of files. | |
114 file_dic = self.component_dic[component] | |
115 file_dic.AddFile(file_name, file_path, crashed_line_number, | |
116 stack_frame_index, function) | |
OLD | NEW |