def RunBenchmarks()

in perfkitbenchmarker/pkb.py [0:0]


def RunBenchmarks():
  """Runs all benchmarks in PerfKitBenchmarker.

  Returns:
    Exit status for the process.
  """
  benchmark_specs = _CreateBenchmarkSpecs()
  if FLAGS.randomize_run_order:
    random.shuffle(benchmark_specs)
  if FLAGS.dry_run:
    print('PKB will run with the following configurations:')
    for spec in benchmark_specs:
      print(spec)
      print('')
    return 0

  benchmark_spec_lists = None
  collector = publisher.SampleCollector()
  try:
    tasks = [(RunBenchmarkTask, (spec,), {}) for spec in benchmark_specs]
    if FLAGS.run_processes is None:
      spec_sample_tuples = RunBenchmarkTasksInSeries(tasks)
    else:
      spec_sample_tuples = background_tasks.RunParallelProcesses(
          tasks, FLAGS.run_processes, FLAGS.run_processes_delay
      )
    benchmark_spec_lists, sample_lists = list(zip(*spec_sample_tuples))
    for sample_list in sample_lists:
      collector.samples.extend(sample_list)

  finally:
    if collector.samples:
      collector.PublishSamples()
    # Use the last run in the series of runs.
    if benchmark_spec_lists:
      benchmark_specs = [spec_list[-1] for spec_list in benchmark_spec_lists]
    if benchmark_specs:
      logging.info(benchmark_status.CreateSummary(benchmark_specs))

    logging.info('Complete logs can be found at: %s', log_util.log_local_path)
    logging.info(
        'Completion statuses can be found at: %s',
        vm_util.PrependTempDir(COMPLETION_STATUS_FILE_NAME),
    )

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

  if FLAGS.archive_bucket:
    archive.ArchiveRun(
        vm_util.GetTempDir(),
        FLAGS.archive_bucket,
        gsutil_path=FLAGS.gsutil_path,
        prefix=FLAGS.run_uri + '_',
    )

  # Write completion status file(s)
  if FLAGS.completion_status_file:
    with open(FLAGS.completion_status_file, 'w') as status_file:
      _WriteCompletionStatusFile(benchmark_specs, status_file)
  completion_status_file_name = vm_util.PrependTempDir(
      COMPLETION_STATUS_FILE_NAME
  )
  with open(completion_status_file_name, 'w') as status_file:
    _WriteCompletionStatusFile(benchmark_specs, status_file)

  # Upload PKB logs to GCS after all benchmark runs are complete.
  log_util.CollectPKBLogs(run_uri=FLAGS.run_uri)
  all_benchmarks_succeeded = all(
      spec.status == benchmark_status.SUCCEEDED for spec in benchmark_specs
  )
  return_code = 0 if all_benchmarks_succeeded else 1
  logging.info('PKB exiting with return_code %s', return_code)
  return return_code