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