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

Side by Side Diff: appengine/findit/crash/culprit.py

Issue 2414523002: [Findit] Reorganizing findit_for_*.py (Closed)
Patch Set: more debugging Created 4 years, 2 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
7 class Culprit(namedtuple('Culprit',
8 ['project', 'components', 'cls', 'regression_range', 'algorithm'])):
9 """The result of successfully identifying the culprit of a crash report.
10
11 Args:
12 project (str): the most-suspected project
13 components (list of str): the suspected crbug components.
14 cls (list of ??): the suspected CLs.
15 regression_range (tuple): a pair of the last-good and first-bad versions.
16 algorithm (str): What algorithm was used to produce this object.
17 """
18 __slots__ = ()
19
20 # TODO(wrengr): better name for this method.
21 def ToDicts(self):
22 """Convert this object to a pair of anonymous dicts for JSON.
23
24 Returns:
25 (analysis_result_dict, tag_dict)
26 The analysis result is a dict like below:
27 {
28 # Indicate if Findit found any suspects_cls, project,
29 # components or regression_range.
30 "found": true,
31 "suspected_project": "chromium-v8", # Which project is most suspected.
32 "feedback_url": "https://.."
33 "suspected_cls": [
34 {
35 "revision": "commit-hash",
36 "url": "https://chromium.googlesource.com/chromium/src/+/...",
37 "review_url": "https://codereview.chromium.org/issue-number",
38 "project_path": "third_party/pdfium",
39 "author": "who@chromium.org",
40 "time": "2015-08-17 03:38:16",
41 "reason": "a plain string with '\n' as line break to expla..."
42 "reason": [('MinDistance', 1, 'minimum distance is 0.'),
43 ('TopFrame', 0.9, 'top frame is2nd frame.')],
44 "changed_files": [
45 {"file": "file_name1.cc",
46 "blame_url": "https://...",
47 "info": "minimum distance (LOC) 0, frame #2"},
48 {"file": "file_name2.cc",
49 "blame_url": "https://...",
50 "info": "minimum distance (LOC) 20, frame #4"},
51 ...
52 ],
53 "confidence": 0.60
54 },
55 ...,
56 ],
57 "regression_range": [ # Detected regression range.
58 "53.0.2765.0",
59 "53.0.2766.0"
60 ],
61 "suspected_components": [ # A list of crbug components to file bugs.
62 "Blink>JavaScript"
63 ]
64 }
65
66 The code review url might not always be available, because not all
67 commits go through code review. In that case, commit url should
68 be used instead.
69
70 The tag dict are allowed key/value pairs to tag the analysis result
71 for query and monitoring purpose on Findit side. For allowed keys,
72 please refer to crash_analysis.py and fracas_crash_analysis.py:
73 For results with normal culprit-finding algorithm: {
74 'found_suspects': True,
75 'has_regression_range': True,
76 'solution': 'core_algorithm',
77 }
78 For results using git blame without a regression range: {
79 'found_suspects': True,
80 'has_regression_range': False,
81 'solution': 'blame',
82 }
83 If nothing is found: {
84 'found_suspects': False,
85 }
86 """
87 # TODO(wrengr): reformulate the JSON stuff so we can drop fields which
88 # are empty; so that, in turn, we can get rid of the NullCulprit class.
89 return (
90 {
91 'found': (bool(self.project) or
92 bool(self.components) or
93 bool(self.cls) or
94 bool(self.regression_range)),
95 'regression_range': self.regression_range,
96 'suspected_project': self.project,
97 'suspected_components': self.components,
98 'suspected_cls': [cl.ToDict() for cl in self.cls],
99 },
100 {
101 'found_suspects': bool(self.cls),
102 'found_project': bool(self.project),
103 'found_components': bool(self.components),
104 'has_regression_range': bool(self.regression_range),
105 'solution': self.algorithm,
106 }
107 )
108
109
110 # TODO(wrengr): ideally we'd be able to refactor things to avoid the
111 # need for this class. Mostly that means (1) refactoring the unittests to
112 # allow Findit.FindCulprit to return None, and (2) reformulating
113 # Culprit.ToDicts to create minimal dicts and reformulating the JSON
114 # protocol to help support that.
115 # TODO(wrengr): if we do end up keeping this class around, we should
116 # do that trick to make it so there's only ever one actual instance and
117 # we simply return the singleton instance every time someone calls the
118 # constructor.
119 class NullCulprit(object):
120 """The result of failing to identify the culprit of a crash report.
121
122 This class serves as a helper so that we can avoid returning None. It
123 has all the same properties and methods as the Culprit class, but
124 returns the empty string, the empty list, or None, as appropriate. The
125 main difference compared to using Culprit with all those falsy values
126 is that the result of the ToDicts method is more minimalistic.
127 """
128 __slots__ = ()
129
130 @property
131 def project(self):
132 return ''
133
134 @property
135 def components(self):
136 return []
137
138 @property
139 def cls(self):
140 return []
141
142 @property
143 def regression_range(self):
144 return None
145
146 @property
147 def algorithm(self):
148 return None
149
150 def ToDicts(self):
151 return (
152 {'found': False},
153 {'found_suspects': False,
154 'has_regression_range': False}
155 )
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698