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

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: 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
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..7ae04a8d5a5386f0d5e0cb7caf0ac03312596904
--- /dev/null
+++ b/appengine/findit/crash/project_classifier.py
@@ -0,0 +1,98 @@
+# 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 import config
+from crash.classifier import Classifier
+from crash.type_enums import CallStackLanguageType
+from model.crash.crash_config import CrashConfig
+
+
+class ProjectClassifier(Classifier):
+ """Determines the project of a crash - (project_name, project_path).
+
+ For example: ('chromium', 'src/'), ('skia', 'src/skia/'), ...etc.
+ """
+
+ CONFIG = CrashConfig.Get().project_classifier
+
+ def _GetProjectNameFromDepPath(self, dep_path):
+ """Return the component name of a path."""
+ if dep_path == 'src/':
+ return 'chromium'
+
+ for host_directory in ProjectClassifier.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
Martin Barbella 2016/05/05 18:33:41 Nit: Dep
Sharu Jiang 2016/05/10 03:11:02 Done.
+ # dep path, the project of this frame is chromium-*.
+ return self._GetProjectNameFromDepPath(frame.dep_path), frame.dep_path
+
+ if not ProjectClassifier.CONFIG:
+ return '', ''
+
+ for marker, name in ProjectClassifier.CONFIG[
+ 'function_marker_to_project_name'].iteritems():
+ if frame.function.startswith(marker):
+ return name, ''
+
+ for marker, name in ProjectClassifier.CONFIG[
+ 'file_path_to_project_name'].iteritems():
+ if marker in frame.file_path or marker in frame.raw_file_path:
+ return name, ''
+
+ return '', ''
+
+ 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
Martin Barbella 2016/05/05 18:33:41 Ditto.
Sharu Jiang 2016/05/10 03:11:03 Done.
+ # dep path, the project of this culprit result is chromium-*.
+ return self._GetProjectNameFromDepPath(result.dep_path), result.dep_path
+
+ for frame, _ in result.file_path_to_project_name.itervalues():
+ return self.GetProjectFromStackFrame(frame)
+
+ 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():
+ if (crash_stack.language_type == CallStackLanguageType.JAVA and
+ ProjectClassifier.CONFIG):
+ def _RankFunctionForJava(class_info):
+ project_name, _ = class_info.class_value
+ return (class_info.count,
+ 0 if 'chromium' in project_name else ProjectClassifier.CONFIG[
+ 'non_chromium_project_rank_priority'][project_name])
+
+ return _RankFunctionForJava
+
+ return self._DefaultRankFunction
+
+ # Set the max_classes to 1, so the returned projects only has one element.
+ projects = self._Classify(results, crash_stack,
+ ProjectClassifier.CONFIG['top_n'], 1,
+ rank_function=_GetRankFunction())
+
+ def _Format(project_name, project_path):
+ return '%s (%s)' % project_name, project_path
+
+ if projects:
+ return _Format(*projects[0])
+
+ return ''

Powered by Google App Engine
This is Rietveld 408576698