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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1f2db6d6eec81c6a1b18ffef6cbdacd87ce0ebf |
| --- /dev/null |
| +++ b/appengine/findit/crash/component_classifier.py |
| @@ -0,0 +1,55 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +from crash.classifier import Classifier |
| +from model.crash.crash_config import CrashConfig |
| + |
| + |
| +class ComponentClassifier(Classifier): |
| + """Determines the component of a crash. |
| + |
| + For example: ['Blink>DOM', 'Blink>HTML']. |
| + """ |
| + |
| + CONFIG = CrashConfig.Get().parsed_component_classifier |
| + |
| + def GetClassFromStackFrame(self, frame): |
| + """Gets the component from file path and function of a frame.""" |
| + for path_regx, function_regx, component in ComponentClassifier.CONFIG[ |
|
Martin Barbella
2016/05/05 18:33:41
Nit: s/regx/regex/
Sharu Jiang
2016/05/10 03:11:02
Done.
|
| + 'path_function_component']: |
| + path_match = path_regx.match(frame.dep_path + frame.file_path) |
| + if not path_match: |
| + continue |
| + |
| + if not function_regx: |
| + return component |
| + |
| + function_match = function_regx.match(frame.function) |
| + if function_match: |
| + return component |
| + |
| + return '' |
| + |
| + def GetClassFromResult(self, result): |
| + """Gets the component from a result. |
| + |
| + Note that Findit assumes files that the culprit result touched come from |
| + the same component. |
| + """ |
| + for frame, _ in result.file_to_stack_infos.iteritems(): |
|
Martin Barbella
2016/05/05 18:33:41
Why not just use keys()?
Sharu Jiang
2016/05/10 03:11:02
Done.
|
| + return self.GetClassFromStackFrame(frame) |
| + |
| + def Classify(self, results, crash_stack): |
| + """Classifies project of a crash. |
| + |
| + Args: |
| + results (list of Result): Culprit results. |
| + crash_stack (CallStack): The callstack that caused the crash. |
| + |
| + Returns: |
| + List of top 2 components. |
| + """ |
| + print type(ComponentClassifier.CONFIG['top_n']) |
|
Martin Barbella
2016/05/05 18:33:41
Is this for debugging? Please remove before landin
Sharu Jiang
2016/05/10 03:11:02
Done.
|
| + return self._Classify(results, crash_stack, |
| + ComponentClassifier.CONFIG['top_n'], 2) |