Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: appengine/findit/crash/suspect.py

Issue 2600223003: Made _UpdateSuspect a method on Suspect rather than a standalone function (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/findit/crash/test/suspect_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/crash/suspect.py
diff --git a/appengine/findit/crash/suspect.py b/appengine/findit/crash/suspect.py
index a87117430f63012d98042b99a3f89a96653eda3e..4c3a2beeebc2578c8de210e43b8a50a6de16249e 100644
--- a/appengine/findit/crash/suspect.py
+++ b/appengine/findit/crash/suspect.py
@@ -98,50 +98,50 @@ class Suspect(object):
return self.ToString()
-def _UpdateSuspect(suspect, file_path, stack_infos, blame):
- """Updates a ``Suspect`` with file path and its stack_infos and blame.
+ def _UpdateSuspect(self, file_path, stack_infos, blame):
+ """Updates a ``Suspect`` with file path and its stack_infos and blame.
- When a file_path is found both shown in stacktrace and touched by
- the revision of this result, update result with the information of
- this file.
+ When a file_path is found both shown in stacktrace and touched by
+ the revision of this result, update result with the information of
+ this file.
- Inserts the file path and its stack infos, and updates the min distance
- if less distance is found between touched lines of this result and
- crashed lines in the file path.
+ Inserts the file path and its stack infos, and updates the min distance
+ if less distance is found between touched lines of this result and
+ crashed lines in the file path.
- Args:
- suspect (Suspect): the suspect to be updated.
- file_path (str): File path of the crashed file.
- stack_infos (list of StackInfo): List of the frames of this file
- together with their callstack priorities.
- blame (Blame): Blame oject of this file.
- """
- suspect.file_to_stack_infos[file_path] = stack_infos
-
- if not blame:
- return
-
- min_distance = float('inf')
- min_distance_frame = stack_infos[0].frame
- for region in blame:
- if region.revision != suspect.changelog.revision:
- continue
-
- region_start = region.start
- region_end = region_start + region.count - 1
- for frame, _ in stack_infos:
- frame_start = frame.crashed_line_numbers[0]
- frame_end = frame.crashed_line_numbers[-1]
- distance = _DistanceBetweenLineRanges((frame_start, frame_end),
- (region_start, region_end))
- if distance < min_distance:
- min_distance = distance
- min_distance_frame = frame
-
- suspect.file_to_analysis_info[file_path] = AnalysisInfo(
- min_distance = min_distance,
- min_distance_frame = min_distance_frame,
- )
+ Args:
+ suspect (Suspect): the suspect to be updated.
+ file_path (str): File path of the crashed file.
+ stack_infos (list of StackInfo): List of the frames of this file
+ together with their callstack priorities.
+ blame (Blame): Blame oject of this file.
+ """
+ self.file_to_stack_infos[file_path] = stack_infos
+
+ if not blame:
+ return
+
+ min_distance = float('inf')
+ min_distance_frame = stack_infos[0].frame
+ for region in blame:
+ if region.revision != self.changelog.revision:
+ continue
+
+ region_start = region.start
+ region_end = region_start + region.count - 1
+ for frame, _ in stack_infos:
+ frame_start = frame.crashed_line_numbers[0]
+ frame_end = frame.crashed_line_numbers[-1]
+ distance = _DistanceBetweenLineRanges((frame_start, frame_end),
+ (region_start, region_end))
+ if distance < min_distance:
+ min_distance = distance
+ min_distance_frame = frame
+
+ self.file_to_analysis_info[file_path] = AnalysisInfo(
+ min_distance = min_distance,
+ min_distance_frame = min_distance_frame,
+ )
def _DistanceBetweenLineRanges((start1, end1), (start2, end2)):
@@ -194,7 +194,10 @@ class SuspectMap(dict):
if self._ignore_cls and changelog.revision in self._ignore_cls:
continue
- if changelog.revision not in self:
- self[changelog.revision] = Suspect(changelog, dep_path)
+ try:
+ suspect = self[changelog.revision]
+ except KeyError:
+ suspect = Suspect(changelog, dep_path)
+ self[changelog.revision] = suspect
- _UpdateSuspect(self[changelog.revision], file_path, stack_infos, blame)
+ suspect._UpdateSuspect(file_path, stack_infos, blame)
« no previous file with comments | « no previous file | appengine/findit/crash/test/suspect_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698