llvm.org GIT mirror llvm / ef31468
[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 Adam Nemet 3 years ago
4 changed file(s) with 52 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1919 import argparse
2020 from collections import defaultdict
2121 from multiprocessing import cpu_count, Pool
22 import os, os.path
23 import fnmatch
24
25 def find_files(dir_or_file):
26 if os.path.isfile(dir_or_file):
27 return [dir_or_file]
28
29 all = []
30 for dir, subdirs, files in os.walk(dir_or_file):
31 for file in files:
32 if fnmatch.fnmatch(file, "*.opt.yaml"):
33 all.append( os.path.join(dir, file))
34 return all
3522
3623 if __name__ == '__main__':
3724 parser = argparse.ArgumentParser(description=desc)
38 parser.add_argument('yaml_dir_or_file_1')
39 parser.add_argument('yaml_dir_or_file_2')
25 parser.add_argument(
26 'yaml_dir_or_file_1',
27 help='An optimization record file or a directory searched for optimization '
28 'record files that are used as the old version for the comparison')
29 parser.add_argument(
30 'yaml_dir_or_file_2',
31 help='An optimization record file or a directory searched for optimization '
32 'record files that are used as the new version for the comparison')
4033 parser.add_argument(
4134 '--jobs',
4235 '-j',
5245 parser.add_argument('--output', '-o', default='diff.opt.yaml')
5346 args = parser.parse_args()
5447
55 files1 = find_files(args.yaml_dir_or_file_1)
56 files2 = find_files(args.yaml_dir_or_file_2)
48 files1 = optrecord.find_opt_files([args.yaml_dir_or_file_1])
49 files2 = optrecord.find_opt_files([args.yaml_dir_or_file_2])
5750
5851 print_progress = not args.no_progress_indicator
5952 all_remarks1, _, _ = optrecord.gather_results(files1, args.jobs, print_progress)
1414
1515 if __name__ == '__main__':
1616 parser = argparse.ArgumentParser(description=desc)
17 parser.add_argument('yaml_files', nargs='+')
17 parser.add_argument(
18 'yaml_dirs_or_files',
19 nargs='+',
20 help='List of optimization record files or directories searched '
21 'for optimization record files.')
1822 parser.add_argument(
1923 '--jobs',
2024 '-j',
3034 args = parser.parse_args()
3135
3236 print_progress = not args.no_progress_indicator
37
38 files = optrecord.find_opt_files(args.yaml_dirs_or_files)
39 if not files:
40 parser.error("No *.opt.yaml files found")
41 sys.exit(1)
42
3343 all_remarks, file_remarks, _ = optrecord.gather_results(
34 args.yaml_files, args.jobs, print_progress)
44 files, args.jobs, print_progress)
3545 if print_progress:
3646 print('\n')
3747
218218
219219 if __name__ == '__main__':
220220 parser = argparse.ArgumentParser(description=desc)
221 parser.add_argument('yaml_files', nargs='+')
221 parser.add_argument(
222 'yaml_dirs_or_files',
223 nargs='+',
224 help='List of optimization record files or directories searched '
225 'for optimization record files.')
222226 parser.add_argument(
223227 '--output-dir',
224228 '-o',
247251 args = parser.parse_args()
248252
249253 print_progress = not args.no_progress_indicator
254
255 files = optrecord.find_opt_files(args.yaml_dirs_or_files)
256 if not files:
257 parser.error("No *.opt.yaml files found")
258 sys.exit(1)
259
250260 all_remarks, file_remarks, should_display_hotness = \
251 optrecord.gather_results(args.yaml_files, args.jobs, print_progress)
261 optrecord.gather_results(files, args.jobs, print_progress)
252262
253263 map_remarks(all_remarks)
254264
1111
1212 import cgi
1313 from collections import defaultdict
14 import fnmatch
1415 import functools
1516 from multiprocessing import Lock
17 import os, os.path
1618 import subprocess
1719
1820 import optpmap
232234 all_remarks.update(all_remarks_job)
233235
234236 return all_remarks, file_remarks, max_hotness != 0
237
238
239 def find_opt_files(dirs_or_files):
240 all = []
241 for dir_or_file in dirs_or_files:
242 if os.path.isfile(dir_or_file):
243 all.append(dir_or_file)
244 else:
245 for dir, subdirs, files in os.walk(dir_or_file):
246 # Exclude mounted directories and symlinks (os.walk default).
247 subdirs[:] = [d for d in subdirs
248 if not os.path.ismount(os.path.join(dir, d))]
249 for file in files:
250 if fnmatch.fnmatch(file, "*.opt.yaml"):
251 all.append(os.path.join(dir, file))
252 return all