コード例 #1
0
def Main(argv):
    parser = argparse.ArgumentParser(description='Bulk trace processing')
    parser.add_argument('--map_function_handle')
    parser.add_argument('-j',
                        '--jobs',
                        type=int,
                        default=map_runner.AUTO_JOB_COUNT)
    parser.add_argument('-o', '--output-file')
    parser.add_argument('-s', '--stop-on-error', action='store_true')

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(0)

    args = parser.parse_args(argv[1:])

    corpus_driver = corpus_driver_cmdline.GetCorpusDriver(parser, args)

    if args.output_file:
        ofile = open(args.output_file, 'w')
    else:
        ofile = sys.stdout

    output_formatter = json_output_formatter.JSONOutputFormatter(ofile)

    try:
        map_handle = None
        if args.map_function_handle:
            map_handle = function_handle.FunctionHandle.FromUserFriendlyString(
                args.map_function_handle)
        job = job_module.Job(map_handle)
    except function_handle.UserFriendlyStringInvalidError:
        error_lines = [
            'The map_traces command-line API has changed! You must now specify the',
            'filenames to load and the map function name, separated by :. For '
            'example, a mapper in',
            'foo.html called Foo would be written as foo.html:Foo .'
        ]
        parser.error('\n'.join(error_lines))

    try:
        trace_handles = corpus_driver.GetTraceHandles()
        runner = map_runner.MapRunner(trace_handles,
                                      job,
                                      stop_on_error=args.stop_on_error,
                                      jobs=args.jobs,
                                      output_formatters=[output_formatter])
        results = runner.Run()
        if not any(result.failures for result in results):
            return 0
        else:
            return 255
    finally:
        if ofile != sys.stdout:
            ofile.close()
コード例 #2
0
ファイル: metric_runner.py プロジェクト: wyrover/emblink
def RunMetricOnTraces(filenames, metrics, extra_import_options=None):
    trace_handles = [
        file_handle.URLFileHandle(f, 'file://%s' % f) for f in filenames
    ]
    job = _GetMetricRunnerHandle(metrics)
    runner = map_runner.MapRunner(
        trace_handles,
        job,
        extra_import_options=extra_import_options,
        progress_reporter=gtest_progress_reporter.GTestProgressReporter())
    map_results = runner.RunMapper()
    return map_results
コード例 #3
0
ファイル: metric_runner.py プロジェクト: zloop1982/catapult
def RunMetricOnTraceHandles(trace_handles, metrics, extra_import_options=None,
                            report_progress=True):
  job = _GetMetricRunnerHandle(metrics)
  with open(os.devnull, 'w') as devnull_f:
    o_stream = sys.stdout
    if not report_progress:
      o_stream = devnull_f

    runner = map_runner.MapRunner(
        trace_handles, job, extra_import_options=extra_import_options,
        progress_reporter=gtest_progress_reporter.GTestProgressReporter(
            output_stream=o_stream))
    map_results = runner.RunMapper()

  return map_results
コード例 #4
0
def _ProcessTracesWithMapper(mapper_handle_str, traces, output_file):
    map_handle = function_handle.FunctionHandle.FromUserFriendlyString(
        mapper_handle_str)
    job = job_module.Job(map_handle)

    trace_handles = [
        file_handle.URLFileHandle(f, 'file://%s' % f) for f in traces
    ]

    runner = map_runner.MapRunner(
        trace_handles,
        job,
        progress_reporter=progress_reporter.ProgressReporter())

    results = runner.RunMapper()
    results_dict = {k: v.AsDict() for k, v in results.iteritems()}
    _DumpToOutputJson(results_dict, output_file)

    return _GetExitCodeForResults(results)
コード例 #5
0
def RunMetricOnTraces(filenames,
                      metrics,
                      extra_import_options=None,
                      report_progress=True):
    trace_handles = [
        file_handle.URLFileHandle(f, 'file://%s' % f) for f in filenames
    ]
    job = _GetMetricRunnerHandle(metrics)
    with open(os.devnull, 'w') as devnull_f:
        o_stream = sys.stdout
        if report_progress:
            o_stream = devnull_f

        runner = map_runner.MapRunner(
            trace_handles,
            job,
            extra_import_options=extra_import_options,
            progress_reporter=gtest_progress_reporter.GTestProgressReporter(
                output_stream=o_stream))
        map_results = runner.RunMapper()

    return map_results