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

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: 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 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):
stgao 2016/05/17 21:40:57 Not sure if "class" would be the best term here, b
Sharu Jiang 2016/05/20 23:16:33 Done.
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
19 def __init__(self, name, occurrences):
20 self.name = name
21 self.occurrences = occurrences
22
23
24 def DefaultRankFunction(class_info):
25 """Default rank function to rank classes.
26
27 Note: The default behavior works for component classifier and for
28 project classifier, it works for cpp callstack class ranking.
29 """
30 # If the top 2 frames are in the same class, give this class highest
31 # priority.
32 if 0 in class_info.occurrences and 1 in class_info.occurrences:
stgao 2016/05/17 21:40:57 It is not clear what 0 and 1 are for at first read
Sharu Jiang 2016/05/20 23:16:33 I cannot think of a way to make it more clear othe
33 return -float('inf'), class_info.occurrences[0]
34
35 return -len(class_info.occurrences), class_info.occurrences[0]
36
37
38 class Classifier(object): # pragma: no cover.
stgao 2016/05/17 21:40:57 Why 'no cover'?
Sharu Jiang 2016/05/20 23:16:33 I thought it would be tested in project and compon
39 """Classifys results or crash stack into a class or a list of classes."""
40
41 def GetClassFromStackFrame(self, frame):
42 raise NotImplementedError()
43
44 def GetClassFromResult(self, result):
45 raise NotImplementedError()
46
47 def _Classify(self, results, crash_stack, top_n, max_classes,
48 rank_function=DefaultRankFunction):
49 """Classifies a crash to a list of classes, ranked by rank_function.
50
51 Extracts a list of classes from results or crash_stack, rank the classes and
52 returns max_classes number of classes on the top.
53
54 Args:
55 results (list of Result): Culprit results.
56 crash_stack (CallStack): The callstack that caused the crash.
57 top_n (int): Number of top frames to be considered when classifying.
58 max_classes (int): Maximal number of classes to return.
59 rank_function (function): Used to rank classes based on
60 ClassOccurrenceInfos.
61
62 Returns:
63 A list of classes of this crash.
64 """
65 # Extracts the class list from culprit results if possible since it's more
66 # reliable.
67 if results:
68 class_list = map(self.GetClassFromResult, results[:top_n])
69 else:
70 class_list = map(self.GetClassFromStackFrame, crash_stack[:top_n])
stgao 2016/05/17 21:40:57 Could this be handled in the sub classes?
Sharu Jiang 2016/05/20 23:16:33 would it be duplicate if I handle the same thing i
71
72 def _GetClassOccurrenceInfos():
73 """Gets ClassOccurrenceInfo list from class_list.
74
75 The ClassOccurrenceInfo list is ordered by the first occurences of each
76 class.
77 """
78 if not class_list:
79 return class_list
80
81 infos = OrderedDict()
stgao 2016/05/17 21:40:57 We sort at #93 below, why we also need ordered dic
Sharu Jiang 2016/05/20 23:16:33 Done.
82
83 # Get occurences information of each class.
84 for index, class_name in enumerate(class_list):
85 if class_name not in infos:
86 infos[class_name] = ClassOccurrenceInfo(class_name, [index])
87 else:
88 infos[class_name].occurrences.append(index)
89
90 return infos.values()
91
92 class_infos = _GetClassOccurrenceInfos()
93 class_infos = sorted(class_infos, key=rank_function)
94
95 classes = [info.name for info in class_infos]
96
97 return classes[:max_classes]
98
99 def Classify(self, results, crash_stack):
100 raise NotImplementedError()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698