def _MeasureCurrentBranch(self, run_label, build_dir):
        PrintErr('Measuring...')
        if self.args.num_workers > 1 and len(self.test_cases) > 1:
            results = self._RunAsync(run_label, build_dir)
        else:
            results = self._RunSync(run_label, build_dir)
        PrintErr('Done.')

        return results
Ejemplo n.º 2
0
    def _CreateTempRepo(self, dir_name, relative_build_dir, branch):
        """Clones a temporary git repository out of the current working dir.

    Args:
      dir_name: Name for the temporary repository directory
      relative_build_dir: Path to the build dir in the current working dir to
          clone build args from.
      branch: Branch to checkout in the new repository. None will keep checked
          out the same branch as the local repo.
    Returns:
      Path to the build directory of the new repository.
    """
        cwd = os.getcwd()

        repo_dir = tempfile.mkdtemp(suffix='-%s' % dir_name)
        src_dir = os.path.join(repo_dir, 'pdfium')

        self.git.CloneLocal(os.getcwd(), src_dir)

        if branch is not None:
            os.chdir(src_dir)
            self.git.Checkout(branch)

        os.chdir(repo_dir)
        PrintErr('Syncing...')

        cmd = [
            'gclient', 'config', '--unmanaged',
            'https://pdfium.googlesource.com/pdfium.git'
        ]
        if self.args.cache_dir:
            cmd.append('--cache-dir=%s' % self.args.cache_dir)
        RunCommandPropagateErr(cmd, exit_status_on_error=1)

        RunCommandPropagateErr(['gclient', 'sync', '--force'],
                               exit_status_on_error=1)

        PrintErr('Done.')

        build_dir = os.path.join(src_dir, relative_build_dir)
        os.makedirs(build_dir)
        os.chdir(src_dir)

        source_gn_args = os.path.join(cwd, relative_build_dir, 'args.gn')
        dest_gn_args = os.path.join(build_dir, 'args.gn')
        shutil.copy(source_gn_args, dest_gn_args)

        RunCommandPropagateErr(['gn', 'gen', relative_build_dir],
                               exit_status_on_error=1)

        os.chdir(cwd)

        return build_dir
Ejemplo n.º 3
0
 def _CheckTools(self):
   """Returns whether the tool file paths are sane."""
   if not os.path.exists(self.pdfium_test_path):
     PrintErr(
         "FAILURE: Can't find test executable '%s'" % self.pdfium_test_path)
     PrintErr('Use --build-dir to specify its location.')
     return False
   if not os.access(self.pdfium_test_path, os.X_OK):
     PrintErr("FAILURE: Test executable '%s' lacks execution permissions" %
              self.pdfium_test_path)
     return False
   return True
    def _ProfileLocalChangesAndCurrentBranchInThisRepo(self):
        """Profiles the current branch with and without uncommitted changes.

    This is done in the local repository and changes may not be restored if the
    script fails or is interrupted.

    Returns:
      A tuple (before, after), where each of before and after is a dict
      mapping a test case name to the profiling values for that test case
      using the given version. The current branch without uncommitted changes is
      considered to be "before" and with uncommitted changes is considered to be
      "after".
    """
        self._BuildCurrentBranch(self.after_build_dir)
        after = self._MeasureCurrentBranch('after', self.after_build_dir)

        pushed = self._StashLocalChanges()
        if not pushed and not self.args.build_dir_before:
            PrintErr('Warning: No local changes to compare')

        before_build_dir = self.before_build_dir

        self._BuildCurrentBranch(before_build_dir)
        before = self._MeasureCurrentBranch('before', before_build_dir)

        self._RestoreLocalChanges()

        return before, after
Ejemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('pdf_path',
                        help='test case to measure load and rendering time')
    parser.add_argument('--build-dir',
                        default=os.path.join('out', 'Release'),
                        help='relative path to the build directory with '
                        '%s' % PDFIUM_TEST)
    parser.add_argument('--profiler',
                        default=CALLGRIND_PROFILER,
                        help='which profiler to use. Supports callgrind and '
                        'perfstat for now.')
    parser.add_argument(
        '--interesting-section',
        action='store_true',
        help='whether to measure just the interesting section or '
        'the whole test harness. The interesting section is '
        'pdfium reading a pdf from memory and rendering '
        'it, which omits loading the time to load the file, '
        'initialize the library, terminate it, etc. '
        'Limiting to only the interesting section does not '
        'work on Release since the delimiters are optimized '
        'out. Callgrind only.')
    parser.add_argument('--output-path',
                        help='where to write the profile data output file')
    args = parser.parse_args()

    if args.interesting_section and args.profiler != CALLGRIND_PROFILER:
        PrintErr('--interesting-section requires profiler to be callgrind.')
        return 1

    run = PerformanceRun(args)
    return run.Run()
