Skip to content

Commit

Permalink
Reformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
Moustafa Kahla committed Jun 12, 2021
1 parent 4c2a489 commit bce6d06
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
24 changes: 12 additions & 12 deletions harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def invoke_optdiff(yaml_file_1, yaml_file_2, filter_only, out_yaml):
out_yaml) # output yaml


def run(config, program, reps, dry,with_perf):
def run(config, program, reps, dry, with_perf):
print('Launching program', program, 'with modes', config[program]['build'])
perf_command='perf record --freq=100000 -o perf.data' if with_perf else ''
exe = config[program]['env']+' '+perf_command+ ' '+ config[program]['run'] + ' ' + config[program]['input']
perf_command = 'perf record --freq=100000 -o perf.data' if with_perf else ''
exe = config[program]['env'] + ' ' + perf_command + ' ' + config[program]['run'] + ' ' + config[program]['input']
os.makedirs('./results', exist_ok=True)
results = {program: {}}
try:
Expand Down Expand Up @@ -280,7 +280,7 @@ def generate_diff_yaml():
'Done generating YAML diff optimization report for builds %s|%s mode %s' % (builds[0], builds[1], mode))
except:
print('Failed generating YAML diff optimization report for builds %s|%s mode %s' % (
builds[0], builds[1], mode))
builds[0], builds[1], mode))

def generate_diff_html():
print('Creating HTML report output diff for %s|%s...' % (builds[0], builds[1]))
Expand All @@ -298,7 +298,7 @@ def generate_diff_html():
if os.path.exists(out_yaml):
ans = input(
'Optimization remark YAML files for builds %s|%s already found from previous build, regenerate (y/n)?\n' % (
builds[0], builds[1]))
builds[0], builds[1]))
if ans.lower() == 'y':
generate_diff_yaml()
else:
Expand All @@ -318,7 +318,7 @@ def generate_remark_reports(config, program, with_perf):

