llvm.org GIT mirror llvm / 135e942
Fix some opt-viewer test issues and disable on Windows. Differential Revision: https://reviews.llvm.org/D41784 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321905 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 1 year, 7 months ago
5 changed file(s) with 35 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
0 import sys
1
2 if 'have_opt_viewer_modules' not in config.available_features:
13 config.unsupported = True
4
5 # Windows has different multiprocessing behavior than non-Windows, which causes
6 # all of the tests to fail presently under Windows. Disable this until those
7 # can be resolved.
8 if sys.platform == 'win32':
9 config.unsupported = True
1818 import optrecord
1919 import argparse
2020 from collections import defaultdict
21 from multiprocessing import cpu_count, Pool
2221
2322 if __name__ == '__main__':
2423 parser = argparse.ArgumentParser(description=desc)
3332 parser.add_argument(
3433 '--jobs',
3534 '-j',
36 default=cpu_count(),
35 default=None,
3736 type=int,
3837 help='Max job count (defaults to %(default)s, the current CPU count)')
3938 parser.add_argument(
2929 parser.add_argument(
3030 '--jobs',
3131 '-j',
32 default=cpu_count(),
32 default=None,
3333 type=int,
3434 help='Max job count (defaults to %(default)s, the current CPU count)')
3535 parser.add_argument(
''', file=self.stream)
4242 return False
4343
4444 class SourceFileRenderer:
45 def __init__(self, source_dir, output_dir, filename):
45 def __init__(self, source_dir, output_dir, filename, no_highlight):
4646 existing_filename = None
4747 if os.path.exists(filename):
4848 existing_filename = filename
5151 if os.path.exists(fn):
5252 existing_filename = fn
5353
54 self.no_highlight = no_highlight
5455 self.stream = codecs.open(os.path.join(output_dir, optrecord.html_file_name(filename)), 'w', encoding='utf-8')
5556 if existing_filename:
5657 self.source_stream = open(existing_filename)
6869 def render_source_lines(self, stream, line_remarks):
6970 file_text = stream.read()
7071
71 if args.no_highlight:
72 if self.no_highlight:
7273 html_highlighted = file_text.decode('utf-8')
7374 else:
7475 html_highlighted = highlight(
156157
157158
158159 class IndexRenderer:
159 def __init__(self, output_dir, should_display_hotness):
160 def __init__(self, output_dir, should_display_hotness, max_hottest_remarks_on_index):
160161 self.stream = codecs.open(os.path.join(output_dir, 'index.html'), 'w', encoding='utf-8')
161162 self.should_display_hotness = should_display_hotness
163 self.max_hottest_remarks_on_index = max_hottest_remarks_on_index
162164
163165 def render_entry(self, r, odd):
164166 escaped_name = cgi.escape(r.DemangledFunctionName)
188190
189191
190192 max_entries = None
191 if should_display_hotness:
192 max_entries = args.max_hottest_remarks_on_index
193 if self.should_display_hotness:
194 max_entries = self.max_hottest_remarks_on_index
193195
194196 for i, remark in enumerate(all_remarks[:max_entries]):
195197 if not suppress(remark):
200202 ''', file=self.stream)
201203
202204
203 def _render_file(source_dir, output_dir, ctx, entry):
205 def _render_file(source_dir, output_dir, ctx, no_highlight, entry):
204206 global context
205207 context = ctx
206208 filename, remarks = entry
207 SourceFileRenderer(source_dir, output_dir, filename).render(remarks)
209 SourceFileRenderer(source_dir, output_dir, filename, no_highlight).render(remarks)
208210
209211
210212 def map_remarks(all_remarks):
226228 file_remarks,
227229 source_dir,
228230 output_dir,
231 no_highlight,
229232 should_display_hotness,
233 max_hottest_remarks_on_index,
230234 num_jobs,
231235 should_print_progress):
232236 try:
237241 else:
238242 raise
239243
240 _render_file_bound = functools.partial(_render_file, source_dir, output_dir, context)
244 _render_file_bound = functools.partial(_render_file, source_dir, output_dir, context, no_highlight)
241245 if should_print_progress:
242246 print('Rendering HTML files...')
243247 optpmap.pmap(_render_file_bound,
249253 sorted_remarks = sorted(optrecord.itervalues(all_remarks), key=lambda r: (r.Hotness, r.File, r.Line, r.Column, r.PassWithDiffPrefix, r.yaml_tag, r.Function), reverse=True)
250254 else:
251255 sorted_remarks = sorted(optrecord.itervalues(all_remarks), key=lambda r: (r.File, r.Line, r.Column, r.PassWithDiffPrefix, r.yaml_tag, r.Function))
252 IndexRenderer(args.output_dir, should_display_hotness).render(sorted_remarks)
256 IndexRenderer(output_dir, should_display_hotness, max_hottest_remarks_on_index).render(sorted_remarks)
253257
254258 shutil.copy(os.path.join(os.path.dirname(os.path.realpath(__file__)),
255259 "style.css"), output_dir)
256260
257261
258 if __name__ == '__main__':
262 def main():
259263 parser = argparse.ArgumentParser(description=desc)
260264 parser.add_argument(
261265 'yaml_dirs_or_files',
272276 parser.add_argument(
273277 '--jobs',
274278 '-j',
275 default=cpu_count(),
279 default=None,
276280 type=int,
277281 help='Max job count (defaults to %(default)s, the current CPU count)')
278282 parser.add_argument(
300304 parser.add_argument(
301305 '--demangler',
302306 help='Set the demangler to be used (defaults to %s)' % optrecord.Remark.default_demangler)
307
308 # Do not make this a global variable. Values needed to be propagated through
309 # to individual classes and functions to be portable with multiprocessing across
310 # Windows and non-Windows.
303311 args = parser.parse_args()
304312
305313 print_progress = not args.no_progress_indicator
320328 file_remarks,
321329 args.source_dir,
322330 args.output_dir,
331 args.no_highlight,
323332 should_display_hotness,
333 args.max_hottest_remarks_on_index,
324334 args.jobs,
325335 print_progress)
336
337 if __name__ == '__main__':
338 main()
4040 _total = multiprocessing.Value('i', len(iterable))
4141
4242 func_and_args = [(func, arg, should_print_progress,) for arg in iterable]
43 if processes <= 1:
43 if processes == 1:
4444 result = map(_wrapped_func, func_and_args, *args, **kwargs)
4545 else:
4646 pool = multiprocessing.Pool(initializer=_init,