Пример #1
0
    def FeatureValueGivenReport(suspect):
      """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.

      Returns:
        The ``FeatureValue`` of this feature.
      """
      grouped_frame_infos = dep_to_grouped_frame_infos.get(suspect.dep_path, {})
      matches = crash_util.MatchSuspectWithFrameInfos(suspect,
                                                      grouped_frame_infos,
                                                      self.Match)

      if not matches:
        return FeatureValue(name=self.name,
                            value=0.0,
                            reason=None,
                            changed_files=None)

      return FeatureValue(
          name=self.name,
          value=1.0,
          reason='\n'.join([str(match) for match in matches.itervalues()]),
          changed_files=None)
Пример #2
0
        def FeatureValueGivenReport(suspect, matches):  # pylint: disable=W0613
            """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.
        matches(dict): Dict mapping crashed group(CrashedFile, CrashedDirectory)
          to a list of ``Match``s representing all frames and all touched files
          matched in the same crashed group(same crashed file or crashed
          directory).

      Returns:
        The ``FeatureValue`` of this feature.
      """

            if not matches:
                return FeatureValue(name=self.name,
                                    value=0.0,
                                    reason=None,
                                    changed_files=None)

            return FeatureValue(name=self.name,
                                value=1.0,
                                reason='Touched files in stacktrace - %s' %
                                ', '.join([
                                    os.path.basename(touched_file.new_path)
                                    for match in matches.itervalues()
                                    for touched_file in match.touched_files
                                ]),
                                changed_files=None)
Пример #3
0
        def FeatureValueGivenReport(suspect):
            """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.

      Returns:
        The ``FeatureValue`` of this feature.
      """
            grouped_frame_infos = dep_to_grouped_frame_infos.get(
                suspect.dep_path, {})
            matches = crash_util.MatchSuspectWithFrameInfos(
                suspect, grouped_frame_infos, self.Match)

            if not matches:
                return FeatureValue(name=self.name,
                                    value=0.0,
                                    reason=None,
                                    changed_files=None)

            crashed_directories = [directory.value for directory in matches]
            plural = len(crashed_directories) > 1

            reason = [
                'Suspected changelist touched file(s) in the %s %s, which '
                'appear%s in the stack trace.' %
                ('directories' if plural else 'directory',
                 ', '.join(crashed_directories), '' if plural else 's')
            ]

            return FeatureValue(name=self.name,
                                value=1.0,
                                reason=reason,
                                changed_files=None)
Пример #4
0
 def __call__(self, x):
   return lambda y: FeatureValue(self.name, y == (x > 5), 'reason0',
                                 [ChangedFile(name='a.cc',
                                              blame_url=None,
                                              reasons=['file_reason0']),
                                  ChangedFile(name='b.cc',
                                              blame_url=None,
                                              reasons=['file_reason0'])])
Пример #5
0
        def FeatureValueGivenReport(suspect, matches):  # pylint: disable=W0613
            """Computes ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.
        matches(dict): Dict mapping crashed group(CrashedFile, CrashedDirectory)
          to a list of ``CrashMatch``s representing all frames and all touched
          files matched in the same crashed group(same crashed file or crashed
          directory).

      Returns:
        The ``FeatureValue`` of this feature.
      """
            if not matches:
                return FeatureValue(name=self.name,
                                    value=0,
                                    reason=None,
                                    changed_files=None)

            def GetMaxIdfInMatches(matches):
                """Gets the maximum idf and the file path with the maximum idf."""
                file_paths = [
                    os.path.join(frame_info.frame.dep_path,
                                 frame_info.frame.file_path)
                    for match in matches.itervalues()
                    for frame_info in match.frame_infos
                ]
                max_idf, max_idf_file_path = max([(ComputeIdf(
                    file_path, self._inverted_index_table), file_path)
                                                  for file_path in file_paths],
                                                 key=lambda item: item[0])

                return max_idf, max_idf_file_path

            logging.info('Computing crash idf feature')
            max_idf, max_idf_file_path = GetMaxIdfInMatches(matches)
            value = LogRegressNomalize(max_idf)
            reason = [
                'Suspected changelist modified the file %s, which is not '
                'commonly changed.' % os.path.basename(max_idf_file_path)
            ]

            return FeatureValue(self.name, value, reason, None)
Пример #6
0
        def FeatureValueGivenReport(suspect, matches):  # pylint: disable=W0613
            """Computes ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.
        matches(dict): Dict mapping crashed group(CrashedFile, CrashedDirectory)
          to a list of ``Match``s representing all frames and all touched files
          matched in the same crashed group(same crashed file or crashed
          directory).

      Returns:
        The ``FeatureValue`` of this feature.
      """
            if not matches:
                return FeatureValue(name=self.name,
                                    value=0,
                                    reason=None,
                                    changed_files=None)

            def TopFrameInMatches(matches):
                frames = [
                    frame_info.frame for match in matches.itervalues()
                    for frame_info in match.frame_infos
                ]
                frames.sort(key=lambda frame: frame.index)
                return frames[0]

            top_frame = TopFrameInMatches(matches)
            value = LinearlyScaled(float(top_frame.index),
                                   float(self.max_frame_index))
            if value <= _MINIMUM_FEATURE_VALUE:
                reason = None
            else:
                reason = 'Top touched frame is #%d %s(in %s)' % (
                    top_frame.index, re.sub('\(.*\)', '', top_frame.function),
                    os.path.basename(top_frame.file_path))

            return FeatureValue(self.name, value, reason, None)
