| OLD | NEW |
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 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 from threading import Lock, Thread | 5 from threading import Lock |
| 6 | 6 |
| 7 from common import utils | 7 from common import utils |
| 8 import crash_utils | 8 import crash_utils |
| 9 | 9 |
| 10 | 10 |
| 11 class Blame(object): | 11 class Blame(object): |
| 12 """Represents a blame object. | 12 """Represents a blame object. |
| 13 | 13 |
| 14 The object contains blame information for one line of stack, and this | 14 The object contains blame information for one line of stack, and this |
| 15 information is shown when there are no CLs that change the crashing files. | 15 information is shown when there are no CLs that change the crashing files. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 callstack: The list of stack frames. | 70 callstack: The list of stack frames. |
| 71 component_to_crash_revision_dict: A dictionary that maps component to its | 71 component_to_crash_revision_dict: A dictionary that maps component to its |
| 72 crash revision. | 72 crash revision. |
| 73 component_to_regression_dict: A dictionary that maps component to its | 73 component_to_regression_dict: A dictionary that maps component to its |
| 74 revision range. | 74 revision range. |
| 75 parsers: A list of two parsers, svn_parser and git_parser | 75 parsers: A list of two parsers, svn_parser and git_parser |
| 76 top_n_frames: A number of stack frames to show the blame result for. | 76 top_n_frames: A number of stack frames to show the blame result for. |
| 77 """ | 77 """ |
| 78 # Only return blame information for first 'top_n_frames' frames. | 78 # Only return blame information for first 'top_n_frames' frames. |
| 79 stack_frames = callstack.GetTopNFrames(top_n_frames) | 79 stack_frames = callstack.GetTopNFrames(top_n_frames) |
| 80 threads = [] | 80 tasks = [] |
| 81 # Iterate through frames in stack. | 81 # Iterate through frames in stack. |
| 82 for stack_frame in stack_frames: | 82 for stack_frame in stack_frames: |
| 83 # If the component this line is from does not have a crash revision, | 83 # If the component this line is from does not have a crash revision, |
| 84 # it is not possible to get blame information, so ignore this line. | 84 # it is not possible to get blame information, so ignore this line. |
| 85 component_path = stack_frame.component_path | 85 component_path = stack_frame.component_path |
| 86 if component_path not in component_to_crash_revision_dict: | 86 if component_path not in component_to_crash_revision_dict: |
| 87 continue | 87 continue |
| 88 | 88 |
| 89 crash_revision = component_to_crash_revision_dict[ | 89 crash_revision = component_to_crash_revision_dict[ |
| 90 component_path]['revision'] | 90 component_path]['revision'] |
| 91 range_start = None | 91 range_start = None |
| 92 range_end = None | 92 range_end = None |
| 93 repository_type = crash_utils.GetRepositoryType(crash_revision) | 93 repository_type = crash_utils.GetRepositoryType(crash_revision) |
| 94 repository_parser = parsers[repository_type] | 94 repository_parser = parsers[repository_type] |
| 95 | 95 |
| 96 # If the revision is in SVN, and if regression information is available, | 96 # If the revision is in SVN, and if regression information is available, |
| 97 # get it. For Git, we cannot know the ordering between hash numbers. | 97 # get it. For Git, we cannot know the ordering between hash numbers. |
| 98 if repository_type == 'svn': | 98 if repository_type == 'svn': |
| 99 if component_to_regression_dict and \ | 99 if component_to_regression_dict and \ |
| 100 component_path in component_to_regression_dict: | 100 component_path in component_to_regression_dict: |
| 101 component_object = component_to_regression_dict[component_path] | 101 component_object = component_to_regression_dict[component_path] |
| 102 range_start = int(component_object['old_revision']) | 102 range_start = int(component_object['old_revision']) |
| 103 range_end = int(component_object['new_revision']) | 103 range_end = int(component_object['new_revision']) |
| 104 | 104 |
| 105 # Generate blame entry, one thread for one entry. | 105 # Create a task to generate blame entry. |
| 106 blame_thread = Thread( | 106 tasks.append({ |
| 107 target=self.__GenerateBlameEntry, | 107 'function': self.__GenerateBlameEntry, |
| 108 args=[repository_parser, stack_frame, crash_revision, | 108 'args': [repository_parser, stack_frame, crash_revision, |
| 109 range_start, range_end]) | 109 range_start, range_end] |
| 110 threads.append(blame_thread) | 110 }) |
| 111 blame_thread.start() | |
| 112 | 111 |
| 113 # Join the results before returning. | 112 # Run all the tasks. |
| 114 for blame_thread in threads: | 113 crash_utils.RunTasks(tasks) |
| 115 blame_thread.join() | 114 |
| 116 | 115 |
| 117 def __GenerateBlameEntry(self, repository_parser, stack_frame, | 116 def __GenerateBlameEntry(self, repository_parser, stack_frame, |
| 118 crash_revision, range_start, range_end): | 117 crash_revision, range_start, range_end): |
| 119 """Generates blame list from the arguments.""" | 118 """Generates blame list from the arguments.""" |
| 120 stack_frame_index = stack_frame.index | 119 stack_frame_index = stack_frame.index |
| 121 component_path = stack_frame.component_path | 120 component_path = stack_frame.component_path |
| 122 component_name = stack_frame.component_name | 121 component_name = stack_frame.component_name |
| 123 file_name = stack_frame.file_name | 122 file_name = stack_frame.file_name |
| 124 file_path = stack_frame.file_path | 123 file_path = stack_frame.file_path |
| 125 crashed_line_number = stack_frame.crashed_line_range[0] | 124 crashed_line_number = stack_frame.crashed_line_range[0] |
| 126 | 125 |
| 126 if file_path.startswith(component_path): |
| 127 file_path = file_path[len(component_path):] |
| 128 |
| 127 # Parse blame information. | 129 # Parse blame information. |
| 128 parsed_blame_info = repository_parser.ParseBlameInfo( | 130 parsed_blame_info = repository_parser.ParseBlameInfo( |
| 129 component_path, file_path, crashed_line_number, crash_revision) | 131 component_path, file_path, crashed_line_number, crash_revision) |
| 130 | 132 |
| 131 # If it fails to retrieve information, do not do anything. | 133 # If it fails to retrieve information, do not do anything. |
| 132 if not parsed_blame_info: | 134 if not parsed_blame_info: |
| 133 return | 135 return |
| 134 | 136 |
| 135 # Create blame object from the parsed info and add it to the list. | 137 # Create blame object from the parsed info and add it to the list. |
| 136 (line_content, revision, author, url, message) = parsed_blame_info | 138 (line_content, revision, author, url, message) = parsed_blame_info |
| (...skipping 17 matching lines...) Expand all Loading... |
| 154 if blame.range_start and blame.range_end: | 156 if blame.range_start and blame.range_end: |
| 155 | 157 |
| 156 # Discards results that are after the end of regression. | 158 # Discards results that are after the end of regression. |
| 157 if not utils.IsGitHash(blame.revision) and ( | 159 if not utils.IsGitHash(blame.revision) and ( |
| 158 int(blame.range_end) <= int(blame.revision)): | 160 int(blame.range_end) <= int(blame.revision)): |
| 159 continue | 161 continue |
| 160 | 162 |
| 161 filtered_blame_list.append(blame) | 163 filtered_blame_list.append(blame) |
| 162 | 164 |
| 163 self.blame_list = filtered_blame_list | 165 self.blame_list = filtered_blame_list |
| OLD | NEW |