def Main(argv, pi_report_file=None): parser = argparse.ArgumentParser( description='Runs a PerfInsights report and outputs it to html') corpus_driver_cmdline.AddArguments(parser) if pi_report_file is None: parser.add_argument('pi_report_file') parser.add_argument('--query') parser.add_argument('-j', '--jobs', type=int, default=1) parser.add_argument('--json', action='store_true') parser.add_argument('-o', '--output-file') parser.add_argument('-s', '--stop-on-error', action='store_true') args = parser.parse_args(argv[1:]) corpus_driver = corpus_driver_cmdline.GetCorpusDriver(parser, args) if not args.output_file: parser.error('Must provide -o') if pi_report_file is None: pi_report_file = os.path.abspath(args.pi_report_file) if args.query is None: query = corpus_query.CorpusQuery.FromString('True') else: query = corpus_query.CorpusQuery.FromString(args.query) with codecs.open(args.output_file, mode='w', encoding='utf-8') as ofile: return PiReportToHTML(ofile, corpus_driver, pi_report_file, query, args.json, args.stop_on_error, args.jobs)
def Main(argv): parser = argparse.ArgumentParser(description='Bulk trace processing') corpus_driver_cmdline.AddArguments(parser) parser.add_argument('--query') 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') args = parser.parse_args(argv[1:]) corpus_driver = corpus_driver_cmdline.GetCorpusDriver(parser, args) if args.query == 'help': parser.exit(_CORPUS_QUERY_HELP) elif args.query is None: query = corpus_query.CorpusQuery.FromString('True') else: query = corpus_query.CorpusQuery.FromString(args.query) if args.output_file: ofile = open(args.output_file, 'w') else: ofile = sys.stdout output_formatter = json_output_formatter.JSONOutputFormatter(ofile) try: map_function_handle = function_handle.FunctionHandle.FromUserFriendlyString( args.map_function_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.GetTraceHandlesMatchingQuery(query) runner = map_runner.MapRunner(trace_handles, map_function_handle, stop_on_error=args.stop_on_error, jobs=args.jobs, output_formatters=[output_formatter]) results = runner.Run() if not results.had_failures: return 0 else: return 255 finally: if ofile != sys.stdout: ofile.close()
def Main(argv): parser = argparse.ArgumentParser( description=_DEFAULT_DESCRIPTION) corpus_driver_cmdline.AddArguments(parser) parser.add_argument('--map_function_handle') parser.add_argument('--reduce_function_handle') parser.add_argument('-o', '--output-file') args = parser.parse_args(argv[1:]) corpus_driver = corpus_driver_cmdline.GetCorpusDriver(parser, args) query = corpus_query.CorpusQuery.FromString('True') if not args.output_file: parser.exit("No output file specified.") ofile = open(args.output_file, 'w') output_formatter = json_output_formatter.JSONOutputFormatter(ofile) try: job = None if args.map_function_handle: map_handle = function_handle.FunctionHandle.FromUserFriendlyString( args.map_function_handle) job = job_module.Job(map_handle, None) elif args.reduce_function_handle: reduce_handle = function_handle.FunctionHandle.FromUserFriendlyString( args.reduce_function_handle) job = job_module.Job(None, reduce_handle) except function_handle.UserFriendlyStringInvalidError: parser.error('Either mapper or reducer not specified.') try: trace_handles = corpus_driver.GetTraceHandlesMatchingQuery(query) runner = map_runner.MapRunner(trace_handles, job, stop_on_error=False, jobs=map_runner.AUTO_JOB_COUNT, output_formatters=[output_formatter]) if args.map_function_handle: results = runner.RunMapper() elif args.reduce_function_handle: results = runner.RunReducer(trace_handles) output_formatter.Format(results) return results finally: if ofile != sys.stdout: ofile.close()
def Main(argv): parser = argparse.ArgumentParser(description='Bulk trace processing') corpus_driver_cmdline.AddArguments(parser) parser.add_argument('--query') parser.add_argument('map_file') parser.add_argument('-j', '--jobs', type=int, default=1) parser.add_argument('-o', '--output-file') parser.add_argument('-s', '--stop-on-error', action='store_true') args = parser.parse_args(argv[1:]) corpus_driver = corpus_driver_cmdline.GetCorpusDriver(parser, args) if not os.path.exists(args.map_file): parser.error('Map does not exist.') if args.query == 'help': parser.exit(_CORPUS_QUERY_HELP) elif args.query is None: query = corpus_query.CorpusQuery.FromString('True') else: query = corpus_query.CorpusQuery.FromString(args.query) if args.output_file: ofile = open(args.output_file, 'w') else: ofile = sys.stdout output_formatter = json_output_formatter.JSONOutputFormatter(ofile) map_function_handle = map_function_handle_module.MapFunctionHandle( filename=os.path.abspath(args.map_file)) try: trace_handles = corpus_driver.GetTraceHandlesMatchingQuery(query) runner = map_runner.MapRunner(trace_handles, map_function_handle, stop_on_error=args.stop_on_error) results = runner.Run(jobs=args.jobs, output_formatters=[output_formatter]) if not results.had_failures: return 0 else: return 255 finally: if ofile != sys.stdout: ofile.close()