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

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

Issue 2518663002: Converting various classes to namedtuples (Closed)
Patch Set: addressing nits Created 4 years, 1 month 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
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from collections import namedtuple 5 from collections import namedtuple
6 6
7 # TODO(http://crbug.com/644476): this class needs a better name. 7 # TODO(http://crbug.com/644476): this class needs a better name.
8 class AnalysisInfo(namedtuple('AnalysisInfo', 8 class AnalysisInfo(namedtuple('AnalysisInfo',
9 ['min_distance', 'min_distance_frame'])): 9 ['min_distance', 'min_distance_frame'])):
10 __slots__ = () 10 __slots__ = ()
11 11
12 12
13 # TODO(wrengr): it's not clear why the ``priority`` is stored at all,
14 # given that every use in this file discards it. ``Result.file_to_stack_infos``
15 # should just store pointers directly to the frames themselves rather
16 # than needing this intermediate object.
17 # TODO(http://crbug.com/644476): this class needs a better name.
18 class StackInfo(namedtuple('StackInfo', ['frame', 'priority'])):
19 """Pair of a frame and the ``priority`` of the ``CallStack`` it came from."""
20 __slots__ = ()
21
22
13 # TODO(http://crbug.com/644476): this class needs a better name. 23 # TODO(http://crbug.com/644476): this class needs a better name.
14 # TODO(http://crbug.com/661822): convert this into a namedtuple.
15 class Result(object): 24 class Result(object):
16 """Represents findit culprit result.""" 25 """Represents findit culprit result."""
17 26
18 def __init__(self, changelog, dep_path, 27 def __init__(self, changelog, dep_path,
19 confidence=None, reasons=None, changed_files=None): 28 confidence=None, reasons=None, changed_files=None):
20 self.changelog = changelog 29 self.changelog = changelog
21 self.dep_path = dep_path 30 self.dep_path = dep_path
22 self.confidence = confidence 31 self.confidence = confidence
23 self.reasons = reasons 32 self.reasons = reasons
24 self.changed_files = changed_files 33 self.changed_files = changed_files
25 34
26 # TODO(wrengr): (a) make these two fields private/readonly 35 # TODO(wrengr): (a) make these two fields private/readonly
27 # TODO(wrengr): (b) zip them together. 36 # TODO(wrengr): (b) zip them together.
28 # TODO(http://crbug.com/661822): change stack_info pair to a namedtuple.
29 self.file_to_stack_infos = {} 37 self.file_to_stack_infos = {}
30 self.file_to_analysis_info = {} 38 self.file_to_analysis_info = {}
31 39
32 def ToDict(self): 40 def ToDict(self):
33 return { 41 return {
34 'url': self.changelog.commit_url, 42 'url': self.changelog.commit_url,
35 'review_url': self.changelog.code_review_url, 43 'review_url': self.changelog.code_review_url,
36 'revision': self.changelog.revision, 44 'revision': self.changelog.revision,
37 'project_path': self.dep_path, 45 'project_path': self.dep_path,
38 'author': self.changelog.author_email, 46 'author': self.changelog.author_email,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 When a file_path is found both shown in stacktrace and touched by 84 When a file_path is found both shown in stacktrace and touched by
77 the revision of this result, update result with the information of 85 the revision of this result, update result with the information of
78 this file. 86 this file.
79 87
80 Inserts the file path and its stack infos, and updates the min distance 88 Inserts the file path and its stack infos, and updates the min distance
81 if less distance is found between touched lines of this result and 89 if less distance is found between touched lines of this result and
82 crashed lines in the file path. 90 crashed lines in the file path.
83 91
84 Args: 92 Args:
85 file_path (str): File path of the crashed file. 93 file_path (str): File path of the crashed file.
86 stack_infos (list): List of (frame, stack_priority), represents frames of 94 stack_infos (list of StackInfo): List of the frames of this file
87 this file and the callstack priorities of those frames. 95 together with their callstack priorities.
88 blame (Blame): Blame oject of this file. 96 blame (Blame): Blame oject of this file.
89 """ 97 """
90 self.file_to_stack_infos[file_path] = stack_infos 98 self.file_to_stack_infos[file_path] = stack_infos
91 99
92 if not blame: 100 if not blame:
93 return 101 return
94 102
95 min_distance = float('inf') 103 min_distance = float('inf')
96 min_distance_frame = stack_infos[0][0] 104 min_distance_frame = stack_infos[0][0]
97 for region in blame: 105 for region in blame:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 """ 169 """
162 for changelog in changelogs: 170 for changelog in changelogs:
163 if self._ignore_cls and changelog.revision in self._ignore_cls: 171 if self._ignore_cls and changelog.revision in self._ignore_cls:
164 continue 172 continue
165 173
166 if changelog.revision not in self: 174 if changelog.revision not in self:
167 self[changelog.revision] = MatchResult(changelog, dep_path) 175 self[changelog.revision] = MatchResult(changelog, dep_path)
168 176
169 match_result = self[changelog.revision] 177 match_result = self[changelog.revision]
170 match_result.Update(file_path, stack_infos, blame) 178 match_result.Update(file_path, stack_infos, blame)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698