def generate_html():
print('Creating HTML report output for build %s ...' % (build))
build_for_hotness= [build] if with_perf else []
build_for_hotness = [build] if with_perf else []
try:
invoke_optviewer(
[in_yaml],
Expand All @@ -345,10 +345,10 @@ def generate_html():
# Create repors for 2-combinations of build options.
combos = itertools.combinations(config[program]['build'], 2)
for builds in combos:
generate_diff_reports(report_dir, builds, 'all',with_perf)
generate_diff_reports(report_dir, builds, 'analysis',with_perf)
generate_diff_reports(report_dir, builds, 'missed',with_perf)
generate_diff_reports(report_dir, builds, 'passed',with_perf)
generate_diff_reports(report_dir, builds, 'all', with_perf)
generate_diff_reports(report_dir, builds, 'analysis', with_perf)
generate_diff_reports(report_dir, builds, 'missed', with_perf)
generate_diff_reports(report_dir, builds, 'passed', with_perf)


def fetch(config, program):
Expand Down Expand Up @@ -419,9 +419,9 @@ def main():
if args.build:
build(config, p)
if args.run:
run(config, p, args.run, args.dry,args.perf)
run(config, p, args.run, args.dry, args.perf)
if args.generate:
generate_remark_reports(config, p,args.perf)
generate_remark_reports(config, p, args.perf)
if args.stats:
show_stats(config, p)

Expand Down
47 changes: 24 additions & 23 deletions opt-viewer/optviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,28 @@ def suppress(remark):
return remark.getArgDict()['Callee'][0].startswith(('\"Swift.', '\"specialized Swift.'))
return False

def get_hotness_lines(output_dir,builds):

def get_hotness_lines(output_dir, builds):
perf_hotness = {}
#print('available builds renderer', builds)
# print('available builds renderer', builds)
for build in builds:
perf_hotness_path = os.path.join(output_dir, '..', "{}.lines_hotness.yaml".format(build))
#print('perf hotness path',perf_hotness_path)
# print('perf hotness path',perf_hotness_path)
f = open(perf_hotness_path)
#print(f)
# print(f)
try:
hotness_dict = yaml.load(f,Loader=CLoader)
hotness_dict = yaml.load(f, Loader=CLoader)
except Exception as e:
print(e)
#print('file loaded:\n\n\n',hotness_dict)
# print('file loaded:\n\n\n',hotness_dict)
perf_hotness[build] = hotness_dict
#print('build hotnes:\n\n\n',perf_hotness[build])
# print('build hotnes:\n\n\n',perf_hotness[build])
f.close()
return perf_hotness


class SourceFileRenderer:
def __init__(self, source_dir, output_dir, filename, no_highlight,builds=[]):
def __init__(self, source_dir, output_dir, filename, no_highlight, builds=[]):
self.filename = filename
existing_filename = None
# print('filename', filename) #ggout
Expand Down Expand Up @@ -99,8 +101,8 @@ def __init__(self, source_dir, output_dir, filename, no_highlight,builds=[]):
self.cpp_lexer = CppLexer(stripnl=False)
self.builds = builds
# We assume that we comparison is between each pair of builds
self.perf_hotness = get_hotness_lines(output_dir,builds)
#input("builds at srcfile: {}".format(builds))
self.perf_hotness = get_hotness_lines(output_dir, builds)
# input("builds at srcfile: {}".format(builds))

def render_source_lines(self, stream, line_remarks):
file_text = stream.read()
Expand Down Expand Up @@ -129,13 +131,13 @@ def render_source_lines(self, stream, line_remarks):
html_highlighted = html_highlighted.replace('</pre></div>', '')

for (linenum, html_line) in enumerate(html_highlighted.split('\n'), start=1):
html_src_line=u'''
html_src_line = u'''
<tr>
<td><a name=\"L{linenum}\">{linenum}</a></td>
<td></td>'''.format(**locals())
# add place holder for every hotness
for _ in range(len(self.builds)):
html_src_line+=u'''
html_src_line += u'''
<td></td>'''
html_src_line += u'''
<td><div class="highlight"><pre>{html_line}</pre></div></td>
Expand Down Expand Up @@ -166,7 +168,7 @@ def render_inline_remarks(self, r, line):
indent = line[:max(r.Column, 1) - 1]
indent = re.sub('\S', ' ', indent)

entery=u'''
entery = u'''
<tr>
<td></td>'''
for build in self.perf_hotness:
Expand All @@ -177,7 +179,7 @@ def render_inline_remarks(self, r, line):
entery_hotness = "{:.3f}%".format(entery_hotness)
entery += u'''
<td>{entery_hotness}</td>'''.format(**locals())
entery+=u'''
entery += u'''
<td class=\"column-entry-{r.color}\">{r.PassWithDiffPrefix}</td>
<td><pre style="display:inline">{indent}</pre><span class=\"column-entry-yellow\"> {r.message}&nbsp;</span></td>
<td class=\"column-entry-yellow\">{inlining_context}</td>
Expand All @@ -187,7 +189,7 @@ def render_inline_remarks(self, r, line):
def render(self, line_remarks):
if not self.source_stream:
return
header1=u'''
header1 = u'''
<html>
<title>{}</title>
<meta charset="utf-8" />
Expand All @@ -203,7 +205,7 @@ def render(self, line_remarks):
for build in self.perf_hotness:
header1 += u'''
<th>{} Perf Hotness</td>'''.format(build)
header1+=u'''
header1 += u'''
<th>Optimization</td>
<th>Source</td>
<th>Inline Context</td>
Expand All @@ -230,8 +232,7 @@ def __init__(self, output_dir, should_display_hotness, max_hottest_remarks_on_in
# self.perf_hotness_seq = perf_hotness_seq
self.builds = builds
# We assume that we comparison is between each pair of builds
self.perf_hotness = get_hotness_lines(output_dir,builds)

self.perf_hotness = get_hotness_lines(output_dir, builds)

def render_entry(self, r, odd):
escaped_name = html.escape(r.DemangledFunctionName)
Expand All @@ -253,7 +254,7 @@ def render_entry(self, r, odd):
file_and_line = file_name + ':' + line_num
entery_hotness = 0 if file_and_line not in self.perf_hotness[build] else self.perf_hotness[build][
file_and_line]
entery_hotness ="{:.3f}%".format(entery_hotness)
entery_hotness = "{:.3f}%".format(entery_hotness)
entery += u'''
<td class=\"column-entry-{odd}\">{entery_hotness}</td>'''.format(**locals())

Expand Down Expand Up @@ -301,12 +302,12 @@ def render(self, all_remarks):
</html>''', file=self.stream)


def _render_file(source_dir, output_dir, ctx, no_highlight,builds, entry):
#input('builds inside srcfile render {}'.format(builds))
def _render_file(source_dir, output_dir, ctx, no_highlight, builds, entry):
# input('builds inside srcfile render {}'.format(builds))
global context
context = ctx
filename, remarks = entry
SourceFileRenderer(source_dir, output_dir, filename, no_highlight,builds).render(remarks)
SourceFileRenderer(source_dir, output_dir, filename, no_highlight, builds).render(remarks)


def map_remarks(all_remarks):
Expand Down Expand Up @@ -346,7 +347,7 @@ def generate_report(all_remarks,
print('Rendering index page...')
if should_display_hotness:
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)
r.Hotness, r.File, r.Line, r.Column, r.PassWithDiffPrefix, r.yaml_tag, r.Function), reverse=True)
else:
sorted_remarks = sorted(optrecord.itervalues(all_remarks),
key=lambda r: (r.File, r.Line, r.Column, r.PassWithDiffPrefix, r.yaml_tag, r.Function))
Expand Down

0 comments on commit bce6d06

Please sign in to comment.