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

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 = (
21 CrashConfig.Get().compiled_component_classifier)
22
23 def GetClassFromStackFrame(self, frame):
24 """Gets the component from file path and function of a frame."""
25 for path_regex, function_regex, component in (
26 self.component_classifier_config['path_function_component']):
27 path_match = path_regex.match(frame.dep_path + frame.file_path)
28 if not path_match:
29 continue
30
31 if not function_regex:
32 return component
33
34 function_match = function_regex.match(frame.function)
35 if function_match:
36 return component
37
38 return ''
39
40 def GetClassFromResult(self, result):
41 """Gets the component from a result.
42
43 Note that Findit assumes files that the culprit result touched come from
44 the same component.
45 """
46 if result.file_to_stack_infos:
47 # A file in culprit result should always have its stack_info, namely a
48 # list of (frame, callstack_priority) pairs.
49 frame, _ = result.file_to_stack_infos.values()[0][0]
50 return self.GetClassFromStackFrame(frame)
51
52 return ''
53
54 def Classify(self, results, crash_stack):
55 """Classifies project of a crash.
56
57 Args:
58 results (list of Result): Culprit results.
59 crash_stack (CallStack): The callstack that caused the crash.
60
61 Returns:
62 List of top 2 components.
63 """
64 return self._Classify(results, crash_stack,
65 self.component_classifier_config['top_n'], 2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698