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

Side by Side Diff: appengine/findit/crash/component_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/changelist_classifier.py ('k') | appengine/findit/crash/culprit.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 from collections import namedtuple 5 from collections import namedtuple
6 from collections import defaultdict 6 from collections import defaultdict
7 import logging 7 import logging
8 import re 8 import re
9 9
10 from crash.component import Component 10 from crash.component import Component
(...skipping 22 matching lines...) Expand all
33 self.top_n = top_n 33 self.top_n = top_n
34 34
35 def GetClassFromStackFrame(self, frame): 35 def GetClassFromStackFrame(self, frame):
36 """Determine which component is responsible for this frame.""" 36 """Determine which component is responsible for this frame."""
37 for component in self.components: 37 for component in self.components:
38 if component.MatchesStackFrame(frame): 38 if component.MatchesStackFrame(frame):
39 return component.component_name 39 return component.component_name
40 40
41 return '' 41 return ''
42 42
43 # TODO(wrengr): refactor this into a method on Result which returns 43 # TODO(wrengr): refactor this into a method on Suspect which returns
44 # the cannonical frame (and documents why it's the one we return). 44 # the cannonical frame (and documents why it's the one we return).
45 def GetClassFromResult(self, result): 45 def GetClassFromSuspect(self, suspect):
46 """Determine which component is responsible for this result. 46 """Determine which component is responsible for this suspect.
47 47
48 Note that Findit assumes files that the culprit result touched come from 48 Note that Findit assumes files that the culprit suspect touched come from
49 the same component. 49 the same component.
50 """ 50 """
51 if result.file_to_stack_infos: 51 if suspect.file_to_stack_infos:
52 # file_to_stack_infos is a dict mapping file_path to stack_infos, 52 # file_to_stack_infos is a dict mapping file_path to stack_infos,
53 # where stack_infos is a list of (frame, callstack_priority) 53 # where stack_infos is a list of (frame, callstack_priority)
54 # pairs. So ``.values()`` returns a list of the stack_infos in an 54 # pairs. So ``.values()`` returns a list of the stack_infos in an
55 # arbitrary order; the first ``[0]`` grabs the "first" stack_infos; 55 # arbitrary order; the first ``[0]`` grabs the "first" stack_infos;
56 # the second ``[0]`` grabs the first pair from the list; and 56 # the second ``[0]`` grabs the first pair from the list; and
57 # the third ``[0]`` grabs the ``frame`` from the pair. 57 # the third ``[0]`` grabs the ``frame`` from the pair.
58 # TODO(wrengr): why is that the right frame to look at? 58 # TODO(wrengr): why is that the right frame to look at?
59 frame = result.file_to_stack_infos.values()[0][0][0] 59 frame = suspect.file_to_stack_infos.values()[0][0][0]
60 return self.GetClassFromStackFrame(frame) 60 return self.GetClassFromStackFrame(frame)
61 61
62 return '' 62 return ''
63 63
64 # TODO(http://crbug.com/657177): return the Component objects 64 # TODO(http://crbug.com/657177): return the Component objects
65 # themselves, rather than strings naming them. 65 # themselves, rather than strings naming them.
66 def Classify(self, results, crash_stack): 66 def Classify(self, suspects, crash_stack):
67 """Classifies component of a crash. 67 """Classifies component of a crash.
68 68
69 Args: 69 Args:
70 results (list of Result): Culprit results. 70 suspects (list of Suspect): Culprit suspects.
71 crash_stack (CallStack): The callstack that caused the crash. 71 crash_stack (CallStack): The callstack that caused the crash.
72 72
73 Returns: 73 Returns:
74 List of top 2 components. 74 List of top 2 components.
75 """ 75 """
76 # If ``results`` are available, we use the components from there since 76 # If ``suspects`` are available, we use the components from there since
77 # they're more reliable than the ones from the ``crash_stack``. 77 # they're more reliable than the ones from the ``crash_stack``.
78 if results: 78 if suspects:
79 classes = map(self.GetClassFromResult, results[:self.top_n]) 79 classes = map(self.GetClassFromSuspect, suspects[:self.top_n])
80 else: 80 else:
81 classes = map(self.GetClassFromStackFrame, 81 classes = map(self.GetClassFromStackFrame,
82 crash_stack.frames[:self.top_n]) 82 crash_stack.frames[:self.top_n])
83 83
84 return RankByOccurrence(classes, 2) 84 return RankByOccurrence(classes, 2)
85 85
86 # TODO(ymzhang): use component of new path as default. RENAME might 86 # TODO(ymzhang): use component of new path as default. RENAME might
87 # need to return two (old path new path may have different components) 87 # need to return two (old path new path may have different components)
88 def GetClassFromFileChangeInfo(self, file_change_info): 88 def GetClassFromFileChangeInfo(self, file_change_info):
89 """Determine which component is responsible for a touched file.""" 89 """Determine which component is responsible for a touched file."""
(...skipping 18 matching lines...) Expand all
108 top_n: number of components assigned to this change log, default is 2 108 top_n: number of components assigned to this change log, default is 2
109 109
110 Returns: 110 Returns:
111 List of components 111 List of components
112 """ 112 """
113 if not change_log: 113 if not change_log:
114 return None 114 return None
115 115
116 classes = map(self.GetClassFromFileChangeInfo, change_log.touched_files) 116 classes = map(self.GetClassFromFileChangeInfo, change_log.touched_files)
117 return RankByOccurrence(classes, top_n, rank_function=lambda x:-len(x)) 117 return RankByOccurrence(classes, top_n, rank_function=lambda x:-len(x))
OLDNEW
« no previous file with comments | « appengine/findit/crash/changelist_classifier.py ('k') | appengine/findit/crash/culprit.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698