Ejemplo n.º 6
0
    def Run(self):
        """Runs test harness and measures performance with the given profiler.

    Returns:
      Exit code for the script.
    """
        if not self._CheckTools():
            return 1

        if self.args.profiler == CALLGRIND_PROFILER:
            time = self._RunCallgrind()
        elif self.args.profiler == PERFSTAT_PROFILER:
            time = self._RunPerfStat()
        elif self.args.profiler == NONE_PROFILER:
            time = self._RunWithoutProfiler()
        else:
            PrintErr('profiler=%s not supported, aborting' %
                     self.args.profiler)
            return 1

        if time is None:
            return 1

        print(time)
        return 0
Ejemplo n.º 7
0
  def _BuildCurrentBranch(self, build_dir):
    """Synchronizes and builds the current version of pdfium.

    Args:
      build_dir: String with path to build directory
    """
    PrintErr('Syncing...')
    RunCommandPropagateErr(['gclient', 'sync', '--force'],
                           exit_status_on_error=1)
    PrintErr('Done.')

    PrintErr('Building...')
    cmd = ['ninja', '-C', build_dir, 'pdfium_test']
    if GetBooleanGnArg('use_goma', build_dir):
      cmd.extend(['-j', '250'])
    RunCommandPropagateErr(cmd, stdout_has_errors=True, exit_status_on_error=1)
    PrintErr('Done.')
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'input_paths',
        nargs='+',
        help='pdf files or directories to search for pdf files '
        'to run as test cases')
    parser.add_argument('--branch-before',
                        help='git branch to use as "before" for comparison. '
                        'Omitting this will use the current branch '
                        'without uncommitted changes as the baseline.')
    parser.add_argument('--branch-after',
                        help='git branch to use as "after" for comparison. '
                        'Omitting this will use the current branch '
                        'with uncommitted changes.')
    parser.add_argument('--build-dir',
                        default=os.path.join('out', 'Release'),
                        help='relative path from the base source directory '
                        'to the build directory')
    parser.add_argument('--build-dir-before',
                        help='relative path from the base source directory '
                        'to the build directory for the "before" branch, if '
                        'different from the build directory for the '
                        '"after" branch')
    parser.add_argument('--cache-dir',
                        default=None,
                        help='directory with a new or preexisting cache for '
                        'downloads. Default is to not use a cache.')
    parser.add_argument(
        '--this-repo',
        action='store_true',
        help='use the repository where the script is instead of '
        'checking out a temporary one. This is faster and '
        'does not require downloads, but although it '
        'restores the state of the local repo, if the '
        'script is killed or crashes the changes can remain '
        'stashed and you may be on another branch.')
    parser.add_argument('--profiler',
                        default='callgrind',
                        help='which profiler to use. Supports callgrind and '
                        'perfstat for now. Default is callgrind.')
    parser.add_argument(
        '--interesting-section',
        action='store_true',
        help='whether to measure just the interesting section or '
        'the whole test harness. Limiting to only the '
        'interesting section does not work on Release since '
        'the delimiters are optimized out')
    parser.add_argument('--num-workers',
                        default=multiprocessing.cpu_count(),
                        type=int,
                        help='run NUM_WORKERS jobs in parallel')
    parser.add_argument(
        '--output-dir',
        help='directory to write the profile data output files')
    parser.add_argument('--threshold-significant',
                        default=0.02,
                        type=float,
                        help='variations in performance above this factor are '
                        'considered significant')
    parser.add_argument(
        '--machine-readable',
        action='store_true',
        help='whether to get output for machines. If enabled the '
        'output will be a json with the format specified in '
        'ComparisonConclusions.GetOutputDict(). Default is '
        'human-readable.')
    parser.add_argument('--case-order',
                        default=None,
                        help='what key to use when sorting test cases in the '
                        'output. Accepted values are "after", "before", '
                        '"ratio" and "rating". Default is sorting by test '
                        'case path.')

    args = parser.parse_args()

    # Always start at the pdfium src dir, which is assumed to be two level above
    # this script.
    pdfium_src_dir = os.path.join(os.path.dirname(__file__), os.path.pardir,
                                  os.path.pardir)
    os.chdir(pdfium_src_dir)

    git = GitHelper()

    if args.branch_after and not args.branch_before:
        PrintErr('--branch-after requires --branch-before to be specified.')
        return 1

    if args.branch_after and not git.BranchExists(args.branch_after):
        PrintErr('Branch "%s" does not exist' % args.branch_after)
        return 1

    if args.branch_before and not git.BranchExists(args.branch_before):
        PrintErr('Branch "%s" does not exist' % args.branch_before)
        return 1

    if args.output_dir:
        args.output_dir = os.path.expanduser(args.output_dir)
        if not os.path.isdir(args.output_dir):
            PrintErr('"%s" is not a directory' % args.output_dir)
            return 1

    if args.threshold_significant <= 0.0:
        PrintErr('--threshold-significant should receive a positive float')
        return 1

    run = CompareRun(args)
    return run.Run()
 def _RestoreLocalChanges(self):
     PrintErr('Restoring local changes')
     self.git.StashPopAll()
 def _StashLocalChanges(self):
     PrintErr('Stashing local changes')
     return self.git.StashPush()
 def _CheckoutBranch(self, branch):
     PrintErr("Checking out branch '%s'" % branch)
     self.git.Checkout(branch)