From: Adam Nemet Date: Mon, 17 Jul 2017 18:00:41 +0000 (+0000) Subject: [opt-viewer] Accept directories that are searched for opt.yaml files X-Git-Tag: android-x86-7.1-r4~13421 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ef31468e6941bdb4ac15079dc5a8244b2b8b3899;p=android-x86%2Fexternal-llvm.git [opt-viewer] Accept directories that are searched for opt.yaml files This allows to pass the build directory where all the opt.yaml files are rather than find | xargs which may invoke opt-viewer multiple times producing incomplete html output. The patch generalizes the same functionality from opt-diff. Differential Revision: https://reviews.llvm.org/D35491 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308200 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/opt-viewer/opt-diff.py b/tools/opt-viewer/opt-diff.py index 9e921f8488d..f39432c8bc9 100755 --- a/tools/opt-viewer/opt-diff.py +++ b/tools/opt-viewer/opt-diff.py @@ -20,24 +20,17 @@ import optrecord 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 @@ if __name__ == '__main__': 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) diff --git a/tools/opt-viewer/opt-stats.py b/tools/opt-viewer/opt-stats.py index a7e598fdfd0..205b08ba8a7 100755 --- a/tools/opt-viewer/opt-stats.py +++ b/tools/opt-viewer/opt-stats.py @@ -15,7 +15,11 @@ from multiprocessing import cpu_count, Pool 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 @@ if __name__ == '__main__': 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') diff --git a/tools/opt-viewer/opt-viewer.py b/tools/opt-viewer/opt-viewer.py index e6dd6a0286f..69bcaedb766 100755 --- a/tools/opt-viewer/opt-viewer.py +++ b/tools/opt-viewer/opt-viewer.py @@ -219,7 +219,11 @@ def generate_report(all_remarks, 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 @@ if __name__ == '__main__': 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) diff --git a/tools/opt-viewer/optrecord.py b/tools/opt-viewer/optrecord.py index 61ed9626cff..6f6537ab055 100644 --- a/tools/opt-viewer/optrecord.py +++ b/tools/opt-viewer/optrecord.py @@ -12,8 +12,10 @@ except ImportError: 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 @@ def gather_results(filenames, num_jobs, should_print_progress): 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