Exemple #1
0
    def testGetDepPathAndNormalizedFilePathSplitLongPathByDepPath(self):
        """Tests ``GetDepPathAndNormalizedFilePath`` split long path by dep path."""
        deps = {
            'src': Dependency('src', 'https://repo', '1'),
            'src/Upper': Dependency('src/Upper', 'https://repo', '2')
        }

        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('a/b/c/src/d/h.cc',
                                                       deps),
            ('src', 'd/h.cc', 'https://repo'))

        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('a/src/upper/b/c.h',
                                                       deps),
            ('src/Upper', 'b/c.h', 'https://repo'))

        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('../../a/src/c.h',
                                                       deps),
            ('src', 'c.h', 'https://repo'))
Exemple #2
0
    def testGetDepPathAndNormalizedFilePath(self):
        deps = {
            'src': Dependency('src', 'https://repo', '1'),
            'src/Upper': Dependency('src/Upper', 'https://repo_upper', '2')
        }

        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('out/r/gen/b.cc', deps),
            ('', 'out/r/gen/b.cc', None))
        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('src/a/b.cc', deps),
            ('src', 'a/b.cc', 'https://repo'))

        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('src/Upper/a/b.cc',
                                                       deps),
            ('src/Upper', 'a/b.cc', 'https://repo_upper'))
        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('src/upper/a/b.cc',
                                                       deps),
            ('src/Upper', 'a/b.cc', 'https://repo_upper'))
        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('Upper/a/b.cc', deps),
            ('src/Upper', 'a/b.cc', 'https://repo_upper'))
        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('upper/a/b.cc', deps),
            ('src/Upper', 'a/b.cc', 'https://repo_upper'))
        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath(
                'upperdummy/a/b.cc',
                deps,
                root_path='src_root',
                root_repo_url='https://root'),
            ('src_root', 'upperdummy/a/b.cc', 'https://root'))

        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('dummy/path/b.cc',
                                                       deps),
            ('src', 'dummy/path/b.cc', parse_util.CHROMIUM_REPO_URL))

        self.assertEqual(
            parse_util.GetDepPathAndNormalizedFilePath('a.java',
                                                       deps,
                                                       is_java=True),
            ('', 'a.java', None))
Exemple #3
0
    def Parse(frame_dict, index, deps):
        """Convert frame dict into ``ProfilerStackFrame`` object.

    Args:
      frame_dict (dict): Dict representing a stack frame from UMA Sampling
        Profiler.
      index (int): Index (or depth) of the frame in the call stack.
      deps (dict): Map dependency path to its corresponding Dependency.
    Returns: ``ProfilerStackFrame`` object and ``LanguageType`` of the frame.
    """
        difference = frame_dict['difference']
        log_change_factor = frame_dict['log_change_factor']
        responsible = frame_dict['responsible']
        is_java = False
        # the following fields may not be present
        raw_file_path = frame_dict.get('filename')
        if raw_file_path:
            is_java = raw_file_path.endswith('.java')
            dep_path, normalized_file_path, repo_url = (
                parse_util.GetDepPathAndNormalizedFilePath(
                    raw_file_path, deps, is_java))
        else:
            dep_path = None
            normalized_file_path = None
            repo_url = None

        function_name = frame_dict.get('function_name')
        function_start_line = frame_dict.get('function_start_line')
        lines = frame_dict.get('lines')
        if lines:
            lines_old = [
                FunctionLine(line_dict['line'], line_dict['sample_fraction'])
                for line_dict in lines[0]
            ]
            lines_new = [
                FunctionLine(line_dict['line'], line_dict['sample_fraction'])
                for line_dict in lines[1]
            ]
        else:
            lines_old = None
            lines_new = None

        frame_object = ProfilerStackFrame(index, difference, log_change_factor,
                                          responsible, dep_path, function_name,
                                          normalized_file_path, raw_file_path,
                                          repo_url, function_start_line,
                                          lines_old, lines_new)
        language_type = LanguageType.JAVA if is_java else LanguageType.CPP

        return frame_object, language_type
Exemple #4
0
    def Parse(language_type,
              format_type,
              line,
              deps,
              default_stack_frame_index=None):
        """Parse line into a StackFrame instance, if possible.

    Args:
      language_type (LanguageType): the language the line is in.
      format_type (CallStackFormatType): the format the line is in.
      line (str): The line to be parsed.
      deps (dict): Map dependency path to its corresponding Dependency.
      default_stack_frame_index (int): The default stack frame index if index
        cannot be parsed from line.

    Returns:
      A ``StackFrame`` or ``None``.
    """
        # TODO(wrengr): how can we avoid duplicating this logic from ``CallStack``?
        format_type = format_type or _DEFAULT_FORMAT_TYPE

        default_language_type = (LanguageType.JAVA
                                 if format_type == CallStackFormatType.JAVA
                                 else LanguageType.CPP)
        language_type = language_type or default_language_type

        line = line.strip()
        line_pattern = CALLSTACK_FORMAT_TO_PATTERN[format_type]

        if format_type == CallStackFormatType.JAVA:
            match = line_pattern.match(line)
            if not match:
                return None

            function = match.group(1)
            raw_file_path = parse_util.GetFullPathForJavaFrame(function)
            crashed_line_numbers = [int(match.group(3))]

        elif format_type == CallStackFormatType.SYZYASAN:
            match = line_pattern.match(line)
            if not match:
                return None

            function = match.group(2).strip()
            raw_file_path = match.group(5)
            crashed_line_numbers = [int(match.group(6))]

        else:
            line_parts = line.split()
            if not line_parts or not line_parts[0].startswith('#'):
                return None

            match = line_pattern.match(line_parts[-1])
            if not match:  # pragma: no cover
                return None

            function = ' '.join(line_parts[3:-1])

            raw_file_path = match.group(1)
            # Fracas java stack has default format type.
            if language_type == LanguageType.JAVA:
                raw_file_path = parse_util.GetFullPathForJavaFrame(function)

            crashed_line_numbers = parse_util.GetCrashedLineRange(
                match.group(2) + (match.group(3) if match.group(3) else ''))
        # Normalize the file path so that it can be compared to repository path.
        dep_path, file_path, repo_url = parse_util.GetDepPathAndNormalizedFilePath(
            raw_file_path, deps, language_type == LanguageType.JAVA)

        # If we have the common stack frame index pattern, then use it
        # since it is more reliable.
        index_match = FRAME_INDEX_PATTERN.match(line)
        if index_match:
            stack_frame_index = int(index_match.group(1))
        else:
            stack_frame_index = int(default_stack_frame_index or 0)

        return StackFrame(stack_frame_index, dep_path, function, file_path,
                          raw_file_path, crashed_line_numbers, repo_url)