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

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: Fix nits and rebase 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
« no previous file with comments | « appengine/findit/crash/crash_util.py ('k') | appengine/findit/crash/results.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.diff import ChangeType
8 from common.git_repository import GitRepository
9 from common.http_client_appengine import HttpClientAppengine
10 from crash import crash_util
11 from crash.results import MatchResults
12 from crash.scorers.aggregator import Aggregator
13 from crash.scorers.min_distance import MinDistance
14 from crash.scorers.top_frame_index import TopFrameIndex
15
16
17 def GetDepsInCrashStack(crash_stack, crash_deps):
18 """Gets Dependencies in crash stack."""
19 if not crash_stack:
20 return {}
21
22 stack_deps = {}
23 for frame in crash_stack:
24 stack_deps[frame.dep_path] = crash_deps[frame.dep_path]
25
26 return stack_deps
27
28
29 def GetChangeLogsForFilesGroupedByDeps(regression_deps_rolls, stack_deps):
30 """Gets a dict containing files touched by changelogs for deps in stack_deps.
31
32 Regression ranges for each dep is determined by regression_deps_rolls.
33 Those changelogs got reverted should be returned in a ignore_cls set.
34
35 Args:
36 regression_deps_rolls (dict): Maps dep_path to DependencyRoll in
37 regression range.
38 stack_deps (dict): Represents all the dependencies shown in
39 the crash stack.
40
41 Returns:
42 A tuple (dep_to_file_to_changelogs, ignore_cls).
43
44 dep_to_file_to_changelogs (dict): Maps dep_path to a dict mapping file path
45 to ChangeLogs that touched this file.
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_to_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'])
88
89 for changelog in changelogs:
90 if changelog.reverted_revision:
91 # Skip reverting cls and add reverted revisions to ignore_cls to later
92 # filter those reverted revisions.
93 ignore_cls.add(changelog.reverted_revision)
94 continue
95
96 for touched_file in changelog.touched_files:
97 if touched_file.change_type == ChangeType.DELETE:
98 continue
99
100 dep_to_file_to_changelogs[dep][touched_file.new_path].append(changelog)
101
102 return dep_to_file_to_changelogs, ignore_cls
103
104
105 def GetStackInfosForFilesGroupedByDeps(stacktrace, stack_deps):
106 """Gets a dict containing all the stack information of files in stacktrace.
107
108 Only gets stack informations for files grouped by deps in stack_deps.
109
110 Args:
111 stacktrace (Stacktrace): Parsed stacktrace object.
112 stack_deps (dict): Represents all the dependencies show in
113 the crash stack.
114
115 Returns:
116 A dict, maps dep path to a dict mapping file path to a list of stack
117 inforamtion of this file. A file may occur in several frames, one stack info
118 consist of a StackFrame and the callstack priority of it.
119
120 For example:
121 {
122 'src/': {
123 'a.cc': [
124 (StackFrame(0, 'src/', '', 'func', 'a.cc', [1]), 0),
125 (StackFrame(2, 'src/', '', 'func', 'a.cc', [33]), 0),
126 ]
127 }
128 }
129 """
130 dep_to_file_to_stack_infos = defaultdict(lambda: defaultdict(list))
131
132 for callstack in stacktrace:
133 for frame in callstack:
134 # We only care about those dependencies in crash stack.
135 if frame.dep_path not in stack_deps:
136 continue
137
138 dep_to_file_to_stack_infos[frame.dep_path][frame.file_path].append((
139 frame, callstack.priority))
140
141 return dep_to_file_to_stack_infos
142
143
144 def GetBlameForFilesGroupedByDeps(stacktrace, stack_deps):
145 """Gets Blames of files in stacktrace for deps in stack_deps.
146
147 Args:
148 stacktrace (Stacktrace): Parsed stacktrace object.
149 stack_deps (dict of Dependencys): Represents all the dependencies shown in
150 the crash stack.
151
152 Returns:
153 A dict, maps dep_path to a dict mapping file path to its Blame.
154
155 For example:
156 {
157 'src/': {
158 'a.cc': Blame(revision, 'a.cc')
159 'b.cc': Blame(revision, 'b.cc')
160 }
161 }
162 """
163 dep_to_file_to_blame = defaultdict(dict)
164
165 for callstack in stacktrace:
166 for frame in callstack:
167 # We only care about those dependencies in crash stack.
168 if frame.dep_path not in stack_deps:
169 continue
170
171 git_repository = GitRepository(stack_deps[frame.dep_path].repo_url,
172 HttpClientAppengine())
173 dep_to_file_to_blame[frame.dep_path][frame.file_path] = (
174 git_repository.GetBlame(
175 frame.file_path, stack_deps[frame.dep_path].revision))
176
177 return dep_to_file_to_blame
178
179
180 def FindMatchResults(dep_to_file_to_changelogs,
181 dep_to_file_to_stack_infos,
182 dep_to_file_to_blame,
183 ignore_cls=None):
184 """Finds results by matching stacktrace and changelogs in regression range.
185
186 This method only applies to those crashes with regression range.
187
188 Args:
189 dep_to_file_to_changelogs (dict): Maps dep_path to a dict mapping file path
190 to ChangeLogs that touched this file.
191 dep_to_file_to_stack_infos (dict): Maps dep path to a dict mapping file path
192 to a list of stack inforamtion of this file. A file may occur in several
193 frames, one stack info consist of a StackFrame and the callstack priority
194 of it.
195 dep_to_file_to_blame (dict): Maps dep_path to a dict mapping file path to
196 its Blame.
197 ignore_cls (set): Set of reverted revisions.
198
199 Returns:
200 A list of MatchResult instances with confidence and reason unset.
201 """
202 match_results = MatchResults(ignore_cls)
203
204 for dep, file_to_stack_infos in dep_to_file_to_stack_infos.iteritems():
205 file_to_changelogs = dep_to_file_to_changelogs[dep]
206
207 for crashed_file_path, stack_infos in file_to_stack_infos.iteritems():
208 for touched_file_path, changelogs in file_to_changelogs.iteritems():
209 if not crash_util.IsSameFilePath(crashed_file_path, touched_file_path):
210 continue
211
212 match_results.GenerateMatchResults(
213 crashed_file_path, dep, stack_infos, changelogs,
214 dep_to_file_to_blame[dep][crashed_file_path])
215
216 return match_results.values()
217
218
219 def FindItForCrash(stacktrace, regression_deps_rolls, crashed_deps):
220 """Finds culprit results for crash.
221
222 Args:
223 stacktrace (Stactrace): Parsed Stactrace object.
224 regression_deps_rolls (dict): Maps dep_path to DependencyRoll in
225 regression range.
226 crashed_deps (dict of Dependencys): Represents all the dependencies of
227 crashed revision.
228
229 Returns:
230 List of dicts of culprit results, sorted by confidence from highest to
231 lowest.
232 """
233 if not regression_deps_rolls:
234 return []
235
236 # We are only interested in the deps in crash stack (the callstack that
237 # caused the crash).
238 stack_deps = GetDepsInCrashStack(stacktrace.GetCrashStack(), crashed_deps)
239
240 # Get dep and file to changelogs, stack_info and blame dicts.
241 dep_to_file_to_changelogs, ignore_cls = GetChangeLogsForFilesGroupedByDeps(
242 regression_deps_rolls, stack_deps)
243 dep_to_file_to_stack_infos = GetStackInfosForFilesGroupedByDeps(
244 stacktrace, stack_deps)
245 dep_to_file_to_blame = GetBlameForFilesGroupedByDeps(stacktrace, stack_deps)
246
247 results = FindMatchResults(dep_to_file_to_changelogs,
248 dep_to_file_to_stack_infos,
249 dep_to_file_to_blame,
250 ignore_cls)
251
252 if not results:
253 return []
254
255 aggregator = Aggregator([TopFrameIndex(), MinDistance()])
256
257 map(aggregator.ScoreAndReason, results)
258
259 return sorted([result.ToDict() for result in results],
260 key=lambda r: -r['confidence'])
OLDNEW
« no previous file with comments | « appengine/findit/crash/crash_util.py ('k') | appengine/findit/crash/results.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698