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

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: 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 class ClassInfo(object):
13
14 def __init__(self, value, count, occurrences):
15 self.value = value
16 self.count = count
17 self.occurrences = occurrences
18
19 def __iter__(self):
Martin Barbella 2016/05/05 18:33:41 It doesn't seem intuitive at all that iterating ov
Sharu Jiang 2016/05/10 03:11:02 Right, this is not that needed, deleted it.
20 yield self.value
21 yield self.count
22 yield self.occurrences
23
24
25 def DefaultRankFunction(class_info):
Martin Barbella 2016/05/05 18:33:41 This doesn't feel like reasonable default behavior
Sharu Jiang 2016/05/10 03:11:02 Because there won't be any other classifiers any s
Martin Barbella 2016/05/10 06:00:41 Alright, that makes sense. This should be well-com
Sharu Jiang 2016/05/17 19:27:54 Done.
26 """Default rank function to rank classes."""
27 # If the top 2 frames are in the same class, give this class highest
28 # priority.
29 if 0 in class_info.occurrences and 1 in class_info.occurrences:
30 return -constants.INFINITY, class_info.occurrences[0]
31
32 return -class_info.count, class_info.occurrences[0]
33
34
35 class Classifier(object):
36
37 def GetClassFromStackFrame(self, frame): # pragma: no cover.
38 raise NotImplementedError()
39
40 def GetClassFromResult(self, result): # pragma: no cover.
41 raise NotImplementedError()
42
43 def _Classify(self, results, crash_stack, top_n, max_classes,
44 rank_function=DefaultRankFunction):
45 """Classifies a crash to a list of classes.
46
47 Args:
48 results (list of Result): Culprit results.
49 crash_stack (CallStack): The callstack that caused the crash.
50 top_n (int): Number of top frames to be considered when classifying.
51 max_classes (int): Maximal number of classes to return.
52 rank_function (function): Used to rank classes based on ClassInfos.
53
54 Returns:
55 A list of classes of this crash.
56 """
57 # Extract the class list from culprit results since it's more reliable.
58 if results:
59 class_list = map(self.GetClassFromResult, results[:top_n])
60 else:
61 class_list = map(self.GetClassFromStackFrame, crash_stack[:top_n])
62
63 def _GetClassInfos():
64 """Gets ClassInfo list from class_list, the order remains the same."""
65 if not class_list:
66 return class_list
67
68 infos = OrderedDict()
69
70 for index, data_class in enumerate(class_list):
Martin Barbella 2016/05/05 18:33:41 This block is a bit hard to read.
Sharu Jiang 2016/05/10 03:11:02 The variable name and the class name are not very
71 if data_class not in infos:
72 infos[data_class] = ClassInfo(data_class, 1, [index])
73 else:
74 infos[data_class].count += 1
75 infos[data_class].occurrences.append(index)
76
77 return infos.values()
78
79 class_infos = _GetClassInfos()
80 class_infos = sorted(class_infos, key=rank_function)
81
82 classes, _, _ = zip(*class_infos)
83
84 return classes[:max_classes]
85
86 def Classify(self, results, crash_stack): # pragma: no cover.
87 raise NotImplementedError()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698