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

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: Rebase and address comments. 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 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 self.project_classifier_config = CrashConfig.Get().project_classifier
21
22 def _GetProjectFromDepPath(self, dep_path):
23 """Returns the project name from a dep path."""
24 if not dep_path:
25 return ''
26
27 if dep_path == 'src/':
28 return 'chromium'
29
30 for host_directory in self.project_classifier_config['host_directories']:
31 if dep_path.startswith(host_directory):
32 path = dep_path[len(host_directory):]
33 return 'chromium-%s' % path.split('/')[0].lower()
34
35 # Unknown path, return the whole path as project name.
36 return 'chromium-%s' % '_'.join(dep_path.split('/'))
37
38 def GetClassFromStackFrame(self, frame):
39 """Returns a tuple (project_name, project_path) of a StackFrame."""
40 for marker, name in self.project_classifier_config[
41 'function_marker_to_project_name'].iteritems():
42 if frame.function.startswith(marker):
43 return name
44
45 for marker, name in self.project_classifier_config[
46 'file_path_marker_to_project_name'].iteritems():
47 if marker in frame.file_path or marker in frame.raw_file_path:
48 return name
49
50 return self._GetProjectFromDepPath(frame.dep_path)
51
52 def GetClassFromResult(self, result):
53 """Returns (project_name, project_path) of a Result."""
54 if result.file_to_stack_infos:
55 # A file in culprit result should always have its stack_info, namely a
56 # list of (frame, callstack_priority) pairs.
57 frame, _ = result.file_to_stack_infos.values()[0][0]
58 return self.GetClassFromStackFrame(frame)
59
60 return ''
61
62 def Classify(self, results, crash_stack):
63 """Classify project of a crash.
64
65 Args:
66 results (list of Result): culprit results.
67 crash_stack (CallStack): the callstack that caused the crash.
68
69 Returns:
70 A tuple, project of the crash - (project_name, project_path).
71 """
72 def _GetRankFunction(language_type):
73 if language_type == CallStackLanguageType.JAVA:
74 def _RankFunctionForJava(class_occurrences_info):
75 project_name = class_occurrences_info.name
76 return (len(class_occurrences_info.occurrences),
77 0 if 'chromium' in project_name else
78 self.project_classifier_config[
79 'non_chromium_project_rank_priority'][project_name])
80
81 return _RankFunctionForJava
82
83 return classifier.DefaultRankFunction
84
85 # Set the max_classes to 1, so the returned projects only has one element.
86 projects = self._Classify(
87 results, crash_stack,
88 self.project_classifier_config['top_n'], 1,
89 rank_function=_GetRankFunction(crash_stack.language_type))
90
91 if projects:
92 return projects[0]
93
94 return ''
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698