| OLD | NEW |
| (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 """TopFrameIndex scorer applies to all Result objects. |
| 6 |
| 7 It represents a heuristic rule: |
| 8 The less the top frame index (this result changed) is, the higher score. |
| 9 """ |
| 10 |
| 11 from crash.scorers.scorer import Scorer |
| 12 |
| 13 _MAX_TOP_N_FRAMES = 7 |
| 14 _INFINITY = 1000 |
| 15 |
| 16 |
| 17 class TopFrameIndex(Scorer): |
| 18 def __init__(self, max_top_n=_MAX_TOP_N_FRAMES): |
| 19 self.max_top_n = max_top_n |
| 20 |
| 21 def GetMetric(self, result): |
| 22 if not result.file_to_stack_infos: |
| 23 return None |
| 24 |
| 25 top_frame_index = _INFINITY |
| 26 for _, stack_infos in result.file_to_stack_infos.iteritems(): |
| 27 for frame, _ in stack_infos: |
| 28 top_frame_index = min(top_frame_index, frame.index) |
| 29 |
| 30 return top_frame_index |
| 31 |
| 32 def Score(self, top_frame_index): |
| 33 # TODO(katesonia): experiment the model and parameters later. |
| 34 if top_frame_index < self.max_top_n: |
| 35 return 1 - top_frame_index / float(self.max_top_n) |
| 36 |
| 37 return 0 |
| 38 |
| 39 def Reason(self, top_frame_index, score): |
| 40 if score == 0: |
| 41 return '' |
| 42 |
| 43 return 'Top frame changed is frame #%d' % top_frame_index |
| OLD | NEW |