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

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: Add classifiers to fracas.py 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
21 def _GetCompiledConfig(config):
22 config = copy.copy(config)
23 config['top_n'] = int(config['top_n'])
24 return config
25
26 self.config = _GetCompiledConfig(CrashConfig.Get().project_classifier)
27
28 def _GetProjectFromDepPath(self, dep_path):
29 """Returns the component name of a path."""
Martin Barbella 2016/05/13 23:05:07 Update this (if needed once other comments are add
Sharu Jiang 2016/05/17 19:27:54 Done.
30 if not dep_path:
31 return '', ''
Martin Barbella 2016/05/13 23:05:07 I'm a bit confused by why we need to return dep_pa
Sharu Jiang 2016/05/17 19:27:54 I just want to offer more information before, but
32
33 if dep_path == 'src/':
34 return 'chromium', dep_path
35
36 for host_directory in self.config['host_directories']:
37 if dep_path.startswith(host_directory):
38 path = dep_path[len(host_directory):]
39 return 'chromium-%s' % path.split('/')[0].lower(), dep_path
40
41 # Unknown path, return the whole path as component name.
42 return 'chromium-%s' % '_'.join(dep_path.split('/')), dep_path
43
44 def GetClassFromStackFrame(self, frame):
45 """Returns a tuple (project_name, project_path) of a StackFrame."""
46 for marker, name in self.config[
47 'function_marker_to_project_name'].iteritems():
48 if frame.function.startswith(marker):
49 return name, ''
50
51 for marker, name in self.config[
52 'file_path_marker_to_project_name'].iteritems():
53 if marker in frame.file_path or marker in frame.raw_file_path:
54 return name, ''
55
56 return self._GetProjectFromDepPath(frame.dep_path)
57
58 def GetClassFromResult(self, result):
59 """Returns (project_name, project_path) of a Result."""
60 if result.file_to_stack_infos:
61 # A file in culprit result should always have its stack_info, namely a
62 # list of (frame, callstack_priority) pairs.
63 frame, _ = result.file_to_stack_infos.values()[0][0]
64 return self.GetClassFromStackFrame(frame)
65
66 return '', ''
67
68 def Classify(self, results, crash_stack):
69 """Classify project of a crash.
70
71 Args:
72 results (list of Result): culprit results.
73 crash_stack (CallStack): the callstack that caused the crash.
74
75 Returns:
76 A tuple, project of the crash - (project_name, project_path).
77 """
78 def _GetRankFunction(language_type):
79 if language_type == CallStackLanguageType.JAVA:
80 def _RankFunctionForJava(class_occurrences_info):
81 project_name, _ = class_occurrences_info.name
82 return (len(class_occurrences_info.occurrences),
83 0 if 'chromium' in project_name else self.config[
84 'non_chromium_project_rank_priority'][project_name])
85
86 return _RankFunctionForJava
87
88 return classifier.DefaultRankFunction
89
90 # Set the max_classes to 1, so the returned projects only has one element.
91 projects = self._Classify(
92 results, crash_stack,
93 self.config['top_n'], 1,
94 rank_function=_GetRankFunction(crash_stack.language_type))
95
96 def _Format(project_name, project_path):
97 if project_path:
98 return '%s (%s)' % (project_name, project_path)
99
100 return project_name
101
102 if projects:
103 return _Format(*projects[0])
104
105 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