| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 collections import namedtuple | 5 from collections import namedtuple |
| 6 | 6 |
| 7 | 7 |
| 8 # TODO(wrengr): we should change things to use integers with None as | 8 # TODO(wrengr): we should change things to use integers with None as |
| 9 # \"infinity\", rather than using floats. | 9 # \"infinity\", rather than using floats. |
| 10 # TODO(http://crbug.com/644476): this class needs a better name. | 10 # TODO(http://crbug.com/644476): this class needs a better name. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 lines.append('Changed file %s crashed in %s' % ( | 92 lines.append('Changed file %s crashed in %s' % ( |
| 93 file_path, ', '.join(line_parts))) | 93 file_path, ', '.join(line_parts))) |
| 94 | 94 |
| 95 return '\n'.join(lines) | 95 return '\n'.join(lines) |
| 96 | 96 |
| 97 def __str__(self): | 97 def __str__(self): |
| 98 return self.ToString() | 98 return self.ToString() |
| 99 | 99 |
| 100 | 100 |
| 101 def _UpdateSuspect(suspect, file_path, stack_infos, blame): | 101 def _UpdateSuspect(self, file_path, stack_infos, blame): |
| 102 """Updates a ``Suspect`` with file path and its stack_infos and blame. | 102 """Updates a ``Suspect`` with file path and its stack_infos and blame. |
| 103 | 103 |
| 104 When a file_path is found both shown in stacktrace and touched by | 104 When a file_path is found both shown in stacktrace and touched by |
| 105 the revision of this result, update result with the information of | 105 the revision of this result, update result with the information of |
| 106 this file. | 106 this file. |
| 107 | 107 |
| 108 Inserts the file path and its stack infos, and updates the min distance | 108 Inserts the file path and its stack infos, and updates the min distance |
| 109 if less distance is found between touched lines of this result and | 109 if less distance is found between touched lines of this result and |
| 110 crashed lines in the file path. | 110 crashed lines in the file path. |
| 111 | 111 |
| 112 Args: | 112 Args: |
| 113 suspect (Suspect): the suspect to be updated. | 113 suspect (Suspect): the suspect to be updated. |
| 114 file_path (str): File path of the crashed file. | 114 file_path (str): File path of the crashed file. |
| 115 stack_infos (list of StackInfo): List of the frames of this file | 115 stack_infos (list of StackInfo): List of the frames of this file |
| 116 together with their callstack priorities. | 116 together with their callstack priorities. |
| 117 blame (Blame): Blame oject of this file. | 117 blame (Blame): Blame oject of this file. |
| 118 """ | 118 """ |
| 119 suspect.file_to_stack_infos[file_path] = stack_infos | 119 self.file_to_stack_infos[file_path] = stack_infos |
| 120 | 120 |
| 121 if not blame: | 121 if not blame: |
| 122 return | 122 return |
| 123 | 123 |
| 124 min_distance = float('inf') | 124 min_distance = float('inf') |
| 125 min_distance_frame = stack_infos[0].frame | 125 min_distance_frame = stack_infos[0].frame |
| 126 for region in blame: | 126 for region in blame: |
| 127 if region.revision != suspect.changelog.revision: | 127 if region.revision != self.changelog.revision: |
| 128 continue | 128 continue |
| 129 | 129 |
| 130 region_start = region.start | 130 region_start = region.start |
| 131 region_end = region_start + region.count - 1 | 131 region_end = region_start + region.count - 1 |
| 132 for frame, _ in stack_infos: | 132 for frame, _ in stack_infos: |
| 133 frame_start = frame.crashed_line_numbers[0] | 133 frame_start = frame.crashed_line_numbers[0] |
| 134 frame_end = frame.crashed_line_numbers[-1] | 134 frame_end = frame.crashed_line_numbers[-1] |
| 135 distance = _DistanceBetweenLineRanges((frame_start, frame_end), | 135 distance = _DistanceBetweenLineRanges((frame_start, frame_end), |
| 136 (region_start, region_end)) | 136 (region_start, region_end)) |
| 137 if distance < min_distance: | 137 if distance < min_distance: |
| 138 min_distance = distance | 138 min_distance = distance |
| 139 min_distance_frame = frame | 139 min_distance_frame = frame |
| 140 | 140 |
| 141 suspect.file_to_analysis_info[file_path] = AnalysisInfo( | 141 self.file_to_analysis_info[file_path] = AnalysisInfo( |
| 142 min_distance = min_distance, | 142 min_distance = min_distance, |
| 143 min_distance_frame = min_distance_frame, | 143 min_distance_frame = min_distance_frame, |
| 144 ) | 144 ) |
| 145 | 145 |
| 146 | 146 |
| 147 def _DistanceBetweenLineRanges((start1, end1), (start2, end2)): | 147 def _DistanceBetweenLineRanges((start1, end1), (start2, end2)): |
| 148 """Given two ranges, compute the (unsigned) distance between them. | 148 """Given two ranges, compute the (unsigned) distance between them. |
| 149 | 149 |
| 150 Args: | 150 Args: |
| 151 start1: the start of the first range | 151 start1: the start of the first range |
| 152 end1: the end of the first range. Must be greater than start1. | 152 end1: the end of the first range. Must be greater than start1. |
| 153 start2: the start of the second range | 153 start2: the start of the second range |
| 154 end2: the end of the second range. Must be greater than start2. | 154 end2: the end of the second range. Must be greater than start2. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 stack_infos (list): List of stack_info dicts, represents frames of this | 187 stack_infos (list): List of stack_info dicts, represents frames of this |
| 188 file and the callstack priorities of those frames. | 188 file and the callstack priorities of those frames. |
| 189 changelogs (list): List of Changelog objects in the dep in regression | 189 changelogs (list): List of Changelog objects in the dep in regression |
| 190 range which touched the file. | 190 range which touched the file. |
| 191 blame (Blame): Blame of the file. | 191 blame (Blame): Blame of the file. |
| 192 """ | 192 """ |
| 193 for changelog in changelogs: | 193 for changelog in changelogs: |
| 194 if self._ignore_cls and changelog.revision in self._ignore_cls: | 194 if self._ignore_cls and changelog.revision in self._ignore_cls: |
| 195 continue | 195 continue |
| 196 | 196 |
| 197 if changelog.revision not in self: | 197 try: |
| 198 self[changelog.revision] = Suspect(changelog, dep_path) | 198 suspect = self[changelog.revision] |
| 199 except KeyError: |
| 200 suspect = Suspect(changelog, dep_path) |
| 201 self[changelog.revision] = suspect |
| 199 | 202 |
| 200 _UpdateSuspect(self[changelog.revision], file_path, stack_infos, blame) | 203 suspect._UpdateSuspect(file_path, stack_infos, blame) |
| OLD | NEW |