Index: llvm/trunk/tools/opt-viewer/opt-diff.py =================================================================== --- llvm/trunk/tools/opt-viewer/opt-diff.py +++ llvm/trunk/tools/opt-viewer/opt-diff.py @@ -20,24 +20,17 @@ import argparse from collections import defaultdict from multiprocessing import cpu_count, Pool -import os, os.path -import fnmatch - -def find_files(dir_or_file): - if os.path.isfile(dir_or_file): - return [dir_or_file] - - all = [] - for dir, subdirs, files in os.walk(dir_or_file): - for file in files: - if fnmatch.fnmatch(file, "*.opt.yaml"): - all.append( os.path.join(dir, file)) - return all if __name__ == '__main__': parser = argparse.ArgumentParser(description=desc) - parser.add_argument('yaml_dir_or_file_1') - parser.add_argument('yaml_dir_or_file_2') + parser.add_argument( + 'yaml_dir_or_file_1', + help='An optimization record file or a directory searched for optimization ' + 'record files that are used as the old version for the comparison') + parser.add_argument( + 'yaml_dir_or_file_2', + help='An optimization record file or a directory searched for optimization ' + 'record files that are used as the new version for the comparison') parser.add_argument( '--jobs', '-j', @@ -53,8 +46,8 @@ parser.add_argument('--output', '-o', default='diff.opt.yaml') args = parser.parse_args() - files1 = find_files(args.yaml_dir_or_file_1) - files2 = find_files(args.yaml_dir_or_file_2) + files1 = optrecord.find_opt_files([args.yaml_dir_or_file_1]) + files2 = optrecord.find_opt_files([args.yaml_dir_or_file_2]) print_progress = not args.no_progress_indicator all_remarks1, _, _ = optrecord.gather_results(files1, args.jobs, print_progress) Index: llvm/trunk/tools/opt-viewer/opt-stats.py =================================================================== --- llvm/trunk/tools/opt-viewer/opt-stats.py +++ llvm/trunk/tools/opt-viewer/opt-stats.py @@ -15,7 +15,11 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description=desc) - parser.add_argument('yaml_files', nargs='+') + parser.add_argument( + 'yaml_dirs_or_files', + nargs='+', + help='List of optimization record files or directories searched ' + 'for optimization record files.') parser.add_argument( '--jobs', '-j', @@ -31,8 +35,14 @@ args = parser.parse_args() print_progress = not args.no_progress_indicator + + files = optrecord.find_opt_files(args.yaml_dirs_or_files) + if not files: + parser.error("No *.opt.yaml files found") + sys.exit(1) + all_remarks, file_remarks, _ = optrecord.gather_results( - args.yaml_files, args.jobs, print_progress) + files, args.jobs, print_progress) if print_progress: print('\n') Index: llvm/trunk/tools/opt-viewer/opt-viewer.py =================================================================== --- llvm/trunk/tools/opt-viewer/opt-viewer.py +++ llvm/trunk/tools/opt-viewer/opt-viewer.py @@ -219,7 +219,11 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description=desc) - parser.add_argument('yaml_files', nargs='+') + parser.add_argument( + 'yaml_dirs_or_files', + nargs='+', + help='List of optimization record files or directories searched ' + 'for optimization record files.') parser.add_argument( '--output-dir', '-o', @@ -248,8 +252,14 @@ args = parser.parse_args() print_progress = not args.no_progress_indicator + + files = optrecord.find_opt_files(args.yaml_dirs_or_files) + if not files: + parser.error("No *.opt.yaml files found") + sys.exit(1) + all_remarks, file_remarks, should_display_hotness = \ - optrecord.gather_results(args.yaml_files, args.jobs, print_progress) + optrecord.gather_results(files, args.jobs, print_progress) map_remarks(all_remarks) Index: llvm/trunk/tools/opt-viewer/optrecord.py =================================================================== --- llvm/trunk/tools/opt-viewer/optrecord.py +++ llvm/trunk/tools/opt-viewer/optrecord.py @@ -12,8 +12,10 @@ import cgi from collections import defaultdict +import fnmatch import functools from multiprocessing import Lock +import os, os.path import subprocess import optpmap @@ -233,3 +235,19 @@ all_remarks.update(all_remarks_job) return all_remarks, file_remarks, max_hotness != 0 + + +def find_opt_files(dirs_or_files): + all = [] + for dir_or_file in dirs_or_files: + if os.path.isfile(dir_or_file): + all.append(dir_or_file) + else: + for dir, subdirs, files in os.walk(dir_or_file): + # Exclude mounted directories and symlinks (os.walk default). + subdirs[:] = [d for d in subdirs + if not os.path.ismount(os.path.join(dir, d))] + for file in files: + if fnmatch.fnmatch(file, "*.opt.yaml"): + all.append(os.path.join(dir, file)) + return all