Пример #7
0
        def FeatureValueGivenReport(suspect, matches):  # pylint: disable=W0613
            """Computes ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.
        matches(dict): Dict mapping crashed group(CrashedFile, CrashedDirectory)
          to a list of ``Match``s representing all frames and all touched files
          matched in the same crashed group(same crashed file or crashed
          directory).

      Returns:
        The ``FeatureValue`` of this feature.
      """
            if not matches:
                return FeatureValue(name=self.name,
                                    value=0,
                                    reason=None,
                                    changed_files=None)

            def TopFrameInMatches(matches):
                frames = [
                    frame_info.frame for match in matches.itervalues()
                    for frame_info in match.frame_infos
                ]
                frames.sort(key=lambda frame: frame.index)
                return frames[0]

            top_frame = TopFrameInMatches(matches)
            value = LinearlyScaled(float(top_frame.index),
                                   float(self.max_frame_index))

            # This feature reason is redundant to MinDistance or TouchedCrashedFile
            # features, which also mentioned which files the suspected cl touched with
            # more useful information. So the reason for this feature is not very
            # helpful, we are not providing the reason for this feature.
            return FeatureValue(self.name, value, None, None)
Пример #8
0
        def FeatureValueGivenReport(suspect):
            """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.

      Returns:
        The ``FeatureValue`` of this feature.
      """
            grouped_frame_infos = dep_to_grouped_frame_infos.get(
                suspect.dep_path, {})
            matches = crash_util.MatchSuspectWithFrameInfos(
                suspect, grouped_frame_infos,
                self.GetMatchFunction(suspect.dep_path))

            if not matches:
                return FeatureValue(name=self.name,
                                    value=0.0,
                                    reason=None,
                                    changed_files=None)

            crashed_components = [component.value for component in matches]
            plural = len(crashed_components) > 1

            reason = [
                'Suspected changelist touched file(s) associated with the '
                'component%s %s, which we believe is related to this testcase based '
                'on information in OWNERS files.' %
                ('s' if plural else '', ', '.join(crashed_components))
            ]

            return FeatureValue(name=self.name,
                                value=1.0,
                                reason=reason,
                                changed_files=None)
Пример #9
0
        def FeatureValueGivenReport(suspect):  # pylint: disable=W0613
            """Compute ``FeatureValue`` for a suspect.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.

      Returns:
        The ``FeatureValue`` of this feature.
      """

            number_of_files = len(suspect.changelog.touched_files)
            return FeatureValue(name=self.name,
                                value=LinearlyScaled(number_of_files,
                                                     self._maximum_files,
                                                     self._minimum_files,
                                                     offset=-1.0),
                                reason=None,
                                changed_files=None)
Пример #10
0
    def FeatureValueGivenReport(suspect, matches):
      """Function mapping suspect related data to MinDistance FeatureValue.

      Args:
        suspect (Suspect): The suspected changelog and some meta information
          about it.
        matches(dict): Dict mapping crashed group(CrashedFile, CrashedDirectory)
          to a list of ``Match``s representing all frames and all touched files
          matched in the same crashed group(same crashed file or crashed
          directory).

      Returns:
        The ``FeatureValue`` of this feature.
      """
      if not matches:
        FeatureValue(name=self.name,
                     value=0.0,
                     reason=None,
                     changed_files=None)

      distance = Distance(float('inf'), None)
      touched_file_to_distance = {}
      for match in matches.itervalues():
        if len(match.touched_files) != 1:
          logging.warning('There should be only one touched file per crashed '
                          'file group.')
          continue

        touched_file = match.touched_files[0]
        # Records the closest frame (the frame has minimum distance between
        # crashed lines and touched lines) for each touched file of the suspect.
        distance_per_file = self.DistanceBetweenTouchedFileAndFrameInfos(
            suspect.changelog.revision, touched_file,
            match.frame_infos, report.dependencies[suspect.dep_path])
        # Failed to get blame information of a file.
        if not distance_per_file:
          logging.warning('suspect\'s change cannot be blamed due to lack of'
                          'blame information for crashed file %s' %
                          touched_file.new_path)
          continue

        # It is possible that a changelog doesn't show in the blame of a file,
        # in this case, treat the changelog as if it didn't change the file.
        if distance_per_file.IsInfinity():
          continue

        touched_file_to_distance[touched_file] = distance_per_file
        distance.Update(distance_per_file.distance,
                        distance_per_file.frame)

      value = LinearlyScaled(float(distance.distance), float(self._maximum))
      if distance.frame is not None:
        current_distance = int(distance.distance)
        file_name = os.path.basename(distance.frame.file_path)
        if current_distance == 0:
          reason = [
              'Suspected changelist touched the crashing line in ' + file_name]
        else:
          plural = current_distance > 1
          reason = [
              'Suspected changelist touched line(s) near the crashing line in '
              '%s (%d line%s away)' % (file_name, current_distance,
                                       's' if plural else '')]
      else:
        reason = None

      if value <= _MINIMUM_FEATURE_VALUE:
        changed_files = None
      else:
        changed_files = MinDistanceFeature.ChangedFiles(
              suspect, touched_file_to_distance,
              report.crashed_version)

      return FeatureValue(name=self.name,
                          value=value,
                          reason=reason,
                          changed_files=changed_files)
Пример #11
0
 def __call__(self, x):
   return lambda y: FeatureValue(self.name, y == (x < 9), None, None)
Пример #12
0
 def __call__(self, x):
   return lambda y: FeatureValue(self.name, y == (x <= 7), 'reason2', None)
Пример #13
0
 def __call__(self, x):
   return lambda y: FeatureValue(self.name, y == ((x % 2) == 1), 'reason1',
                                 [ChangedFile(name='b.cc',
                                              blame_url=None,
                                              reasons=['file_reason1'])])