| Index: appengine/findit/crash/project_classifier.py
|
| diff --git a/appengine/findit/crash/project_classifier.py b/appengine/findit/crash/project_classifier.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f28a19145e938fdf5b105fa6ddf1d9706666baee
|
| --- /dev/null
|
| +++ b/appengine/findit/crash/project_classifier.py
|
| @@ -0,0 +1,112 @@
|
| +# 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.
|
| +
|
| +import copy
|
| +
|
| +from crash import classifier
|
| +from crash.type_enums import CallStackLanguageType
|
| +from model.crash.crash_config import CrashConfig
|
| +
|
| +
|
| +class ProjectClassifier(classifier.Classifier):
|
| + """Determines the project of a crash - (project_name, project_path).
|
| +
|
| + For example: ('chromium', 'src/'), ('skia', 'src/skia/'), ...etc.
|
| + """
|
| +
|
| + def __init__(self):
|
| + super(ProjectClassifier, self).__init__()
|
| +
|
| + def _GetCompiledConfig(config):
|
| + config = copy.copy(config)
|
| + config['top_n'] = int(config['top_n'])
|
| + return config
|
| +
|
| + self.config = _GetCompiledConfig(CrashConfig.Get().project_classifier)
|
| +
|
| + def _GetProjectNameFromDepPath(self, dep_path):
|
| + """Returns the component name of a path."""
|
| + if dep_path == 'src/':
|
| + return 'chromium'
|
| +
|
| + for host_directory in self.config['host_directories']:
|
| + if dep_path.startswith(host_directory):
|
| + path = dep_path[len(host_directory):]
|
| + return 'chromium-%s' % path.split('/')[0].lower()
|
| +
|
| + # Unknown path, return the whole path as component name.
|
| + return 'chromium-%s' % '_'.join(dep_path.split('/'))
|
| +
|
| + def GetClassFromStackFrame(self, frame):
|
| + """Returns a tuple (project_name, project_path) of a StackFrame."""
|
| + if frame.dep_path:
|
| + # Dep paths are parsed from chromium dependency, if a frame has non-empty
|
| + # dep path, the project of this frame is chromium-*.
|
| + return self._GetProjectNameFromDepPath(frame.dep_path), frame.dep_path
|
| +
|
| + for marker, name in self.config[
|
| + 'function_marker_to_project_name'].iteritems():
|
| + if frame.function.startswith(marker):
|
| + return name, ''
|
| +
|
| + for marker, name in self.config[
|
| + 'file_path_marker_to_project_name'].iteritems():
|
| + if marker in frame.file_path or marker in frame.raw_file_path:
|
| + return name, ''
|
| +
|
| + return 'others', ''
|
| +
|
| + def GetClassFromResult(self, result):
|
| + """Returns (project_name, project_path) of a Result."""
|
| + if result.dep_path:
|
| + # Dep paths are parsed from chromium dependency, if a result has non-empty
|
| + # dep path, the project of this culprit result is chromium-*.
|
| + return self._GetProjectNameFromDepPath(result.dep_path), result.dep_path
|
| +
|
| + if result.file_to_stack_infos:
|
| + # A file in culprit result should always have its stack_info, namely a
|
| + # list of (frame, callstack_priority) pairs.
|
| + frame, _ = result.file_to_stack_infos.values()[0][0]
|
| + return self.GetClassFromStackFrame(frame)
|
| +
|
| + return 'others', ''
|
| +
|
| + def Classify(self, results, crash_stack):
|
| + """Classify project of a crash.
|
| +
|
| + Args:
|
| + results (list of Result): culprit results.
|
| + crash_stack (CallStack): the callstack that caused the crash.
|
| +
|
| + Returns:
|
| + A tuple, project of the crash - (project_name, project_path).
|
| + """
|
| + def _GetRankFunction(language_type):
|
| + if language_type == CallStackLanguageType.JAVA:
|
| + def _RankFunctionForJava(class_occurrences_info):
|
| + project_name, _ = class_occurrences_info.name
|
| + return (len(class_occurrences_info.occurrences),
|
| + 0 if 'chromium' in project_name else self.config[
|
| + 'non_chromium_project_rank_priority'][project_name])
|
| +
|
| + return _RankFunctionForJava
|
| +
|
| + return classifier.DefaultRankFunction
|
| +
|
| + # Set the max_classes to 1, so the returned projects only has one element.
|
| + projects = self._Classify(
|
| + results, crash_stack,
|
| + self.config['top_n'], 1,
|
| + rank_function=_GetRankFunction(crash_stack.language_type))
|
| +
|
| + def _Format(project_name, project_path):
|
| + if project_path:
|
| + return '%s (%s)' % (project_name, project_path)
|
| +
|
| + return project_name
|
| +
|
| + if projects:
|
| + return _Format(*projects[0])
|
| +
|
| + return 'others'
|
|
|