示例#1
0
def process_test_logs(name, test_name, test_args, start_time, run_time,
                      log_files):
    """Gather test information and put it in a TestResults proto.

  Args:
    name: Benchmark target identifier.
    test_name:  A unique bazel target, e.g. "//path/to:test"
    test_args:  A string containing all arguments to run the target with.

    start_time: Test starting time (epoch)
    run_time:   Wall time that the test ran for
    log_files:  Paths to the log files

  Returns:
    A TestResults proto
  """

    results = test_log_pb2.TestResults()
    results.name = name
    results.target = test_name
    results.start_time = start_time
    results.run_time = run_time

    # Gather source code information
    git_sha = get_git_commit_sha()
    if git_sha:
        results.commit_id.hash = git_sha

    results.entries.CopyFrom(process_benchmarks(log_files))
    results.run_configuration.argument.extend(test_args)
    results.machine_configuration.CopyFrom(
        system_info_lib.gather_machine_configuration())
    return results
示例#2
0
def store_data_in_json(timing_entries, start_time, output_file=None):
    """Stores benchmark results in JSON format.

  Args:
    timing_entries: list of TimingEntry objects.
    start_time: (datetime) start time of the test run.
    output_file: if specified, writes benchmark results to output_file.
      If not specified, writes results to the file specified by
      BENCHMARK_RESULTS_FILE environment variable.

  Raises:
    ValueError: when neither output_file is passed in nor
      BENCHMARK_RESULTS_FILE is set.
  """
    test_result = test_log_pb2.TestResults(
        start_time=calendar.timegm(start_time.timetuple()))
    if not output_file:
        if _OUTPUT_FILE_ENV_VAR not in os.environ:
            raise ValueError(
                'Could not determine location to store results at.')
        output_file = os.environ[_OUTPUT_FILE_ENV_VAR]

    with gfile.Open(output_file, 'wb') as jsonfile:
        if _TEST_NAME_ENV_VAR in os.environ:
            test_result.name = os.environ['POD_NAME_PREFIX']
        else:
            test_result.name = 'TestBenchmark'

        for timing_entry in timing_entries:
            test_result.entries.entry.add(name=timing_entry.name,
                                          iters=timing_entry.iters,
                                          wall_time=timing_entry.timing)
        json_test_results = json_format.MessageToJson(test_result)
        jsonfile.write(json_test_results)
def process_test_logs(test_name, test_args, start_time, run_time, log_files):
    results = test_log_pb2.TestResults()
    results.target = test_name
    results.start_time = start_time
    results.run_time = run_time
    results.entries.CopyFrom(process_benchmarks(log_files))
    results.run_configuration.argument.extend(test_args)
    results.machine_configuration.CopyFrom(
        system_info_lib.gather_machine_configuration())
    return results
示例#4
0
def store_data_in_json(stat_entries,
                       timestamp,
                       output_file=None,
                       test_name=None):
    """Stores benchmark results in JSON format.

  Args:
    stat_entries: list of StatEntry objects.
    timestamp: (datetime) start time of the test run.
    output_file: if specified, writes benchmark results to output_file.
      Otherwise, if TF_DIST_BENCHMARK_RESULTS_FILE environment variable is set,
      writes to file specified by this environment variable. If neither
      output_file is passed in, nor TF_DIST_BENCHMARK_RESULTS_FILE is set,
      does nothing.
    test_name: benchmark name. This argument is required if
      TF_DIST_BENCHMARK_NAME environment variable is not set.

  Raises:
    ValueError: when neither test_name is passed in nor
      TF_DIST_BENCHMARK_NAME is set.
  """
    test_result = test_log_pb2.TestResults(
        start_time=calendar.timegm(timestamp.timetuple()))
    if not output_file:
        if _OUTPUT_FILE_ENV_VAR not in os.environ:
            logging.warning(
                'Skipping storing json output, since we could not determine '
                'location to store results at. Either output_file argument or '
                '%s environment variable needs to be set.',
                _OUTPUT_FILE_ENV_VAR)
            return
        output_file = os.environ[_OUTPUT_FILE_ENV_VAR]

    if test_name is not None:
        test_result.name = test_name
    elif _TEST_NAME_ENV_VAR in os.environ:
        test_result.name = os.environ[_TEST_NAME_ENV_VAR]
    else:
        raise ValueError(
            'Could not determine test name. test_name argument is not passed in '
            'and TF_DIST_BENCHMARK_NAME environment variable is not set.')

    for stat_entry in stat_entries:
        test_result.entries.entry.add(name=stat_entry.name,
                                      iters=stat_entry.num_samples,
                                      wall_time=stat_entry.stat_value)
    json_test_results = json_format.MessageToJson(test_result)

    with gfile.Open(output_file, 'wb') as jsonfile:
        jsonfile.write(json_test_results)