Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1648)

Unified Diff: appengine/findit/crash/project_classifier.py

Issue 1914113002: [Findit] Enable project classifier and component classifier (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/findit/crash/fracas_parser.py ('k') | appengine/findit/crash/results.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..eddfa327c7af069b494474323eb4ca70a2eb6967
--- /dev/null
+++ b/appengine/findit/crash/project_classifier.py
@@ -0,0 +1,101 @@
+# 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 logging
+
+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__()
+ self.project_classifier_config = CrashConfig.Get().project_classifier
+ if self.project_classifier_config:
+ self.project_classifier_config['host_directories'].sort(
+ key=lambda host: -len(host.split('/')))
+
+ def _GetProjectFromDepPath(self, dep_path):
+ """Returns the project name from a dep path."""
+ if not dep_path:
+ return ''
+
+ if dep_path == 'src/':
+ return 'chromium'
+
+ for host_directory in self.project_classifier_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 project name.
+ return 'chromium-%s' % '_'.join(dep_path.split('/'))
+
+ def GetClassFromStackFrame(self, frame):
+ """Returns a tuple (project_name, project_path) of a StackFrame."""
+ for marker, name in self.project_classifier_config[
+ 'function_marker_to_project_name'].iteritems():
+ if frame.function.startswith(marker):
+ return name
+
+ for marker, name in self.project_classifier_config[
+ 'file_path_marker_to_project_name'].iteritems():
+ if marker in frame.file_path or marker in frame.raw_file_path:
+ return name
+
+ return self._GetProjectFromDepPath(frame.dep_path)
+
+ def GetClassFromResult(self, result):
+ """Returns (project_name, project_path) of a Result."""
+ 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 ''
+
+ 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).
+ """
+ if not self.project_classifier_config:
+ logging.warning('Empty configuration for project classifier.')
+ return ''
+
+ 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.project_classifier_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.project_classifier_config['top_n'], 1,
+ rank_function=_GetRankFunction(crash_stack.language_type))
+
+ if projects:
+ return projects[0]
+
+ return ''
« no previous file with comments | « appengine/findit/crash/fracas_parser.py ('k') | appengine/findit/crash/results.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698