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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 from crash import config
6 from crash.classifier import Classifier
7 from crash.type_enums import CallStackLanguageType
8 from model.crash.crash_config import CrashConfig
9
10
11 class ProjectClassifier(Classifier):
12 """Determines the project of a crash - (project_name, project_path).
13
14 For example: ('chromium', 'src/'), ('skia', 'src/skia/'), ...etc.
15 """
16
17 CONFIG = CrashConfig.Get().project_classifier
18
19 def _GetProjectNameFromDepPath(self, dep_path):
20 """Return the component name of a path."""
21 if dep_path == 'src/':
22 return 'chromium'
23
24 for host_directory in ProjectClassifier.CONFIG['host_directories']:
25 if dep_path.startswith(host_directory):
26 path = dep_path[len(host_directory):]
27 return 'chromium-%s' % path.split('/')[0].lower()
28
29 # Unknown path, return the whole path as component name.
30 return 'chromium-%s' % '_'.join(dep_path.split('/'))
31
32 def GetClassFromStackFrame(self, frame):
33 """Returns a tuple (project_name, project_path) of a StackFrame."""
34 if frame.dep_path:
35 # 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.
36 # dep path, the project of this frame is chromium-*.
37 return self._GetProjectNameFromDepPath(frame.dep_path), frame.dep_path
38
39 if not ProjectClassifier.CONFIG:
40 return '', ''
41
42 for marker, name in ProjectClassifier.CONFIG[
43 'function_marker_to_project_name'].iteritems():
44 if frame.function.startswith(marker):
45 return name, ''
46
47 for marker, name in ProjectClassifier.CONFIG[
48 'file_path_to_project_name'].iteritems():
49 if marker in frame.file_path or marker in frame.raw_file_path:
50 return name, ''
51
52 return '', ''
53
54 def GetClassFromResult(self, result):
55 """Returns (project_name, project_path) of a Result."""
56 if result.dep_path:
57 # 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.
58 # dep path, the project of this culprit result is chromium-*.
59 return self._GetProjectNameFromDepPath(result.dep_path), result.dep_path
60
61 for frame, _ in result.file_path_to_project_name.itervalues():
62 return self.GetProjectFromStackFrame(frame)
63
64 def Classify(self, results, crash_stack):
65 """Classify project of a crash.
66
67 Args:
68 results (list of Result): culprit results.
69 crash_stack (CallStack): the callstack that caused the crash.
70
71 Returns:
72 A tuple, project of the crash - (project_name, project_path).
73 """
74 def _GetRankFunction():
75 if (crash_stack.language_type == CallStackLanguageType.JAVA and
76 ProjectClassifier.CONFIG):
77 def _RankFunctionForJava(class_info):
78 project_name, _ = class_info.class_value
79 return (class_info.count,
80 0 if 'chromium' in project_name else ProjectClassifier.CONFIG[
81 'non_chromium_project_rank_priority'][project_name])
82
83 return _RankFunctionForJava
84
85 return self._DefaultRankFunction
86
87 # Set the max_classes to 1, so the returned projects only has one element.
88 projects = self._Classify(results, crash_stack,
89 ProjectClassifier.CONFIG['top_n'], 1,
90 rank_function=_GetRankFunction())
91
92 def _Format(project_name, project_path):
93 return '%s (%s)' % project_name, project_path
94
95 if projects:
96 return _Format(*projects[0])
97
98 return ''
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698