Chromium Code Reviews| 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 = {} | |
| 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: name of the crashed file | |
| 25 file_path: path of the crashed file | |
| 26 crashed_line_number: crashed line of the file | |
| 27 stack_frame_index: the file's position in the callstack | |
| 28 function: 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] = {} | |
| 33 | |
| 34 if file_path not in self.file_dic[file_name]: | |
| 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'] = [] | |
| 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'] = [] | |
| 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 = {} | |
| 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): | |
| 93 """Returns a file dictionary for a given component.""" | |
| 94 return self.component_dic[component] | |
| 95 | |
| 96 def FromStacktrace(self, stack_frame_list): | |
|
stgao
2014/08/01 17:22:20
Could you please give a better name for this funct
jeun
2014/08/06 18:22:59
Done.
| |
| 97 """Parses stacktrace, given an instance of StackFrame list.""" | |
| 98 # Iterate through the list of stackframe objects. | |
| 99 for stackframe in stack_frame_list: | |
|
stgao
2014/08/01 17:22:20
stackframe -> stack_frame?
Let's make it consisten
jeun
2014/08/06 18:22:59
Done.
| |
| 100 # If the component of this line is not in the list of components to | |
| 101 # look for, ignore this line. | |
| 102 component = stackframe.component | |
| 103 if component not in self.component_dic: | |
| 104 continue | |
| 105 | |
| 106 # Get values of the variables | |
| 107 file_name = stackframe.file_name | |
| 108 file_path = stackframe.file_path | |
| 109 crashed_line_number = stackframe.crashed_line_number | |
| 110 stack_frame_index = stackframe.index | |
| 111 function = stackframe.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 |