Chromium Code Reviews| Index: appengine/findit/crash/scorers/top_frame_index.py |
| diff --git a/appengine/findit/crash/scorers/top_frame_index.py b/appengine/findit/crash/scorers/top_frame_index.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c7c5e9e0588eb03b001fce70839ede61bf91a0d1 |
| --- /dev/null |
| +++ b/appengine/findit/crash/scorers/top_frame_index.py |
| @@ -0,0 +1,42 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""TopFrameIndex scorer applies to all Result objects. |
| + |
| +It represents a heuristic rule: |
| + The less the top frame index (this result changed) is, the higher score. |
| +""" |
| + |
| +from crash.scorers.scorer import Scorer |
| + |
| +_MAX_TOP_N_FRAMES = 20 |
| +_INFINITY = 1000 |
| + |
| + |
| +class TopFrameIndex(Scorer): |
| + def __init__(self, max_top_n=_MAX_TOP_N_FRAMES): |
| + self.max_top_n = max_top_n |
| + |
| + def GetMetric(self, result): |
| + if not result.file_to_stack_infos: |
| + return None |
| + |
| + top_frame_index = _INFINITY |
| + for _, stack_infos in result.file_to_stack_infos.iteritems(): |
| + for frame, _ in stack_infos: |
| + top_frame_index = min(top_frame_index, frame.index) |
| + |
| + return top_frame_index |
| + |
| + def Score(self, top_frame_index): |
| + if top_frame_index < self.max_top_n: |
| + return 1 - top_frame_index / float(self.max_top_n) |
|
stgao
2016/04/15 18:35:19
I think this is reasonable, but without experiment
Sharu
2016/04/15 22:59:47
Add a todo
|
| + |
| + return 0 |
| + |
| + def Reason(self, top_frame_index, score): |
| + if score == 0: |
| + return '' |
| + |
| + return 'Top frame changed is frame #%d' % top_frame_index |
|
stgao
2016/04/15 18:35:19
Doesn't "top frame" refer to the first frame?
Sharu
2016/04/15 22:59:47
Not necessarily true I guess, not sure, @mbarbella
|