From 4f6decadc5a49ad0285e1af314cd7e43ee59a236 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Tue, 14 Feb 2017 18:18:58 +0000 Subject: [PATCH] [opt-viewer] For single-process, fall back on map instead of Pool.map This allows for nicer backtrace and debugging when -j1 is passed: $ opt-viewer.py CMakeFiles/LLVMScalarOpts.dir/LoopVersioningLICM.cpp.opt.yaml html Traceback (most recent call last): File "/org/llvm/utils/opt-viewer/opt-viewer.py", line 405, in generate_report(pmap, all_remarks, file_remarks, args.source_dir, args.output_dir) File "/org/llvm/utils/opt-viewer/opt-viewer.py", line 362, in generate_report pmap(_render_file_bound, file_remarks.items()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 567, in get raise self._value Exception: blah $ opt-viewer.py -j 1 CMakeFiles/LLVMScalarOpts.dir/LoopVersioningLICM.cpp.opt.yaml html Traceback (most recent call last): File "/org/llvm/utils/opt-viewer/opt-viewer.py", line 405, in generate_report(pmap, all_remarks, file_remarks, args.source_dir, args.output_dir) File "/org/llvm/utils/opt-viewer/opt-viewer.py", line 362, in generate_report pmap(_render_file_bound, file_remarks.items()) File "/org/llvm/utils/opt-viewer/opt-viewer.py", line 317, in _render_file SourceFileRenderer(source_dir, output_dir, filename).render(remarks) File "/org/llvm/utils/opt-viewer/opt-viewer.py", line 168, in __init__ raise Exception("blah") Exception: blah llvm-svn: 295080 --- llvm/utils/opt-viewer/opt-viewer.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/llvm/utils/opt-viewer/opt-viewer.py b/llvm/utils/opt-viewer/opt-viewer.py index 31fd79959461..f5a20666d361 100755 --- a/llvm/utils/opt-viewer/opt-viewer.py +++ b/llvm/utils/opt-viewer/opt-viewer.py @@ -316,8 +316,8 @@ def _render_file(source_dir, output_dir, ctx, entry): SourceFileRenderer(source_dir, output_dir, filename).render(remarks) -def gather_results(pool, filenames): - remarks = pool.map(get_remarks, filenames) +def gather_results(pmap, filenames): + remarks = pmap(get_remarks, filenames) def merge_file_remarks(file_remarks_job, all_remarks, merged): for filename, d in file_remarks_job.iteritems(): @@ -348,7 +348,7 @@ def map_remarks(all_remarks): context.caller_loc[caller] = arg['DebugLoc'] -def generate_report(pool, all_remarks, file_remarks, source_dir, output_dir): +def generate_report(pmap, all_remarks, file_remarks, source_dir, output_dir): try: os.makedirs(output_dir) except OSError as e: @@ -358,7 +358,7 @@ def generate_report(pool, all_remarks, file_remarks, source_dir, output_dir): raise _render_file_bound = functools.partial(_render_file, source_dir, output_dir, context) - pool.map(_render_file_bound, file_remarks.items()) + pmap(_render_file_bound, file_remarks.items()) if context.should_display_hotness(): sorted_remarks = sorted(all_remarks.itervalues(), key=lambda r: (r.Hotness, r.__dict__), reverse=True) @@ -391,9 +391,14 @@ if __name__ == '__main__': parser.print_help() sys.exit(1) - pool = Pool(processes=args.jobs) - all_remarks, file_remarks = gather_results(pool, args.yaml_files) + if args.jobs == 1: + pmap = map + else: + pool = Pool(processes=args.jobs) + pmap = pool.map + + all_remarks, file_remarks = gather_results(pmap, args.yaml_files) map_remarks(all_remarks) - generate_report(pool, all_remarks, file_remarks, args.source_dir, args.output_dir) + generate_report(pmap, all_remarks, file_remarks, args.source_dir, args.output_dir)