Exemple #1
0
def MakeFailedRunSample(error_message, run_stage_that_failed):
    """Create a sample.Sample representing a failed run stage.

  The sample metric will have the name 'Run Failed';
  the value will be 1 (has to be convertable to a float),
  and the unit will be 'Run Failed' (for lack of a better idea).

  The sample metadata will include the error message from the
  Exception, the run stage that failed, as well as all PKB
  command line flags that were passed in.

  Args:
    error_message: error message that was caught, resulting in the
      run stage failure.
    run_stage_that_failed: run stage that failed by raising an Exception

  Returns:
    a sample.Sample representing the run stage failure.
  """
    # Note: currently all provided PKB command line flags are included in the
    # metadata. We may want to only include flags specific to the benchmark that
    # failed. This can be acomplished using gflag's FlagsByModuleDict().
    metadata = {
        'error_message':
        error_message[0:FLAGS.failed_run_samples_error_length],
        'run_stage': run_stage_that_failed,
        'flags': str(flag_util.GetProvidedCommandLineFlags())
    }
    return [sample.Sample('Run Failed', 1, 'Run Failed', metadata)]
Exemple #2
0
def MakeFailedRunSample(spec, error_message, run_stage_that_failed):
  """Create a sample.Sample representing a failed run stage.

  The sample metric will have the name 'Run Failed';
  the value will be 1 (has to be convertible to a float),
  and the unit will be 'Run Failed' (for lack of a better idea).

  The sample metadata will include the error message from the
  Exception, the run stage that failed, as well as all PKB
  command line flags that were passed in.

  Args:
    spec: benchmark_spec
    error_message: error message that was caught, resulting in the
      run stage failure.
    run_stage_that_failed: run stage that failed by raising an Exception

  Returns:
    a sample.Sample representing the run stage failure.
  """
  # Note: currently all provided PKB command line flags are included in the
  # metadata. We may want to only include flags specific to the benchmark that
  # failed. This can be acomplished using gflag's FlagsByModuleDict().
  metadata = {
      'error_message': error_message[0:FLAGS.failed_run_samples_error_length],
      'run_stage': run_stage_that_failed,
      'flags': str(flag_util.GetProvidedCommandLineFlags())
  }

  def UpdateVmStatus(vm):
    vm.UpdateInterruptibleVmStatus()
  vm_util.RunThreaded(UpdateVmStatus, spec.vms)

  interruptible_vm_count = 0
  interrupted_vm_count = 0
  vm_status_codes = []
  for vm in spec.vms:
    if vm.IsInterruptible():
      interruptible_vm_count += 1
      if vm.WasInterrupted():
        interrupted_vm_count += 1
        spec.failed_substatus = (
            benchmark_status.FailedSubstatus.INTERRUPTED)
        status_code = vm.GetVmStatusCode()
        if status_code:
          vm_status_codes.append(status_code)

  if spec.failed_substatus:
    metadata['failed_substatus'] = spec.failed_substatus

  if interruptible_vm_count:
    metadata.update({'interruptible_vms': interruptible_vm_count,
                     'interrupted_vms': interrupted_vm_count,
                     'vm_status_codes': vm_status_codes})
  if interrupted_vm_count:
    logging.error(
        '%d interruptible VMs were interrupted in this failed PKB run.',
        interrupted_vm_count)
  return [sample.Sample('Run Failed', 1, 'Run Failed', metadata)]
Exemple #3
0
def PublishRunStartedSample(spec):
    """Publishes a sample indicating that a run has started.

  This sample is published immediately so that there exists some metric for any
  run (even if the process dies).

  Args:
    spec: The BenchmarkSpec object with run information.
  """
    collector = SampleCollector()
    metadata = {'flags': str(flag_util.GetProvidedCommandLineFlags())}
    collector.AddSamples(
        [sample.Sample('Run Started', 1, 'Run Started', metadata)], spec.name,
        spec)
    collector.PublishSamples()
 def testGetProvidedCommandLineFlags(self):
   self.assertDictEqual({
       'flag1': '1',
       'flag2': '2',
   }, flag_util.GetProvidedCommandLineFlags())