Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.classifier import Classifier | 7 from crash.classifier import Classifier |
| 8 from model.crash.crash_config import CrashConfig | 8 from crash.component import Component |
| 9 | 9 |
| 10 | 10 |
| 11 class ComponentClassifier(Classifier): | 11 class ComponentClassifier(Classifier): |
| 12 """Determines the component of a crash. | 12 """Determines the component of a crash. |
| 13 | 13 |
| 14 For example: ['Blink>DOM', 'Blink>HTML']. | 14 For example: ['Blink>DOM', 'Blink>HTML']. |
| 15 """ | 15 """ |
| 16 | 16 |
| 17 def __init__(self): | 17 def __init__(self, components, top_n): |
| 18 """Build a classifier for components. | |
| 19 | |
| 20 Args: | |
| 21 components (list of Component): the components to check for | |
| 22 top_n (int): how many frames of the callstack to look at""" | |
| 18 super(ComponentClassifier, self).__init__() | 23 super(ComponentClassifier, self).__init__() |
| 19 self.component_classifier_config = ( | 24 if not components: |
| 20 CrashConfig.Get().compiled_component_classifier) | 25 logging.warning('Empty configuration for component classifier.') |
| 26 components = [] | |
| 27 self.components = components | |
| 28 self.top_n = top_n | |
| 29 | |
| 21 | 30 |
| 22 def GetClassFromStackFrame(self, frame): | 31 def GetClassFromStackFrame(self, frame): |
| 23 """Gets the component from file path and function of a frame.""" | 32 """Determine which component is responsible for this frame.""" |
| 24 for path_regex, function_regex, component in ( | 33 for component in self.components: |
| 25 self.component_classifier_config['path_function_component']): | 34 if component.MatchesStackFrame(frame): |
| 26 path_match = path_regex.match(frame.dep_path + frame.file_path) | 35 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 | 36 |
| 37 return '' | 37 return '' |
| 38 | 38 |
| 39 | |
|
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.
| |
| 39 def GetClassFromResult(self, result): | 40 def GetClassFromResult(self, result): |
| 40 """Gets the component from a result. | 41 """Gets the component from a result. |
| 41 | 42 |
| 42 Note that Findit assumes files that the culprit result touched come from | 43 Note that Findit assumes files that the culprit result touched come from |
| 43 the same component. | 44 the same component. |
| 44 """ | 45 """ |
| 45 if result.file_to_stack_infos: | 46 if result.file_to_stack_infos: |
| 46 # A file in culprit result should always have its stack_info, namely a | 47 # A file in culprit result should always have its stack_info, namely a |
| 47 # list of (frame, callstack_priority) pairs. | 48 # list of (frame, callstack_priority) pairs. |
| 48 frame, _ = result.file_to_stack_infos.values()[0][0] | 49 frame, _ = result.file_to_stack_infos.values()[0][0] |
| 49 return self.GetClassFromStackFrame(frame) | 50 return self.GetClassFromStackFrame(frame) |
| 50 | 51 |
| 51 return '' | 52 return '' |
| 52 | 53 |
| 54 | |
|
Sharu Jiang
2016/09/20 00:31:29
ditto.
wrengr
2016/09/27 22:00:39
Done.
| |
| 53 def Classify(self, results, crash_stack): | 55 def Classify(self, results, crash_stack): |
| 54 """Classifies project of a crash. | 56 """Classifies project of a crash. |
| 55 | 57 |
| 56 Args: | 58 Args: |
| 57 results (list of Result): Culprit results. | 59 results (list of Result): Culprit results. |
| 58 crash_stack (CallStack): The callstack that caused the crash. | 60 crash_stack (CallStack): The callstack that caused the crash. |
| 59 | 61 |
| 60 Returns: | 62 Returns: |
| 61 List of top 2 components. | 63 List of top 2 components. |
| 62 """ | 64 """ |
| 63 if not self.component_classifier_config: | 65 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) | |
| OLD | NEW |