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

Side by Side Diff: appengine/findit/crash/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/callstack.py ('k') | appengine/findit/crash/component_classifier.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 from collections import namedtuple
6 from collections import OrderedDict
7
8 from common import constants
9 from crash.type_enums import CallStackLanguageType
10 from model.crash.crash_config import CrashConfig
11
12
13 class ClassOccurrenceInfo(object):
14 """Represents information of a class in results or crash_stack.
15
16 Class information includes the name of the class, a list of indice (index in
17 results list or in the crash_stack) of occurrences.
18 Class can be project name, like 'chromium', 'chromium-skia', or component name
19 like 'Blink>API', 'Blink>DOM'.
20 """
21
22 def __init__(self, name, occurrences):
23 self.name = name
24 self.occurrences = occurrences
25
26
27 def DefaultRankFunction(class_info):
28 """Default rank function to rank classes.
29
30 Note: The default behavior works for component classifier and for
31 project classifier, it works for cpp callstack class ranking.
32 """
33 # If the top 2 frames are in the same class, give this class highest
34 # priority.
35 if 0 in class_info.occurrences and 1 in class_info.occurrences:
36 return -float('inf'), class_info.occurrences[0]
37
38 return -len(class_info.occurrences), class_info.occurrences[0]
39
40
41 class Classifier(object):
42 """Classifys results or crash stack into a class or a list of classes."""
43
44 def GetClassFromStackFrame(self, frame): # pragma: no cover.
45 raise NotImplementedError()
46
47 def GetClassFromResult(self, result): # pragma: no cover.
48 raise NotImplementedError()
49
50 def _Classify(self, results, crash_stack, top_n, max_classes,
51 rank_function=DefaultRankFunction):
52 """Classifies a crash to a list of classes, ranked by rank_function.
53
54 Extracts a list of classes from results or crash_stack, rank the classes and
55 returns max_classes number of classes on the top.
56
57 Args:
58 results (list of Result): Culprit results.
59 crash_stack (CallStack): The callstack that caused the crash.
60 top_n (int): Number of top frames to be considered when classifying.
61 max_classes (int): Maximal number of classes to return.
62 rank_function (function): Used to rank classes based on
63 ClassOccurrenceInfos.
64
65 Returns:
66 A list of classes of this crash.
67 """
68 # Extracts the class list from culprit results if possible since it's more
69 # reliable.
70 if results:
71 class_list = map(self.GetClassFromResult, results[:top_n])
72 else:
73 class_list = map(self.GetClassFromStackFrame, crash_stack[:top_n])
74
75 def _GetClassOccurrenceInfos():
76 """Gets ClassOccurrenceInfo list from class_list."""
77 if not class_list:
78 return class_list
79
80 infos = {}
81
82 # Get occurences information of each class.
83 for index, class_name in enumerate(class_list):
84 if class_name not in infos:
85 infos[class_name] = ClassOccurrenceInfo(class_name, [index])
86 else:
87 infos[class_name].occurrences.append(index)
88
89 return infos.values()
90
91 class_infos = _GetClassOccurrenceInfos()
92 class_infos = sorted(class_infos, key=rank_function)
93
94 classes = [info.name for info in class_infos]
95
96 return classes[:max_classes]
97
98 def Classify(self, results, crash_stack): # pragma: no cover.
99 raise NotImplementedError()
OLDNEW
« no previous file with comments | « appengine/findit/crash/callstack.py ('k') | appengine/findit/crash/component_classifier.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698