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

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

Issue 1861373003: [Findit] Initial code of findit for crash. Add scorers to apply heuristic rules. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Address comments. Created 4 years, 8 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 _INFINITY = 1000
6
7
8 class Result(object):
9
10 def __init__(self, changelog, dep_path, component,
11 confidence=None, reason=None):
12 self.changelog = changelog
13 self.dep_path = dep_path
14 self.component = component
15 self.confidence = confidence
16 self.reason = reason
17
18 self.file_to_stack_infos = {}
19
20 def ToDict(self):
21 return {
22 'url': self.changelog.commit_url,
23 'revision': self.changelog.revision,
24 'dep_path': self.dep_path,
25 'component': self.component,
26 'author': self.changelog.author_email,
27 'time': self.changelog.author_time,
28 'reason': self.reason,
29 'confidence': self.confidence,
30 }
31
32 def ToString(self):
33 if not self.file_to_stack_infos:
34 return ''
35
36 lines = []
37 for file_path, stack_infos in self.file_to_stack_infos.iteritems():
38 line_parts = []
39 for frame, _ in stack_infos:
40 line_parts.append('%s (#%d)' % (frame.function, frame.index))
41
42 lines.append('Changed file %s which crashed in %s' % (
43 file_path, ', '.join(line_parts)))
44
45 return '\n'.join(lines)
46
47 def __str__(self):
48 return self.ToString()
49
50
51 class MatchResult(Result):
52
53 def __init__(self, changelog, dep_path, component,
54 confidence=None, reason=None):
55 super(MatchResult, self).__init__(
56 changelog, dep_path, component, confidence, reason)
57
58 self.min_distance = _INFINITY
59
60 def Update(self, file_path, stack_infos, blame):
61 """Updates match result once a file_path is found both shown in
62 stacktrace and touched by the revision of this result.
63
64 Inserts the file path and its stack infos, and updates the min distance
65 if less distance is found between touched lines of this result and
66 crashed lines in the file path.
67
68 Args:
69 file_path (str): File path of the crashed file.
70 stack_infos (list): List of (StackFrame, callstack priority) tuples,
71 represents frames of this file and the callstack priorities of those
72 frames.
73 blame (Blame): Blame oject of this file.
74 """
75 self.file_to_stack_infos[file_path] = stack_infos
76
77 for region in blame:
78 if region.revision != self.changelog.revision:
79 continue
80
81 region_lines = range(region.start, region.start + region.count)
82
83 for frame, _ in stack_infos:
84 self.min_distance = min(self.min_distance, self._DistanceOfTwoRegions(
85 frame.crashed_line_numbers, region_lines))
86
87 def _DistanceOfTwoRegions(self, region1, region2):
88
Martin Barbella 2016/04/19 22:21:29 Consistent whitespace after defs/docstrings in thi
Sharu Jiang 2016/04/20 18:54:24 Done.
89 if set(region1).intersection(set(region2)):
90 return 0
91
92 if region1[-1] < region2[0]:
93 return region2[0] - region1[-1]
94
95 return region1[0] - region2[-1]
96
97
98 class MatchResults(dict):
99
100 def __init__(self, ignore_cls=None):
101 super(MatchResults, self).__init__()
102 self.ignore_cls = ignore_cls
103
104 def GenerateMatchResults(self, file_path, dep_path,
105 stack_infos, changelogs, blame):
106 """Generates match results based on newly found file path, its stack_infos,
107 and all the changelogs that touched this file in the dep in regression
108 ranges, those reverted changelogs should be ignored.
109
110 Args:
111 file_path (str): File path of the crashed file.
112 dep_path (str): Path of the dependency of the file.
113 stack_infos (list): List of (StackFrame, callstack priority) tuples,
114 represents frames of this file and the callstack priorities of those
115 frames.
116 changelogs (list): List of Changelog objects in the dep in regression
117 range which touched the file.
118 blame (Blame): Blame of the file.
119 """
120
121 for changelog in changelogs:
122 if self.ignore_cls and changelog.revision in self.ignore_cls:
123 continue
124
125 if changelog.revision not in self:
126 # TODO(katesonia): Enable component classifier later. Get it from
127 # file_path and dep_path.
128 component = ''
129 self[changelog.revision] = MatchResult(changelog, dep_path, component)
130
131 match_result = self[changelog.revision]
132
133 match_result.Update(file_path, stack_infos, blame)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698