| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 import logging | 5 import logging |
| 6 import math | 6 import math |
| 7 | 7 |
| 8 from crash.loglinear.feature import ChangedFile | 8 from crash.loglinear.feature import ChangedFile |
| 9 from crash.loglinear.feature import Feature | 9 from crash.loglinear.feature import Feature |
| 10 from crash.loglinear.feature import FeatureValue | 10 from crash.loglinear.feature import FeatureValue |
| 11 from crash.loglinear.feature import LogLinearlyScaled | 11 from crash.loglinear.feature import LogLinearlyScaled |
| 12 import libs.math.logarithms as lmath | 12 import libs.math.logarithms as lmath |
| 13 | 13 |
| 14 | 14 |
| 15 class TouchCrashedFileFeature(Feature): | 15 class TouchCrashedFileFeature(Feature): |
| 16 """Returns either log one or log zero. | 16 """Returns either log one or log zero. |
| 17 | 17 |
| 18 When a suspect touched crashed file, we return the log-domain | 18 When a suspect touched crashed file, we return the log-domain |
| 19 value 0 (aka normal-domain value of 1). When the there is no file match, | 19 value 0 (aka normal-domain value of 1). When the there is no file match, |
| 20 we return log-domain value -inf (aka normal-domain value of 0). | 20 we return log-domain value -inf (aka normal-domain value of 0). |
| 21 """ | 21 """ |
| 22 @property | 22 @property |
| 23 def name(self): | 23 def name(self): |
| 24 return 'TouchCrashedFile' | 24 return 'TouchCrashedFile' |
| 25 | 25 |
| 26 def __call__(self, report): | 26 def __call__(self, report): |
| 27 """ | 27 """ |
| 28 Args: | 28 Args: |
| 29 report (CrashReportWithDependencies): the crash report being analyzed. | 29 report (CrashReport): the crash report being analyzed. |
| 30 | 30 |
| 31 Returns: | 31 Returns: |
| 32 A ``FeatureValue`` with name, log-domain value, reason and changed_files. | 32 A ``FeatureValue`` with name, log-domain value, reason and changed_files. |
| 33 """ | 33 """ |
| 34 def FeatureValueGivenReport( | 34 def FeatureValueGivenReport(suspect, matches): # pylint: disable=W0613 |
| 35 suspect, touched_file_to_stack_infos): # pylint: disable=W0613 | |
| 36 """Compute ``FeatureValue`` for a suspect. | 35 """Compute ``FeatureValue`` for a suspect. |
| 37 | 36 |
| 38 Args: | 37 Args: |
| 39 suspect (Suspect): The suspected changelog and some meta information | 38 suspect (Suspect): The suspected changelog and some meta information |
| 40 about it. | 39 about it. |
| 41 touched_file_to_stack_infos(dict): Dict mapping ``FileChangeInfo`` to | 40 matches(dict): Dict mapping crashed group(CrashedFile, CrashedDirectory) |
| 42 a list of ``StackInfo``s representing all the frames that the suspect | 41 to a list of ``Match``s representing all frames and all touched files |
| 43 touched. | 42 matched in the same crashed group(same crashed file or crashed |
| 43 directory). |
| 44 | 44 |
| 45 Returns: | 45 Returns: |
| 46 The ``FeatureValue`` of this feature. | 46 The ``FeatureValue`` of this feature. |
| 47 """ | 47 """ |
| 48 | 48 |
| 49 if not touched_file_to_stack_infos: | 49 if not matches: |
| 50 return FeatureValue( | 50 return FeatureValue( |
| 51 self.name, lmath.LOG_ZERO, | 51 self.name, lmath.LOG_ZERO, |
| 52 'No file got touched by the suspect.', None) | 52 'No file got touched by the suspect.', None) |
| 53 | 53 |
| 54 return FeatureValue( | 54 return FeatureValue( |
| 55 name = self.name, | 55 name = self.name, |
| 56 value = lmath.LOG_ONE, | 56 value = lmath.LOG_ONE, |
| 57 reason = ('Touched files - %s' % ', '.join([ | 57 reason = 'Touched files - %s' % ', '.join([ |
| 58 touched_file.new_path for touched_file, _ in | 58 touched_file.new_path for match in matches.itervalues() |
| 59 touched_file_to_stack_infos.iteritems()])), | 59 for touched_file in match.touched_files]), |
| 60 changed_files = None) | 60 changed_files = None) |
| 61 | 61 |
| 62 return FeatureValueGivenReport | 62 return FeatureValueGivenReport |
| OLD | NEW |