From 0a35ac89932c2536e91601c67f76709f6443243d Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 10 Oct 2015 13:01:35 +0300 Subject: Generate per-benchmark page with jinja2 --- obbench | 90 ++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 40 deletions(-) (limited to 'obbench') diff --git a/obbench b/obbench index d2ec72f..c80b294 100755 --- a/obbench +++ b/obbench @@ -79,6 +79,41 @@ summary_j2 = '''\ ''' +benchmark_j2 = '''\ +{% autoescape true %} + + + Obnam benchmark: {{ obj.commit_id }} {{ obj.name }} + + + + +

Obnam benchmark: {{ obj.commit_id }} {{ obj.name }}

+ + + + {% for step in obj.steps %} + {% if 'obnam' in step %} + + {% endif %} + {% endfor %} + + + + {% for step in obj.steps %} + {% if 'obnam' in step %} + + {% endif %} + {% endfor %} + +
{{ step.obnam }} seconds
(% of goal)
+ {{ step.duration_fmt }} ({{step.reference_fmt }})
+ + +{% endautoescape %} +''' + + class ObnamBenchmarker(cliapp.Application): def process_args(self, args): @@ -263,33 +298,6 @@ class ObnamBenchmarker(cliapp.Application): spec['html_dir'], '{}_{}.html'.format(obj['commit_id'], obj['name'])) with open(filename, 'w') as f: - f.write('\n') - - f.write('\n') - f.write( - 'Obnam benchmark: {commit} {name}\n'.format( - commit=self.q(obj['commit_id']), - name=self.q(obj['name']))) - f.write('\n') - f.write('\n') - - f.write('\n') - f.write( - '

Obnam benchmark: {commit} {name}

\n'.format( - commit=self.q(obj['commit_id']), - name=self.q(obj['name']))) - f.write('\n') - - f.write('\n') - for step in obj['steps']: - if 'obnam' in step: - f.write( - '\n'.format( - action=self.q(step['obnam']))) - f.write('\n') - - f.write('\n') for index, step in enumerate(obj['steps']): if 'obnam' not in step: continue @@ -299,8 +307,9 @@ class ObnamBenchmarker(cliapp.Application): name=obj['name'], index=index) - profile_filename = os.path.join(spec['html_dir'], basename) - with open(profile_filename, 'w') as profile: + step['profile_filename'] = os.path.join( + spec['html_dir'], basename) + with open(step['profile_filename'], 'w') as profile: profile.write(step['profile']) reference = 'unknown' @@ -309,18 +318,19 @@ class ObnamBenchmarker(cliapp.Application): if 'reference' in spec_step: reference = '%.1f %%' % ( 100.0 * step['duration'] / spec_step['reference']) + step['reference_fmt'] = reference + + step['duration_fmt'] = '%.1f' % step['duration'] - f.write( - '\n'.format( - link=self.q(basename), - duration=self.q('%.1f' % step['duration']), - ref=reference)) - f.write('\n') - - f.write('
{action} seconds
(% of goal)
{duration} ' - '({ref})
\n') - f.write('\n') - f.write('\n') + vars = { + 'obj': obj, + } + + env = jinja2.Environment( + autoescape=lambda foo: True, + extensions=['jinja2.ext.autoescape']) + template = env.from_string(benchmark_j2) + f.write(template.render(**vars)) def q(self, text): '''Quote for HTML''' -- cgit v1.2.1