parameters: (codereview_url,
                                             error_on_unfinished=True,
                                             error_on_try_failure=True)
docstring: Generate bench expectations from a code review.
  
    Scans the given code review for Perf trybot runs. Downloads the results of
    finished trybots and uses them to generate new expectations for their
    waterfall counterparts.
  
    Args:
        url: string; URL of the code review.
        error_on_unfinished: bool; throw an error if any trybot has not finished.
        error_on_try_failure: bool; throw an error if any trybot failed an
            important step.
docstring_summary: Generate bench expectations from a code review.
docstring_tokens: Generate bench expectations from a code review .
function: def gen_bench_expectations_from_codereview(codereview_url,
                                             error_on_unfinished=True,
                                             error_on_try_failure=True):
    """Generate bench expectations from a code review.
  
    Scans the given code review for Perf trybot runs. Downloads the results of
    finished trybots and uses them to generate new expectations for their
    waterfall counterparts.
  
    Args:
        url: string; URL of the code review.
        error_on_unfinished: bool; throw an error if any trybot has not finished.
        error_on_try_failure: bool; throw an error if any trybot failed an
            important step.
    """
    try_builds = find_all_builds(codereview_url)
  
    # Verify that all trybots have finished running.
    if error_on_unfinished and not _all_trybots_finished(try_builds):
      raise TrybotNotFinishedError('Not all trybots have finished.')
  
    failed_run = []
    failed_data_pull = []
    failed_gen_expectations = []
  
    # Don't even try to do anything if BenchPictures, PostBench, or
    # UploadBenchResults failed.
    for try_build in try_builds:
      for step in ('BenchPictures', 'PostBench', 'UploadBenchResults'):
        if not _step_succeeded(try_build, step):
          msg = '%s failed on %s!' % (step, try_build.builder_name)
          if error_on_try_failure:
            raise Exception(msg)
          print 'WARNING: %s Skipping.' % msg
          failed_run.append(try_build.builder_name)
  
    if os.path.isdir(TMP_BENCH_DATA_DIR):
      shutil.rmtree(TMP_BENCH_DATA_DIR)
  
    for try_build in try_builds:
      try_builder = try_build.builder_name
  
      # Even if we're not erroring out on try failures, we can't generate new
      # expectations for failed bots.
      if try_builder in failed_run:
        continue
  
      builder = try_builder.replace('-Trybot', '')
  
      # Download the data.
      dest_dir = os.path.join(TMP_BENCH_DATA_DIR, builder)
      os.makedirs(dest_dir)
      try:
        get_bench_data(try_builder, try_build.build_number, dest_dir)
      except subprocess.CalledProcessError:
        failed_data_pull.append(try_builder)
        continue
  
      # Find the revision at which the data was generated.
      revision = find_revision_from_downloaded_data(dest_dir)
      if not revision:
        # If we can't find a revision, then something is wrong with the data we
        # downloaded. Skip this builder.
        failed_data_pull.append(try_builder)
        continue
  
      # Generate new expectations.
      output_file = os.path.join(CHECKOUT_PATH, 'expectations', 'bench',
                                 'bench_expectations_%s.txt' % builder)
      try:
        subprocess.check_call(['python',
                               os.path.join(CHECKOUT_PATH, 'bench',
                                            'gen_bench_expectations.py'),
                               '-b', builder, '-o', output_file,
                               '-d', dest_dir, '-r', revision])
      except subprocess.CalledProcessError:
        failed_gen_expectations.append(builder)
  
    failure = ''
    if failed_data_pull:
      failure += 'Failed to load data for: %s\n\n' % ','.join(failed_data_pull)
    if failed_gen_expectations:
      failure += 'Failed to generate expectations for: %s\n\n' % ','.join(
          failed_gen_expectations)
    if failure:
      raise Exception(failure)
function_tokens: def gen_bench_expectations_from_codereview ( codereview_url , error_on_unfinished = True , error_on_try_failure = True ) : try_builds = find_all_builds ( codereview_url ) # Verify that all trybots have finished running. if error_on_unfinished and not _all_trybots_finished ( try_builds ) : raise TrybotNotFinishedError ( 'Not all trybots have finished.' ) failed_run = [ ] failed_data_pull = [ ] failed_gen_expectations = [ ] # Don't even try to do anything if BenchPictures, PostBench, or # UploadBenchResults failed. for try_build in try_builds : for step in ( 'BenchPictures' , 'PostBench' , 'UploadBenchResults' ) : if not _step_succeeded ( try_build , step ) : msg = '%s failed on %s!' % ( step , try_build . builder_name ) if error_on_try_failure : raise Exception ( msg ) print 'WARNING: %s Skipping.' % msg failed_run . append ( try_build . builder_name ) if os . path . isdir ( TMP_BENCH_DATA_DIR ) : shutil . rmtree ( TMP_BENCH_DATA_DIR ) for try_build in try_builds : try_builder = try_build . builder_name # Even if we're not erroring out on try failures, we can't generate new # expectations for failed bots. if try_builder in failed_run : continue builder = try_builder . replace ( '-Trybot' , '' ) # Download the data. dest_dir = os . path . join ( TMP_BENCH_DATA_DIR , builder ) os . makedirs ( dest_dir ) try : get_bench_data ( try_builder , try_build . build_number , dest_dir ) except subprocess . CalledProcessError : failed_data_pull . append ( try_builder ) continue # Find the revision at which the data was generated. revision = find_revision_from_downloaded_data ( dest_dir ) if not revision : # If we can't find a revision, then something is wrong with the data we # downloaded. Skip this builder. failed_data_pull . append ( try_builder ) continue # Generate new expectations. output_file = os . path . join ( CHECKOUT_PATH , 'expectations' , 'bench' , 'bench_expectations_%s.txt' % builder ) try : subprocess . check_call ( [ 'python' , os . path . join ( CHECKOUT_PATH , 'bench' , 'gen_bench_expectations.py' ) , '-b' , builder , '-o' , output_file , '-d' , dest_dir , '-r' , revision ] ) except subprocess . CalledProcessError : failed_gen_expectations . append ( builder ) failure = '' if failed_data_pull : failure += 'Failed to load data for: %s\n\n' % ',' . join ( failed_data_pull ) if failed_gen_expectations : failure += 'Failed to generate expectations for: %s\n\n' % ',' . join ( failed_gen_expectations ) if failure : raise Exception ( failure )