| OLD | NEW |
| 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 from collections import defaultdict | 6 from collections import defaultdict |
| 7 import logging | 7 import logging |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 from crash.component import Component | 10 from crash.component import Component |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 crash_stack (CallStack): The callstack that caused the crash. | 71 crash_stack (CallStack): The callstack that caused the crash. |
| 72 | 72 |
| 73 Returns: | 73 Returns: |
| 74 List of top 2 components. | 74 List of top 2 components. |
| 75 """ | 75 """ |
| 76 # If ``results`` are available, we use the components from there since | 76 # If ``results`` are available, we use the components from there since |
| 77 # they're more reliable than the ones from the ``crash_stack``. | 77 # they're more reliable than the ones from the ``crash_stack``. |
| 78 if results: | 78 if results: |
| 79 classes = map(self.GetClassFromResult, results[:self.top_n]) | 79 classes = map(self.GetClassFromResult, results[:self.top_n]) |
| 80 else: | 80 else: |
| 81 classes = map(self.GetClassFromStackFrame, crash_stack[:self.top_n]) | 81 classes = map(self.GetClassFromStackFrame, |
| 82 crash_stack.frames[:self.top_n]) |
| 82 | 83 |
| 83 return RankByOccurrence(classes, 2) | 84 return RankByOccurrence(classes, 2) |
| 84 | 85 |
| 85 # TODO(ymzhang): use component of new path as default. RENAME might | 86 # TODO(ymzhang): use component of new path as default. RENAME might |
| 86 # need to return two (old path new path may have different components) | 87 # need to return two (old path new path may have different components) |
| 87 def GetClassFromFileChangeInfo(self, file_change_info): | 88 def GetClassFromFileChangeInfo(self, file_change_info): |
| 88 """Determine which component is responsible for a touched file.""" | 89 """Determine which component is responsible for a touched file.""" |
| 89 if not file_change_info: | 90 if not file_change_info: |
| 90 return None | 91 return None |
| 91 | 92 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 107 top_n: number of components assigned to this change log, default is 2 | 108 top_n: number of components assigned to this change log, default is 2 |
| 108 | 109 |
| 109 Returns: | 110 Returns: |
| 110 List of components | 111 List of components |
| 111 """ | 112 """ |
| 112 if not change_log: | 113 if not change_log: |
| 113 return None | 114 return None |
| 114 | 115 |
| 115 classes = map(self.GetClassFromFileChangeInfo, change_log.touched_files) | 116 classes = map(self.GetClassFromFileChangeInfo, change_log.touched_files) |
| 116 return RankByOccurrence(classes, top_n, rank_function=lambda x:-len(x)) | 117 return RankByOccurrence(classes, top_n, rank_function=lambda x:-len(x)) |
| OLD | NEW |