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 | |
| 7 from crash import classifier | |
| 8 from crash.type_enums import CallStackLanguageType | |
| 9 from model.crash.crash_config import CrashConfig | |
| 10 | |
| 11 | |
| 12 class ProjectClassifier(classifier.Classifier): | |
| 13 """Determines the project of a crash - (project_name, project_path). | |
| 14 | |
| 15 For example: ('chromium', 'src/'), ('skia', 'src/skia/'), ...etc. | |
| 16 """ | |
| 17 | |
| 18 def __init__(self): | |
| 19 super(ProjectClassifier, self).__init__() | |
| 20 | |
| 21 def _GetCompiledConfig(config): | |
| 22 config = copy.copy(config) | |
|
stgao
2016/05/17 21:40:57
deepcopy if copy is really needed.
Sharu Jiang
2016/05/20 23:16:33
No need any more.
| |
| 23 config['top_n'] = int(config['top_n']) | |
|
stgao
2016/05/17 21:40:57
same here.
Sharu Jiang
2016/05/20 23:16:33
Oops.
| |
| 24 return config | |
| 25 | |
| 26 self.config = _GetCompiledConfig(CrashConfig.Get().project_classifier) | |
|
stgao
2016/05/17 21:40:57
self.config is not specific, maybe project_classif
Sharu Jiang
2016/05/20 23:16:33
Done.
| |
| 27 | |
| 28 def _GetProjectFromDepPath(self, dep_path): | |
| 29 """Returns the project name from a dep path.""" | |
| 30 if not dep_path: | |
| 31 return '' | |
| 32 | |
| 33 if dep_path == 'src/': | |
| 34 return 'chromium' | |
| 35 | |
| 36 for host_directory in self.config['host_directories']: | |
|
stgao
2016/05/17 21:40:57
should the host directories be sorted like the one
Sharu Jiang
2016/05/20 23:16:33
The order of host_directories is exactly the same
stgao
2016/05/21 00:54:03
Are they always sorted in the config?
Sharu Jiang
2016/05/23 23:54:50
I am a little confused, they are always in this or
stgao
2016/05/24 00:10:58
Yes, they are in order in clusterfuzz, but they ar
Sharu Jiang
2016/05/24 22:22:44
get it, that makes sense.
| |
| 37 if dep_path.startswith(host_directory): | |
| 38 path = dep_path[len(host_directory):] | |
| 39 return 'chromium-%s' % path.split('/')[0].lower() | |
| 40 | |
| 41 # Unknown path, return the whole path as project name. | |
| 42 return 'chromium-%s' % '_'.join(dep_path.split('/')) | |
| 43 | |
| 44 def GetClassFromStackFrame(self, frame): | |
| 45 """Returns a tuple (project_name, project_path) of a StackFrame.""" | |
| 46 for marker, name in self.config[ | |
| 47 'function_marker_to_project_name'].iteritems(): | |
| 48 if frame.function.startswith(marker): | |
| 49 return name | |
| 50 | |
| 51 for marker, name in self.config[ | |
| 52 'file_path_marker_to_project_name'].iteritems(): | |
| 53 if marker in frame.file_path or marker in frame.raw_file_path: | |
| 54 return name | |
| 55 | |
| 56 return self._GetProjectFromDepPath(frame.dep_path) | |
| 57 | |
| 58 def GetClassFromResult(self, result): | |
| 59 """Returns (project_name, project_path) of a Result.""" | |
| 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 """Classify 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 A tuple, project of the crash - (project_name, project_path). | |
| 77 """ | |
| 78 def _GetRankFunction(language_type): | |
| 79 if language_type == CallStackLanguageType.JAVA: | |
| 80 def _RankFunctionForJava(class_occurrences_info): | |
| 81 project_name = class_occurrences_info.name | |
| 82 return (len(class_occurrences_info.occurrences), | |
| 83 0 if 'chromium' in project_name else self.config[ | |
| 84 'non_chromium_project_rank_priority'][project_name]) | |
| 85 | |
| 86 return _RankFunctionForJava | |
| 87 | |
| 88 return classifier.DefaultRankFunction | |
| 89 | |
| 90 # Set the max_classes to 1, so the returned projects only has one element. | |
| 91 projects = self._Classify( | |
| 92 results, crash_stack, | |
| 93 self.config['top_n'], 1, | |
| 94 rank_function=_GetRankFunction(crash_stack.language_type)) | |
| 95 | |
| 96 if projects: | |
| 97 return projects[0] | |
| 98 | |
| 99 return '' | |
| OLD | NEW |