| OLD | NEW |
| (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 class NullCulprit(object): |
| 116 """The result of failing to identify the culprit of a crash report. |
| 117 |
| 118 This class serves as a helper so that we can avoid returning None. It |
| 119 has all the same properties and methods as the Culprit class, but |
| 120 returns the empty string, the empty list, or None, as appropriate. The |
| 121 main difference compared to using Culprit with all those falsy values |
| 122 is that the result of the ToDicts method is more minimalistic. |
| 123 """ |
| 124 __slots__ = () |
| 125 |
| 126 @property |
| 127 def project(self): |
| 128 return '' |
| 129 |
| 130 @property |
| 131 def components(self): |
| 132 return [] |
| 133 |
| 134 @property |
| 135 def cls(self): |
| 136 return [] |
| 137 |
| 138 @property |
| 139 def regression_range(self): |
| 140 return None |
| 141 |
| 142 @property |
| 143 def algorithm(self): |
| 144 return None |
| 145 |
| 146 def ToDicts(self): |
| 147 return ( |
| 148 {'found': False}, |
| 149 {'found_suspects': False, |
| 150 'has_regression_range': False} |
| 151 ) |
| OLD | NEW |