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

Side by Side Diff: appengine/findit/crash/component_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 and 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 import copy
6 import re
7
8 from crash.classifier import Classifier
9 from model.crash.crash_config import CrashConfig
10
11
12 class ComponentClassifier(Classifier):
13 """Determines the component of a crash.
14
15 For example: ['Blink>DOM', 'Blink>HTML'].
16 """
17
18 def __init__(self):
19 super(ComponentClassifier, self).__init__()
20 self.component_classifier_config = CrashConfig.Get().component_classifier
21
22 def GetClassFromStackFrame(self, frame):
23 """Gets the component from file path and function of a frame."""
24 for path_regex, function_regex, component in (
25 self.component_classifier_config['path_function_component']):
26 path_match = path_regex.match(frame.dep_path + frame.file_path)
27 if not path_match:
28 continue
29
30 if not function_regex:
31 return component
32
33 function_match = function_regex.match(frame.function)
34 if function_match:
35 return component
36
37 return ''
38
39 def GetClassFromResult(self, result):
40 """Gets the component from a result.
41
42 Note that Findit assumes files that the culprit result touched come from
43 the same component.
44 """
45 if result.file_to_stack_infos:
46 # A file in culprit result should always have its stack_info, namely a
47 # list of (frame, callstack_priority) pairs.
48 frame, _ = result.file_to_stack_infos.values()[0][0]
49 return self.GetClassFromStackFrame(frame)
50
51 return ''
52
53 def Classify(self, results, crash_stack):
54 """Classifies project of a crash.
55
56 Args:
57 results (list of Result): Culprit results.
58 crash_stack (CallStack): The callstack that caused the crash.
59
60 Returns:
61 List of top 2 components.
62 """
63 return self._Classify(results, crash_stack,
64 self.component_classifier_config['top_n'], 2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698