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

Side by Side Diff: appengine/findit/crash/project_classifier.py

Issue 2588513002: [Predator] renamed "Result" to "Suspect" (Closed)
Patch Set: Removing redundant import 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 unified diff | Download patch
« no previous file with comments | « appengine/findit/crash/loglinear/feature.py ('k') | appengine/findit/crash/results.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import logging 5 import logging
6 6
7 from crash.occurrence import RankByOccurrence 7 from crash.occurrence import RankByOccurrence
8 from crash.type_enums import CallStackLanguageType 8 from crash.type_enums import CallStackLanguageType
9 from model.crash.crash_config import CrashConfig 9 from model.crash.crash_config import CrashConfig
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 if frame.function.startswith(marker): 47 if frame.function.startswith(marker):
48 return name 48 return name
49 49
50 for marker, name in self.project_classifier_config[ 50 for marker, name in self.project_classifier_config[
51 'file_path_marker_to_project_name'].iteritems(): 51 'file_path_marker_to_project_name'].iteritems():
52 if marker in frame.file_path or marker in frame.raw_file_path: 52 if marker in frame.file_path or marker in frame.raw_file_path:
53 return name 53 return name
54 54
55 return self._GetProjectFromDepPath(frame.dep_path) 55 return self._GetProjectFromDepPath(frame.dep_path)
56 56
57 # TODO(wrengr): refactor this into a method on Result which returns 57 # TODO(wrengr): refactor this into a method on Suspect which returns
58 # the cannonical frame (and documents why it's the one we return). 58 # the cannonical frame (and documents why it's the one we return).
59 def GetClassFromResult(self, result): 59 def GetClassFromSuspect(self, suspect):
60 """Determine which project is responsible for this result.""" 60 """Determine which project is responsible for this suspect."""
61 if result.file_to_stack_infos: 61 if suspect.file_to_stack_infos:
62 # file_to_stack_infos is a dict mapping file_path to stack_infos, 62 # file_to_stack_infos is a dict mapping file_path to stack_infos,
63 # where stack_infos is a list of (frame, callstack_priority) 63 # where stack_infos is a list of (frame, callstack_priority)
64 # pairs. So ``.values()`` returns a list of the stack_infos in an 64 # pairs. So ``.values()`` returns a list of the stack_infos in an
65 # arbitrary order; the first ``[0]`` grabs the "first" stack_infos; 65 # arbitrary order; the first ``[0]`` grabs the "first" stack_infos;
66 # the second ``[0]`` grabs the first pair from the list; and 66 # the second ``[0]`` grabs the first pair from the list; and
67 # the third ``[0]`` grabs the ``frame`` from the pair. 67 # the third ``[0]`` grabs the ``frame`` from the pair.
68 # TODO(wrengr): why is that the right frame to look at? 68 # TODO(wrengr): why is that the right frame to look at?
69 frame = result.file_to_stack_infos.values()[0][0][0] 69 frame = suspect.file_to_stack_infos.values()[0][0][0]
70 return self.GetClassFromStackFrame(frame) 70 return self.GetClassFromStackFrame(frame)
71 71
72 return '' 72 return ''
73 73
74 def Classify(self, results, crash_stack): 74 def Classify(self, suspects, crash_stack):
75 """Classify project of a crash. 75 """Classify project of a crash.
76 76
77 Args: 77 Args:
78 results (list of Result): culprit results. 78 suspects (list of Suspect): culprit suspects.
79 crash_stack (CallStack): the callstack that caused the crash. 79 crash_stack (CallStack): the callstack that caused the crash.
80 80
81 Returns: 81 Returns:
82 The name of the most-suspected project; or the empty string on failure. 82 The name of the most-suspected project; or the empty string on failure.
83 """ 83 """
84 if not self.project_classifier_config: 84 if not self.project_classifier_config:
85 logging.warning('ProjectClassifier.Classify: Empty configuration.') 85 logging.warning('ProjectClassifier.Classify: Empty configuration.')
86 return None 86 return None
87 87
88 rank_function = None 88 rank_function = None
89 if crash_stack.language_type == CallStackLanguageType.JAVA: 89 if crash_stack.language_type == CallStackLanguageType.JAVA:
90 def _RankFunctionForJava(occurrence): 90 def _RankFunctionForJava(occurrence):
91 # TODO(wrengr): why are we weighting by the length, instead of 91 # TODO(wrengr): why are we weighting by the length, instead of
92 # the negative length as we do in the DefaultOccurrenceRanging? 92 # the negative length as we do in the DefaultOccurrenceRanging?
93 weight = len(occurrence) 93 weight = len(occurrence)
94 project_name = occurrence.name 94 project_name = occurrence.name
95 if 'chromium' in project_name: 95 if 'chromium' in project_name:
96 index = 0 96 index = 0
97 else: 97 else:
98 index = self.project_classifier_config[ 98 index = self.project_classifier_config[
99 'non_chromium_project_rank_priority'][project_name] 99 'non_chromium_project_rank_priority'][project_name]
100 return (weight, index) 100 return (weight, index)
101 101
102 rank_function = _RankFunctionForJava 102 rank_function = _RankFunctionForJava
103 103
104 top_n_frames = self.project_classifier_config['top_n'] 104 top_n_frames = self.project_classifier_config['top_n']
105 # If ``results`` are available, we use the projects from there since 105 # If ``suspects`` are available, we use the projects from there since
106 # they're more reliable than the ones from the ``crash_stack``. 106 # they're more reliable than the ones from the ``crash_stack``.
107 if results: 107 if suspects:
108 classes = map(self.GetClassFromResult, results[:top_n_frames]) 108 classes = map(self.GetClassFromSuspect, suspects[:top_n_frames])
109 else: 109 else:
110 classes = map(self.GetClassFromStackFrame, 110 classes = map(self.GetClassFromStackFrame,
111 crash_stack.frames[:top_n_frames]) 111 crash_stack.frames[:top_n_frames])
112 112
113 # Since we're only going to return the highest-ranked class, might 113 # Since we're only going to return the highest-ranked class, might
114 # as well set ``max_classes`` to 1. 114 # as well set ``max_classes`` to 1.
115 projects = RankByOccurrence(classes, 1, rank_function=rank_function) 115 projects = RankByOccurrence(classes, 1, rank_function=rank_function)
116 116
117 if projects: 117 if projects:
118 return projects[0] 118 return projects[0]
119 119
120 logging.warning('ProjectClassifier.Classify: no projects found.') 120 logging.warning('ProjectClassifier.Classify: no projects found.')
121 return '' 121 return ''
OLDNEW
« no previous file with comments | « appengine/findit/crash/loglinear/feature.py ('k') | appengine/findit/crash/results.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698