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

Side by Side Diff: appengine/findit/crash/findit_for_crash.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 from collections import defaultdict
6
7 from common import chromium_deps
8 from common.change_log import ChangeLog
9 from common.git_repository import GitRepository
10 from common.http_client_appengine import HttpClientAppengine
11 from crash import crash_util
12 from crash.results import MatchResult, MatchResults
13 from crash.scorers.aggregator import Aggregator
14 from crash.scorers.top_frame_index import TopFrameIndex
15 from crash.scorers.min_distance import MinDistance
16
17
18 def GetDepsInCrashStack(crash_stack, crash_deps):
19 """Gets Dependencies in crash stack."""
20 if not crash_stack:
21 return {}
22
23 stack_deps = {}
24 for frame in crash_stack:
25 stack_deps[frame.dep_path] = crash_deps[frame.dep_path]
26
27 return stack_deps
28
29
30 def GetDepFileToChangeLogsAndIgnoreCls(regression_deps_rolls, stack_deps):
Martin Barbella 2016/04/18 21:01:18 In general I'm not a fan of these function names.
Sharu Jiang 2016/04/19 20:38:37 How about I change the name to 'GetFileToChangelog
Martin Barbella 2016/04/19 22:21:28 Seems better, but potentially still problematic. T
31 """For those deps we concern, gets a dict containing all the files touched by
32 changelogs in regressoin range and a set of revisions that should be ignored.
Martin Barbella 2016/04/18 21:01:18 s/regressoin/regression/
Sharu Jiang 2016/04/19 20:38:37 Done.
33
34 Args:
35 regression_deps_rolls (dict): Maps dep_path to DependencyRoll in
36 regression range.
37 stack_deps (dict): Represents all the dependencies show in
38 the crash stack.
39
40 Returns:
41 A tuple (dep_file_to_changelogs, ignore_cls).
42
43 dep_file_to_changelogs (dict): Maps dep_path to a dict mapping file path
44 to ChangeLogs that touched this file.
45
46 For example:
47 {
48 'src/': {
49 'a.cc': [
50 ChangeLog.FromDict({
51 'author_name': 'test@chromium.org',
52 'message': 'dummy',
53 'committer_email': 'example@chromium.org',
54 'commit_position': 175976,
55 'author_email': 'example@chromium.org',
56 'touched_files': [
57 {
58 'change_type': 'add',
59 'new_path': 'a.cc',
60 'old_path': 'b/a.cc'
61 },
62 ...
63 ],
64 'author_time': 'Thu Mar 31 21:24:43 2016',
65 'committer_time': 'Thu Mar 31 21:28:39 2016',
66 'commit_url':
67 'https://repo.test/+/bcfd',
68 'code_review_url': 'https://codereview.chromium.org/3281',
69 'committer_name': 'example@chromium.org',
70 'revision': 'bcfd',
71 'reverted_revision': None
72 }),
73 ]
74 }
75 }
76
77 ignore_cls (set): A set of reverted revisions.
78 """
79 dep_file_to_changelogs = defaultdict(lambda: defaultdict(list))
80 ignore_cls = set()
81
82 for dep in stack_deps:
83 dep_roll = regression_deps_rolls[dep]
84
85 git_repository = GitRepository(dep_roll['repo_url'], HttpClientAppengine())
86 changelogs = git_repository.GetChangeLogs(dep_roll['old_revision'],
87 dep_roll['new_revision'])
Martin Barbella 2016/04/18 21:01:18 Indentation.
Sharu Jiang 2016/04/19 20:38:37 Done.
88
89 for changelog in changelogs:
90 if changelog.reverted_revision:
91 # Add reverted revisions to ignore_cls to filter those reverted
92 # revisions later while matching cls.
93 ignore_cls.add(changelog.reverted_revision)
94 continue
95
96 for touched_file in changelog.touched_files:
97 # If a dependency is deleted or is a .h file, skip this file.
98 if (touched_file.change_type == 'delete' or
99 touched_file.new_path.endswith('.h')):
100 continue
101
102 dep_file_to_changelogs[dep][touched_file.new_path].append(changelog)
103
104 return dep_file_to_changelogs, ignore_cls
105
106
107 def GetDepFileToStackInfos(stacktrace):
108 """Gets a dict containing all the stack information of files in stacktrace.
109
110 Args:
111 stacktrace (Stacktrace): Parsed stacktrace object.
112
113 Returns:
114 A dict, maps dep path to a dict mapping file path to a list of stack
115 inforamtion of this file. A file may occur in several frames, one stack info
116 consist of a StackFrame and the callstack priority of it.
117
118 For example:
119 {
120 'src/': {
121 'a.cc': [
122 (StackFrame(0, 'src/', '', 'func', 'a.cc', [1]), 0),
123 (StackFrame(2, 'src/', '', 'func', 'a.cc', [33]), 0),
124 ]
125 }
126 }
127 """
128 dep_file_to_stack_infos = defaultdict(lambda: defaultdict(list))
129
130 for callstack in stacktrace:
131 for frame in callstack:
132 if frame.file_path.endswith('.h'):
133 continue
134
135 dep_file_to_stack_infos[frame.dep_path][frame.file_path].append((
136 frame, callstack.priority))
137
138 return dep_file_to_stack_infos
139
140
141 def GetDepFileToBlame(stacktrace, stack_deps):
142 """Gets Blames for files in stacktrace.
143
144 Args:
145 stacktrace (Stacktrace): Parsed stacktrace object.
146 stack_deps (dict of Dependencys): Represents all the dependencies shown in
147 the crash stack.
148
149 Returns:
150 A dict, maps dep_path to a dict mapping file path to its Blame.
151
152 For example:
153 {
154 'src/': {
155 'a.cc': Blame(revision, 'a.cc')
156 'b.cc': Blame(revision, 'b.cc')
157 }
158 }
159 """
160 dep_file_to_blame = defaultdict(dict)
161 for callstack in stacktrace:
162 for frame in callstack:
163 # We only care about those dependencies in crash stack.
164 if frame.dep_path not in stack_deps:
165 continue
166
167 git_repository = GitRepository(stack_deps[frame.dep_path].repo_url,
168 HttpClientAppengine())
169 dep_file_to_blame[frame.dep_path][frame.file_path] = (
170 git_repository.GetBlame(
171 frame.file_path, stack_deps[frame.dep_path].revision))
172 return dep_file_to_blame
173
174
175 def FindMatchResults(dep_file_to_changelogs,
176 dep_file_to_stack_infos,
177 dep_file_to_blame,
178 ignore_cls=None):
179 """Finds culprit results by matching stacktrace and changelogs in regression
180 range. This method only applies to those crashes with regression range.
181
182 Args:
183 dep_file_to_changelogs (dict): Maps dep_path to a dict mapping file path
184 to ChangeLogs that touched this file.
185
186 dep_file_to_stack_infos (dict): Maps dep path to a dict mapping file path
187 to a list of stack inforamtion of this file. A file may occur in several
188 frames, one stack info consist of a StackFrame and the callstack priority
189 of it.
190
191 dep_file_to_blame (dict): Maps dep_path to a dict mapping file path to
192 its Blame.
193
194 ignore_cls (set): Set of reverted revisions.
195
196 Returns:
197 A list of MatchResult instances with confidence and reason unset.
198 """
199 match_results = MatchResults(ignore_cls)
200
201 for dep, file_to_stack_infos in dep_file_to_stack_infos.iteritems():
202 for crashed_file_path, stack_infos in file_to_stack_infos.iteritems():
203
204 file_to_changelogs = dep_file_to_changelogs[dep]
205 for touched_file_path, changelogs in file_to_changelogs.iteritems():
206 if not crash_util.IsSameFilePath(crashed_file_path, touched_file_path):
207 continue
208
209 match_results.GenerateMatchResults(
210 crashed_file_path, dep, stack_infos, changelogs,
211 dep_file_to_blame[dep][crashed_file_path])
212
213 return match_results.values()
214
215
216 def FindItForCrash(stacktrace, regression_range, crash_revision, platform):
217 """Finds culprit results for crash.
218
219 Args:
220 stacktrace (Stactrace): Parsed Stactrace object.
221 regression_range (tuple or None): A tuple of githash strs -
222 (good_revision, bad_revision), None if no regression range provided.
223 crash_revision (str): The crashed revision githash str.
224 platform (str): The target platform of the Chrome build, should be one of
225 'win', 'ios', 'mac', 'unix', 'android'.
226
227 Returns:
228 List of dicts of culprit results, sorted by confidence from highest to
229 lowest.
230 """
231
232 if not regression_range:
233 return []
234
235 good_revision, bad_revision = regression_range
236
237 # Get regression deps and crash deps.
238 # Right now we only care about those deps for all platforms.
Martin Barbella 2016/04/18 21:01:18 Should this be a TODO?
Sharu Jiang 2016/04/19 20:38:37 Sorry, this is a deprecated comment, should delete
239 regression_deps_rolls = chromium_deps.GetDEPSRollsDict(
240 good_revision, bad_revision, platform)
241 crash_deps = chromium_deps.GetChromeDependency(crash_revision, platform)
242
243 crash_stack = stacktrace.GetCrashStack()
244 stack_deps = GetDepsInCrashStack(crash_stack, crash_deps)
245
246 # Get dep and file to changelogs, stack_info and blame dicts.
247 dep_file_to_changelogs, ignore_cls = GetDepFileToChangeLogsAndIgnoreCls(
248 regression_deps_rolls, stack_deps)
249 dep_file_to_stack_infos = GetDepFileToStackInfos(stacktrace)
250 dep_file_to_blame = GetDepFileToBlame(stacktrace, stack_deps)
251
252 results = FindMatchResults(dep_file_to_changelogs,
253 dep_file_to_stack_infos,
254 dep_file_to_blame,
255 ignore_cls)
256
257 if not results:
258 return []
259
260 aggregator = Aggregator([TopFrameIndex(), MinDistance()])
261
262 map(aggregator.ScoreAndReason, results)
263
264 return sorted([result.ToDict() for result in results],
265 key=lambda r: -r['confidence'])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698