Chromium Code Reviews| Index: appengine/findit/crash/component_classifier.py |
| diff --git a/appengine/findit/crash/component_classifier.py b/appengine/findit/crash/component_classifier.py |
| index 281b31ea979f92efa89e085fa253a1c0161804a6..8e3956f245f1e5298926326678c259655000f9fa 100644 |
| --- a/appengine/findit/crash/component_classifier.py |
| +++ b/appengine/findit/crash/component_classifier.py |
| @@ -5,7 +5,7 @@ |
| import logging |
| from crash.classifier import Classifier |
| -from model.crash.crash_config import CrashConfig |
| +from crash.component import Component |
| class ComponentClassifier(Classifier): |
| @@ -14,28 +14,29 @@ class ComponentClassifier(Classifier): |
| For example: ['Blink>DOM', 'Blink>HTML']. |
| """ |
| - def __init__(self): |
| - super(ComponentClassifier, self).__init__() |
| - self.component_classifier_config = ( |
| - CrashConfig.Get().compiled_component_classifier) |
| + def __init__(self, components, top_n): |
| + """Build a classifier for components. |
| - def GetClassFromStackFrame(self, frame): |
| - """Gets the component from file path and function of a frame.""" |
| - for path_regex, function_regex, component in ( |
| - self.component_classifier_config['path_function_component']): |
| - path_match = path_regex.match(frame.dep_path + frame.file_path) |
| - if not path_match: |
| - continue |
| + Args: |
| + components (list of Component): the components to check for |
| + top_n (int): how many frames of the callstack to look at""" |
| + super(ComponentClassifier, self).__init__() |
| + if not components: |
| + logging.warning('Empty configuration for component classifier.') |
| + components = [] |
| + self.components = components |
| + self.top_n = top_n |
| - if not function_regex: |
| - return component |
| - function_match = function_regex.match(frame.function) |
| - if function_match: |
| - return component |
| + def GetClassFromStackFrame(self, frame): |
| + """Determine which component is responsible for this frame.""" |
| + for component in self.components: |
| + if component.MatchesStackFrame(frame): |
| + return component.component_name |
| return '' |
| + |
|
Sharu Jiang
2016/09/20 00:31:29
nit: only one empty line between 2 methods in Clas
wrengr
2016/09/27 22:00:39
Done.
|
| def GetClassFromResult(self, result): |
| """Gets the component from a result. |
| @@ -50,6 +51,7 @@ class ComponentClassifier(Classifier): |
| return '' |
| + |
|
Sharu Jiang
2016/09/20 00:31:29
ditto.
wrengr
2016/09/27 22:00:39
Done.
|
| def Classify(self, results, crash_stack): |
| """Classifies project of a crash. |
| @@ -60,9 +62,4 @@ class ComponentClassifier(Classifier): |
| Returns: |
| List of top 2 components. |
| """ |
| - if not self.component_classifier_config: |
| - logging.warning('Empty configuration for component classifier.') |
| - return [] |
| - |
| - return self._Classify(results, crash_stack, |
| - self.component_classifier_config['top_n'], 2) |
| + return self._Classify(results, crash_stack, self.top_n, 2) |