Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import copy | |
| 6 import re | |
| 7 | |
| 8 from crash.classifier import Classifier | |
| 9 from model.crash.crash_config import CrashConfig | |
| 10 | |
| 11 | |
| 12 class ComponentClassifier(Classifier): | |
| 13 """Determines the component of a crash. | |
| 14 | |
| 15 For example: ['Blink>DOM', 'Blink>HTML']. | |
| 16 """ | |
| 17 | |
| 18 def __init__(self): | |
| 19 super(ComponentClassifier, self).__init__() | |
| 20 | |
| 21 def _GetCompiledConfig(config): | |
| 22 config = copy.copy(config) | |
|
stgao
2016/05/17 21:40:57
deepcopy
Sharu Jiang
2016/05/20 23:16:33
This is not necessary any more.
| |
| 23 config['top_n'] = int(config['top_n']) | |
|
stgao
2016/05/17 21:40:57
Why this is needed?
Sharu Jiang
2016/05/20 23:16:33
Oops...
| |
| 24 path_function_component = [] | |
| 25 | |
| 26 for path, function, component in config['path_function_component']: | |
|
stgao
2016/05/17 21:40:57
Could this be cached in the CrashConfig instance?
Sharu Jiang
2016/05/20 23:16:33
I do a CrashConfig.Get() for every crash, so I don
stgao
2016/05/21 00:54:03
On appengine, NDB has an app-instance cache for ND
Sharu Jiang
2016/05/23 23:54:50
Done.
| |
| 27 path_function_component.append(( | |
| 28 re.compile(path), | |
| 29 re.compile(function) if function else None, | |
| 30 component)) | |
| 31 config['path_function_component'] = path_function_component | |
| 32 | |
| 33 return config | |
| 34 | |
| 35 self.config = _GetCompiledConfig(CrashConfig.Get().component_classifier) | |
| 36 | |
| 37 def GetClassFromStackFrame(self, frame): | |
| 38 """Gets the component from file path and function of a frame.""" | |
| 39 for path_regex, function_regex, component in self.config[ | |
| 40 'path_function_component']: | |
| 41 path_match = path_regex.match(frame.dep_path + frame.file_path) | |
| 42 if not path_match: | |
| 43 continue | |
| 44 | |
| 45 if not function_regex: | |
| 46 return component | |
| 47 | |
| 48 function_match = function_regex.match(frame.function) | |
| 49 if function_match: | |
| 50 return component | |
| 51 | |
| 52 return '' | |
| 53 | |
| 54 def GetClassFromResult(self, result): | |
| 55 """Gets the component from a result. | |
| 56 | |
| 57 Note that Findit assumes files that the culprit result touched come from | |
| 58 the same component. | |
| 59 """ | |
| 60 if result.file_to_stack_infos: | |
| 61 # A file in culprit result should always have its stack_info, namely a | |
| 62 # list of (frame, callstack_priority) pairs. | |
| 63 frame, _ = result.file_to_stack_infos.values()[0][0] | |
| 64 return self.GetClassFromStackFrame(frame) | |
| 65 | |
| 66 return '' | |
| 67 | |
| 68 def Classify(self, results, crash_stack): | |
| 69 """Classifies project of a crash. | |
| 70 | |
| 71 Args: | |
| 72 results (list of Result): Culprit results. | |
| 73 crash_stack (CallStack): The callstack that caused the crash. | |
| 74 | |
| 75 Returns: | |
| 76 List of top 2 components. | |
| 77 """ | |
| 78 return self._Classify(results, crash_stack, self.config['top_n'], 2) | |
| OLD | NEW |