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

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
« no previous file with comments | « appengine/findit/crash/fracas_parser.py ('k') | appengine/findit/crash/results.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 self.project_classifier_config['host_directories'].sort(
22 cmp=self._CompareHosts)
stgao 2016/05/24 22:28:48 This could be simplified by just comparing the len
Sharu Jiang 2016/05/24 23:30:24 I think only when a host is contained by another,
stgao 2016/05/24 23:35:36 For those that are not contained by another, does
Sharu Jiang 2016/05/25 00:08:07 Done.
23
24 def _CompareHosts(self, host1, host2):
25 """Compares 2 host directories.
26
27 If a host is contained in another host, the shorter the length the smaller,
28 otherwise, use the alphabetic order.
29 For example, 'src/tools' < 'src', 'src/chrome/ < src/media'.
30 """
31 if host1.startswith(host2) or host2.startswith(host1):
32 return -cmp(len(host1), len(host2))
33
34 return cmp(host1, host2)
35
36 def _GetProjectFromDepPath(self, dep_path):
37 """Returns the project name from a dep path."""
38 if not dep_path:
39 return ''
40
41 if dep_path == 'src/':
42 return 'chromium'
43
44 for host_directory in self.project_classifier_config['host_directories']:
45 if dep_path.startswith(host_directory):
46 path = dep_path[len(host_directory):]
47 return 'chromium-%s' % path.split('/')[0].lower()
48
49 # Unknown path, return the whole path as project name.
50 return 'chromium-%s' % '_'.join(dep_path.split('/'))
51
52 def GetClassFromStackFrame(self, frame):
53 """Returns a tuple (project_name, project_path) of a StackFrame."""
54 for marker, name in self.project_classifier_config[
55 'function_marker_to_project_name'].iteritems():
56 if frame.function.startswith(marker):
57 return name
58
59 for marker, name in self.project_classifier_config[
60 'file_path_marker_to_project_name'].iteritems():
61 if marker in frame.file_path or marker in frame.raw_file_path:
62 return name
63
64 return self._GetProjectFromDepPath(frame.dep_path)
65
66 def GetClassFromResult(self, result):
67 """Returns (project_name, project_path) of a Result."""
68 if result.file_to_stack_infos:
69 # A file in culprit result should always have its stack_info, namely a
70 # list of (frame, callstack_priority) pairs.
71 frame, _ = result.file_to_stack_infos.values()[0][0]
72 return self.GetClassFromStackFrame(frame)
73
74 return ''
75
76 def Classify(self, results, crash_stack):
77 """Classify project of a crash.
78
79 Args:
80 results (list of Result): culprit results.
81 crash_stack (CallStack): the callstack that caused the crash.
82
83 Returns:
84 A tuple, project of the crash - (project_name, project_path).
85 """
86 def _GetRankFunction(language_type):
87 if language_type == CallStackLanguageType.JAVA:
88 def _RankFunctionForJava(class_occurrences_info):
89 project_name = class_occurrences_info.name
90 return (len(class_occurrences_info.occurrences),
91 0 if 'chromium' in project_name else
92 self.project_classifier_config[
93 'non_chromium_project_rank_priority'][project_name])
94
95 return _RankFunctionForJava
96
97 return classifier.DefaultRankFunction
98
99 # Set the max_classes to 1, so the returned projects only has one element.
100 projects = self._Classify(
101 results, crash_stack,
102 self.project_classifier_config['top_n'], 1,
103 rank_function=_GetRankFunction(crash_stack.language_type))
104
105 if projects:
106 return projects[0]
107
108 return ''
OLDNEW
« 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