예제 #1
0
def SetUpPKB():
    """Set globals and environment variables for PKB.

  After SetUpPKB() returns, it should be possible to call PKB
  functions, like benchmark_spec.Prepare() or benchmark_spec.Run().

  SetUpPKB() also modifies the local file system by creating a temp
  directory and storing new SSH keys.
  """
    if not FLAGS.ignore_package_requirements:
        requirements.CheckBasicRequirements()

    for executable in REQUIRED_EXECUTABLES:
        if not vm_util.ExecutableOnPath(executable):
            raise errors.Setup.MissingExecutableError(
                'Could not find required executable "%s"', executable)

    if FLAGS.run_uri is None:
        if stages.PROVISION in FLAGS.run_stage:
            FLAGS.run_uri = str(uuid.uuid4())[-8:]
        else:
            # Attempt to get the last modified run directory.
            run_uri = vm_util.GetLastRunUri()
            if run_uri:
                FLAGS.run_uri = run_uri
                logging.warning(
                    'No run_uri specified. Attempting to run the following stages with '
                    '--run_uri=%s: %s', FLAGS.run_uri,
                    ', '.join(FLAGS.run_stage))
            else:
                raise errors.Setup.NoRunURIError(
                    'No run_uri specified. Could not run the following stages: %s'
                    % ', '.join(FLAGS.run_stage))
    elif not FLAGS.run_uri.isalnum() or len(
            FLAGS.run_uri) > MAX_RUN_URI_LENGTH:
        raise errors.Setup.BadRunURIError(
            'run_uri must be alphanumeric and less '
            'than or equal to 8 characters in '
            'length.')

    vm_util.GenTempDir()
    log_util.ConfigureLogging(
        stderr_log_level=log_util.LOG_LEVELS[FLAGS.log_level],
        log_path=vm_util.PrependTempDir(LOG_FILE_NAME),
        run_uri=FLAGS.run_uri,
        file_log_level=log_util.LOG_LEVELS[FLAGS.file_log_level])
    logging.info('PerfKitBenchmarker version: %s', version.VERSION)

    vm_util.SSHKeyGen()

    events.initialization_complete.send(parsed_flags=FLAGS)
예제 #2
0
def _InitializeRunUri():
  """Determines the PKB run URI and sets FLAGS.run_uri."""
  if FLAGS.run_uri is None:
    if stages.PROVISION in FLAGS.run_stage:
      FLAGS.run_uri = str(uuid.uuid4())[-8:]
    else:
      # Attempt to get the last modified run directory.
      run_uri = vm_util.GetLastRunUri()
      if run_uri:
        FLAGS.run_uri = run_uri
        logging.warning(
            'No run_uri specified. Attempting to run the following stages with '
            '--run_uri=%s: %s', FLAGS.run_uri, ', '.join(FLAGS.run_stage))
      else:
        raise errors.Setup.NoRunURIError(
            'No run_uri specified. Could not run the following stages: %s' %
            ', '.join(FLAGS.run_stage))
  elif not FLAGS.run_uri.isalnum() or len(FLAGS.run_uri) > MAX_RUN_URI_LENGTH:
    raise errors.Setup.BadRunURIError('run_uri must be alphanumeric and less '
                                      'than or equal to %d characters in '
                                      'length.' % MAX_RUN_URI_LENGTH)
예제 #3
0
def RunBenchmarks(publish=True):
    """Runs all benchmarks in PerfKitBenchmarker.

  Args:
    publish: A boolean indicating whether results should be published.

  Returns:
    Exit status for the process.
  """
    if FLAGS.version:
        print version.VERSION
        return

    for executable in REQUIRED_EXECUTABLES:
        if not vm_util.ExecutableOnPath(executable):
            logging.error('Could not find required executable "%s".' %
                          executable)
            return 1

    if FLAGS.run_uri is None:
        if FLAGS.run_stage not in [STAGE_ALL, STAGE_PREPARE]:
            # Attempt to get the last modified run directory.
            run_uri = vm_util.GetLastRunUri()
            if run_uri:
                FLAGS.run_uri = run_uri
                logging.warning(
                    'No run_uri specified. Attempting to run "%s" with --run_uri=%s.',
                    FLAGS.run_stage, FLAGS.run_uri)
            else:
                logging.error('No run_uri specified. Could not run "%s".',
                              FLAGS.run_stage)
                return 1
        else:
            FLAGS.run_uri = str(uuid.uuid4())[-8:]
    elif not FLAGS.run_uri.isalnum() or len(
            FLAGS.run_uri) > MAX_RUN_URI_LENGTH:
        logging.error('run_uri must be alphanumeric and less than or equal '
                      'to 10 characters in length.')
        return 1

    vm_util.GenTempDir()
    log_util.ConfigureLogging(
        stderr_log_level=log_util.LOG_LEVELS[FLAGS.log_level],
        log_path=vm_util.PrependTempDir(LOG_FILE_NAME),
        run_uri=FLAGS.run_uri)
    _LogCommandLineFlags()

    if FLAGS.os_type == benchmark_spec.WINDOWS and not vm_util.RunningOnWindows(
    ):
        logging.error('In order to run benchmarks on Windows VMs, you must be '
                      'running on Windows.')
        return 1

    vm_util.SSHKeyGen()
    collector = SampleCollector()
    events.initialization_complete.send(parsed_flags=FLAGS)

    if FLAGS.static_vm_file:
        with open(FLAGS.static_vm_file) as fp:
            static_virtual_machine.StaticVirtualMachine.ReadStaticVirtualMachineFile(
                fp)

    if FLAGS.benchmark_config_pair:
        # Convert benchmark_config_pair into a {benchmark_name: file_name}
        # dictionary.
        tmp_dict = {}
        for config_pair in FLAGS.benchmark_config_pair:
            pair = config_pair.split(':')
            tmp_dict[pair[0]] = pair[1]
        FLAGS.benchmark_config_pair = tmp_dict

    try:
        benchmark_list = benchmark_sets.GetBenchmarksFromFlags()
        total_benchmarks = len(benchmark_list)
        if FLAGS.parallelism > 1:
            sequence_range = range(total_benchmarks, 0, -1)
            args = [((benchmark, collector, sequence_counter,
                      total_benchmarks), {})
                    for benchmark, sequence_counter in zip(
                        benchmark_list, sequence_range)]
            vm_util.RunThreaded(RunBenchmark,
                                args,
                                max_concurrent_threads=FLAGS.parallelism)
        else:
            sequence_range = range(1, total_benchmarks + 1)
            for benchmark, sequence_counter in zip(benchmark_list,
                                                   sequence_range):
                RunBenchmark(benchmark, collector, sequence_counter,
                             total_benchmarks)
    finally:
        if collector.samples:
            collector.PublishSamples()

        logging.info('Complete logs can be found at: %s',
                     vm_util.PrependTempDir(LOG_FILE_NAME))

    if FLAGS.run_stage not in [STAGE_ALL, STAGE_CLEANUP]:
        logging.info('To run again with this setup, please use --run_uri=%s',
                     FLAGS.run_uri)