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

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: Fix nits and doc strings. 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 changelog_json = self.changelog.ToDict()
stgao 2016/04/15 18:35:19 This seems unnecessary as we only refer to several
Sharu 2016/04/15 22:59:47 Done.
22 return {
23 'url': changelog_json['commit_url'],
24 'revision': changelog_json['revision'],
25 'dep_path': self.dep_path,
26 'component': self.component,
27 'author': changelog_json['author_email'],
28 'time': changelog_json['author_time'],
29 'reason': self.reason,
30 'confidence': self.confidence,
31 }
32
33 def ToString(self):
34 if not self.file_to_stack_infos:
35 return ''
36
37 lines = []
38 for file_path, stack_infos in self.file_to_stack_infos.iteritems():
39 line_parts = []
40 for frame, _ in stack_infos:
41 line_parts.append('%s (#%d)' % (frame.function, frame.index))
42
43 lines.append('Changed file %s which crashed in %s' % (
44 file_path, ', '.join(line_parts)))
45
46 return '\n'.join(lines)
47
48 def __str__(self):
49 return self.ToString()
50
51 def __repr__(self):
52 return self.ToString()
53
54
55 class MatchResult(Result):
56
57 def __init__(self, changelog, dep_path, component,
58 confidence=None, reason=None):
59 super(MatchResult, self).__init__(
60 changelog, dep_path, component, confidence, reason)
61
62 self.min_distance = _INFINITY
63
64 def Update(self, file_path, stack_infos, blame):
65 """Updates match result once a file_path is found both shown in
66 stacktrace and touched by the changelog of this result.
stgao 2016/04/15 18:35:19 changelog here might not be that clear enough. It
Sharu 2016/04/15 22:59:47 Done.
67
68 Inserts the file path and its stack infos, and updates the min distance
69 if less distance is found between touched lines of this result and
70 crashed lines in the file path.
71
72 Args:
73 file_path (str): File path of the crashed file.
74 stack_infos (list): List of (StackFrame, callstack priority) tuples,
75 represents frames of this file and the callstack priorities of those
76 frames.
77 blame (Blame): Blame oject of this file.
78 """
79 self.file_to_stack_infos[file_path] = stack_infos
80
81 for region in blame:
82 if region.revision != self.changelog.revision:
83 continue
84
85 region_lines = range(region.start, region.start + region.count)
86
87 for frame, _ in stack_infos:
88 self.min_distance = min(self.min_distance, self._DistanceOfTwoRegions(
89 frame.crashed_line_numbers, region_lines))
90
91 def _DistanceOfTwoRegions(self, region1, region2):
92
93 if set(region1).intersection(set(region2)):
94 return 0
95
96 if region1[-1] < region2[0]:
97 return region2[0] - region1[-1]
98
99 return region1[0] - region2[-1]
100
101
102 class MatchResults(dict):
103
104 def __init__(self, ignore_cls=None):
105 super(MatchResults, self).__init__()
106 self.ignore_cls = ignore_cls
107
108 def GenerateMatchResults(self, file_path, dep_path,
109 stack_infos, changelogs, blame):
110 """Generates match results based on newly found file path, its stack_infos,
111 and all the changelogs that touched this file in the dep in regression
112 ranges, those reverted changelogs should be ignored.
113
114 Args:
115 file_path (str): File path of the crashed file.
116 dep_path (str): Path of the dependency of the file.
117 stack_infos (list): List of (StackFrame, callstack priority) tuples,
118 represents frames of this file and the callstack priorities of those
119 frames.
120 changelogs (list): List of Changelog objects in the dep in regression
121 range which touched the file.
122 blame (Blame): Blame of the file.
123 """
124
125 for changelog in changelogs:
126 if self.ignore_cls and changelog.revision in self.ignore_cls:
127 continue
128
129 if changelog.revision not in self:
130 # TODO(katesonia): Enable component classifier later. Get it from
131 # file_path and dep_path.
132 component = ''
133 self[changelog.revision] = MatchResult(changelog, dep_path, component)
134
135 match_result = self[changelog.revision]
136
137 match_result.Update(file_path, stack_infos, blame)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698