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 FileDicttionary(object): | |
|
stgao
2014/08/07 21:03:37
Misspell: Dicttionary -> Dictionary.
Please do a
jeun
2014/08/07 22:03:20
Done.
| |
| 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_dict = {} | |
| 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_dict: | |
| 32 self.file_dict[file_name] = {} | |
| 33 | |
| 34 if file_path not in self.file_dict[file_name]: | |
| 35 self.file_dict[file_name][file_path] = {} | |
| 36 self.file_dict[file_name][file_path]['line_numbers'] = [] | |
| 37 self.file_dict[file_name][file_path]['stack_frame_indices'] = [] | |
| 38 self.file_dict[file_name][file_path]['function'] = [] | |
| 39 | |
| 40 # Add the crashed line, frame index and function name. | |
| 41 self.file_dict[file_name][file_path]['line_numbers'].append( | |
| 42 crashed_line_number) | |
| 43 self.file_dict[file_name][file_path]['stack_frame_indices'].append( | |
| 44 stack_frame_index) | |
| 45 self.file_dict[file_name][file_path]['function'].append(function) | |
| 46 | |
| 47 def GetPathDic(self, file_name): | |
| 48 """Returns file's path and crash information.""" | |
| 49 return self.file_dict[file_name] | |
| 50 | |
| 51 def GetCrashedLineNumbers(self, file_path): | |
| 52 """Returns crashed line numbers given a file path.""" | |
| 53 file_name = os.path.basename(file_path) | |
| 54 return self.file_dict[file_name][file_path]['line_numbers'] | |
| 55 | |
| 56 def GetCrashStackFrameindex(self, file_path): | |
| 57 """Returns stack frame indices given a file path.""" | |
| 58 file_name = os.path.basename(file_path) | |
| 59 return self.file_dict[file_name][file_path]['stack_frame_indices'] | |
| 60 | |
| 61 def GetCrashFunction(self, file_path): | |
| 62 """Returns list of crashed functions given a file path.""" | |
| 63 file_name = os.path.basename(file_path) | |
| 64 return self.file_dict[file_name][file_path]['function'] | |
| 65 | |
| 66 def __iter__(self): | |
| 67 return iter(self.file_dict) | |
| 68 | |
| 69 | |
| 70 class ComponentDictionary(object): | |
| 71 """Represents a file dictionary. | |
| 72 | |
| 73 It maps each component (blink, chrome, etc) to a file dictionary. | |
| 74 """ | |
| 75 | |
| 76 def __init__(self, components): | |
| 77 """Initializes the dictionary with given components.""" | |
| 78 self.component_dict = {} | |
| 79 | |
| 80 # Create file dictionary for all the components. | |
| 81 for component in components: | |
| 82 self.component_dict[component] = FileDicttionary() | |
| 83 | |
| 84 def __iter__(self): | |
| 85 return iter(self.component_dict) | |
| 86 | |
| 87 def GetFileDict(self, component): | |
| 88 """Returns a file dictionary for a given component.""" | |
| 89 return self.component_dict[component] | |
| 90 | |
| 91 def GenerateFileDict(self, stack_frame_list): | |
| 92 """Generates file dictionary, given an instance of StackFrame list.""" | |
| 93 # Iterate through the list of stackframe objects. | |
| 94 for stack_frame in stack_frame_list: | |
| 95 # If the component of this line is not in the list of components to | |
| 96 # look for, ignore this line. | |
| 97 component = stack_frame.component | |
| 98 if component not in self.component_dict: | |
| 99 continue | |
| 100 | |
| 101 # Get values of the variables | |
| 102 file_name = stack_frame.file_name | |
| 103 file_path = stack_frame.file_path | |
| 104 crashed_line_number = stack_frame.crashed_line_number | |
| 105 stack_frame_index = stack_frame.index | |
| 106 function = stack_frame.function | |
| 107 | |
| 108 # Add the file to this component's dictionary of files. | |
| 109 file_dict = self.component_dict[component] | |
| 110 file_dict.AddFile(file_name, file_path, crashed_line_number, | |
| 111 stack_frame_index, function) | |
| OLD | NEW |