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

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

Issue 2338273006: [Findit] Factoring out the components, so they can classify themselves (Closed)
Patch Set: rebasing to remove dependency on crrev.com/2344443005 Created 4 years, 2 months 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/component.py ('k') | appengine/findit/crash/findit_for_chromecrash.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
7 from crash.classifier import Classifier 6 from crash.classifier import Classifier
8 from model.crash.crash_config import CrashConfig
9
10 7
11 class ComponentClassifier(Classifier): 8 class ComponentClassifier(Classifier):
12 """Determines the component of a crash. 9 """Determines the component of a crash.
13 10
14 For example: ['Blink>DOM', 'Blink>HTML']. 11 For example: ['Blink>DOM', 'Blink>HTML'].
15 """ 12 """
16 13
17 def __init__(self): 14 def __init__(self, components, top_n):
15 """Build a classifier for components.
16
17 Args:
18 components (list of crash.component.Component): the components to
19 check for.
20 top_n (int): how many frames of the callstack to look at"""
18 super(ComponentClassifier, self).__init__() 21 super(ComponentClassifier, self).__init__()
19 self.component_classifier_config = ( 22 if not components:
20 CrashConfig.Get().compiled_component_classifier) 23 logging.warning('Empty configuration for component classifier.')
24 components = []
25 self.components = components
26 self.top_n = top_n
21 27
22 def GetClassFromStackFrame(self, frame): 28 def GetClassFromStackFrame(self, frame):
23 """Gets the component from file path and function of a frame.""" 29 """Determine which component is responsible for this frame."""
24 for path_regex, function_regex, component in ( 30 for component in self.components:
25 self.component_classifier_config['path_function_component']): 31 if component.MatchesStackFrame(frame):
26 path_match = path_regex.match(frame.dep_path + frame.file_path) 32 return component.component_name
27 if not path_match:
28 continue
29
30 if not function_regex:
31 return component
32
33 function_match = function_regex.match(frame.function)
34 if function_match:
35 return component
36 33
37 return '' 34 return ''
38 35
39 def GetClassFromResult(self, result): 36 def GetClassFromResult(self, result):
40 """Gets the component from a result. 37 """Gets the component from a result.
41 38
42 Note that Findit assumes files that the culprit result touched come from 39 Note that Findit assumes files that the culprit result touched come from
43 the same component. 40 the same component.
44 """ 41 """
45 if result.file_to_stack_infos: 42 if result.file_to_stack_infos:
46 # A file in culprit result should always have its stack_info, namely a 43 # A file in culprit result should always have its stack_info, namely a
47 # list of (frame, callstack_priority) pairs. 44 # list of (frame, callstack_priority) pairs.
48 frame, _ = result.file_to_stack_infos.values()[0][0] 45 frame, _ = result.file_to_stack_infos.values()[0][0]
49 return self.GetClassFromStackFrame(frame) 46 return self.GetClassFromStackFrame(frame)
50 47
51 return '' 48 return ''
52 49
53 def Classify(self, results, crash_stack): 50 def Classify(self, results, crash_stack):
54 """Classifies project of a crash. 51 """Classifies project of a crash.
55 52
56 Args: 53 Args:
57 results (list of Result): Culprit results. 54 results (list of Result): Culprit results.
58 crash_stack (CallStack): The callstack that caused the crash. 55 crash_stack (CallStack): The callstack that caused the crash.
59 56
60 Returns: 57 Returns:
61 List of top 2 components. 58 List of top 2 components.
62 """ 59 """
63 if not self.component_classifier_config: 60 return self._Classify(results, crash_stack, self.top_n, 2)
64 logging.warning('Empty configuration for component classifier.')
65 return []
66
67 return self._Classify(results, crash_stack,
68 self.component_classifier_config['top_n'], 2)
OLDNEW
« no previous file with comments | « appengine/findit/crash/component.py ('k') | appengine/findit/crash/findit_for_chromecrash.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698