summaryrefslogtreecommitdiff
path: root/stats/compare_reports.py
blob: 035df9045c0d4f6a90fa2eb1f5ea1eb85b0b5ba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#!/usr/bin/env python3

"""
Copyright (c) 2015, Intel Corporation

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of Intel Corporation nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

from mako.template import Template
import pprint
import collections
import argparse
import sys
import os

# Import ezbench from the utils/ folder
ezbench_dir = os.path.abspath(sys.path[0]+'/../')
sys.path.append(ezbench_dir+'/utils/')
sys.path.append(ezbench_dir+'/utils/env_dump')
from ezbench import *
from env_dump_parser import *

# constants
html_name="index.html"

# parse the options
parser = argparse.ArgumentParser()
parser.add_argument("--title", help="Set the title for the report")
parser.add_argument("--unit", help="Set the output unit (Default: ms)")
parser.add_argument("--output", help="Report html file path", required=True)
parser.add_argument("--commit_url", help="HTTP URL pattern, {commit} contains the SHA1")
parser.add_argument("--verbose", help="Be more verbose when generating the report", action="store_true")
parser.add_argument("log_folder", nargs='+')
args = parser.parse_args()

# select the right unit
if args.unit is not None:
	output_unit = args.unit
else:
	output_unit = "ms"

# Parse the results and then create one report with the following structure:
# commit -> report_name -> benchmark -> bench results
db = dict()
db["commits"] = collections.OrderedDict()
db["reports"] = list()
db["benchmarks"] = list()
db['env_sets'] = dict()
db["envs"] = dict()
db["targets"] = dict()
human_envs = dict()
git_history = None
for log_folder in args.log_folder:
	print("{f}: ".format(f=log_folder), end="")
	report_name = [x for x in log_folder.split('/') if x][-1]
	try:
		sbench = SmartEzbench(ezbench_dir, report_name, readonly=True)
		if git_history is None:
			git_history = sbench.git_history()
		report = sbench.report(git_history=git_history)
	except RuntimeError:
		report = genPerformanceReport(log_folder)

	db["reports"].append(report_name)

	# drop the no-op benchmark
	report.benchmarks = list(filter(lambda b: b.full_name != "no-op", report.benchmarks))

	# make sure all the benchmarks are listed in db["envs"]
	for benchmark in report.benchmarks:
		db["envs"][benchmark.full_name] = dict()

	for event in report.events:
		if type(event) is EventBuildBroken:
			event.commit_range.new.annotation = event.commit_range.new.sha1 + ": build broken"
			event.commit_range.new.annotation_long = str(event)
		elif type(event) is EventBuildFixed:
			event.fixed_commit_range.new.annotation = event.fixed_commit_range.new.sha1 + ": build fixed"
			event.fixed_commit_range.new.annotation_long = str(event)
		elif type(event) is EventPerfChange:
			for result in event.commit_range.new.results:
				if result.benchmark.full_name != event.benchmark.full_name:
					continue
				result.annotation = str(event)

	# add all the commits
	for commit in report.commits:
		# drop the no-op results
		commit.results = list(filter(lambda r: r.benchmark.full_name != "no-op", commit.results))
		if len(commit.results) == 0 and not hasattr(commit, 'annotation'):
			continue

		if not commit.sha1 in db["commits"]:
			db["commits"][commit.sha1] = dict()
			db["commits"][commit.sha1]['reports'] = dict()
			db["commits"][commit.sha1]['commit'] = commit
			if commit.compil_exit_code <= 0:
				db["commits"][commit.sha1]['build_color'] = "#00FF00"
			else:
				db["commits"][commit.sha1]['build_color'] = "#FF0000"
			db["commits"][commit.sha1]['build_error'] = str(EzbenchExitCode(commit.compil_exit_code)).split('.')[1]
		db["commits"][commit.sha1]['reports'][report_name] = dict()

		# Add the results and perform some stats
		score_sum = 0
		count = 0
		for result in commit.results:
			if not result.benchmark.full_name in db["benchmarks"]:
				db["benchmarks"].append(result.benchmark.full_name)
			db["commits"][commit.sha1]['reports'][report_name][result.benchmark.full_name] = result
			orig_avr_runs = sum(result.data) / float(len(result.data))
			average = convert_unit(orig_avr_runs, result.unit_str, output_unit)
			score_sum += average
			count += 1
			result.average = float("{0:.2f}".format(average))

			# Compare to the target
			if not result.benchmark.full_name in db["targets"]:
				db["targets"][result.benchmark.full_name] = average

			# Environment
			if result.benchmark.full_name not in human_envs:
				for envfile in result.env_files:
					if envfile is not None:
						human_envs[result.benchmark.full_name] = EnvDumpReport(log_folder + "/" + envfile, True)
			if result.benchmark.full_name not in db['env_sets']:
				db['env_sets'][result.benchmark.full_name] = list()
			for e in range(0, len(result.env_files)):
				# Create the per-run information
				envfile = result.env_files[e]
				if envfile is None:
					continue

				r = EnvDumpReport(log_folder + "/" + envfile, False).to_set(['^DATE',
				                                                             '^ENV.ENV_DUMP_FILE',
				                                                             '^ENV.EZBENCH_PERFMETER_PID',
				                                                             '^ENV.EZBENCH_X_PID',
				                                                             'SHA1$',
				                                                             'extension count$',
				                                                             'window id$'])
				tup = dict()
				tup['log_folder'] = report_name
				tup['commit'] = commit
				tup['run'] = e

				# Compare the set to existing ones
				found = False
				for report in db['env_sets'][result.benchmark.full_name]:
					if r  == report['set']:
						report['users'].append(tup)
						found = True

				# Add the report
				if not found:
					new_entry = dict()
					new_entry['set'] = r
					new_entry['users'] = list()
					new_entry['users'].append(tup)
					db['env_sets'][result.benchmark.full_name].append(new_entry)

		if count > 0:
			avg = score_sum / count
		else:
			avg = 0
		db["commits"][commit.sha1]['reports'][report_name]["average"] = float("{0:.2f}".format(avg))
		db["commits"][commit.sha1]['reports'][report_name]["average_unit"] = output_unit

# Generate the environment
for bench in human_envs:
	env = human_envs[bench]
	if env is not None:
		for key in sorted(list(env.values)):
			cur = db['envs'][bench]
			fields = key.split(":")
			for f in range(0, len(fields)):
				field = fields[f].strip()
				if f < len(fields) - 1:
					if field not in cur:
						cur[field] = dict()
					cur = cur[field]
				else:
					cur[field] = env.values[key]

# Generate the environment diffs
db['env_diff_keys'] = dict()
for bench in db['env_sets']:
	final_union = set()
	for report in db['env_sets'][bench]:
		diff = db['env_sets'][bench][0]['set'] ^ report['set']
		final_union = final_union | diff
	db['env_diff_keys'][bench] = sorted(dict(final_union).keys())

# Sort the benchmarks by name to avoid ever-changing layouts
db["benchmarks"] = sort(db["benchmarks"])

# Support creating new URLs
if args.commit_url is not None:
    db["commit_url"] = args.commit_url

if args.verbose:
    pprint.pprint(db)

# Generate the report
html_template="""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%! import cgi %>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>${title}</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <style>
            body {{ font-size: 10pt; }}
            table { font-size: 10pt; }

            /* http://martinivanov.net/2011/09/26/css3-treevew-no-javascript/ */
            .css-treeview input + label + ul
            {
                display: none;
            }
            .css-treeview input:checked + label + ul
            {
                display: block;
            }
            .css-treeview input
            {
                position: absolute;
                opacity: 0;
            }
            .css-treeview label,
            .css-treeview label::before
            {
                cursor: pointer;
            }
            .css-treeview input:disabled + label
            {
                cursor: default;
                opacity: .6;
            }
            table{
                border-collapse:collapse;
            }
            table td{
                padding:5px; border:#4e95f4 1px solid;
            }
            table tr:nth-child(odd){
                background: #b8d1f3;
            }
            table tr:nth-child(even){
                background: #dae5f4;
            }

            .env_node:hover {
                cursor: pointer;
                text-decoration: underline;
            }

            .close_button {
                color: black;
                background-color: grey;
                cursor:pointer;
            }
            .close_button:hover {
                text-decoration:underline;
            }
        </style>
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load('visualization', '1', {packages: ['corechart']});
            google.setOnLoadCallback(drawTrend);
            google.setOnLoadCallback(drawDetails);

            var currentCommit = "${default_commit}";

            function showColumn(dataTable, chart, activColumns, series, col, show) {
                seriesCol = 0
                for (i = 0; i < col; i++)
                    if (dataTable.getColumnType(i) == 'number')
                        seriesCol++
                if (!show) {
                    activColumns[col] = {
                        label: dataTable.getColumnLabel(col),
                        type: dataTable.getColumnType(col),
                        calc: function () {
                            return null;
                        }
                    };
                    series[seriesCol].color = '#CCCCCC';
                }
                else {
                    activColumns[col] = col;
                    series[seriesCol].color = null;
                }
            }

            function showAllColumns(dataTable, chart, activColumns, series, show) {
                for (var i = 1; i < dataTable.getNumberOfColumns(); i++) {
                    if (dataTable.getColumnType(i) == 'number')
                        showColumn(dataTable, chart, activColumns, series, i, show)
                }
            }

            function handle_selection(sel, dataTable, series, activColumns, chart) {
                var col = sel[0].column;

                var allActive = true;
                for (var i = 1; i < dataTable.getNumberOfColumns(); i++) {
                    if (dataTable.getColumnType(i) == 'number' && activColumns[i] != i) {
                        allActive = false;
                    }
                }
                if (activColumns[col] == col) {
                    // The clicked columns is active
                    if (allActive) {
                        showAllColumns(dataTable, chart, activColumns, series, false);
                        showColumn(dataTable, chart, activColumns, series, col, true);
                    } else {
                        showColumn(dataTable, chart, activColumns, series, col, false);
                    }
                }
                else {
                    // The clicked columns is inactive, show it
                    showColumn(dataTable, chart, activColumns, series, col, true);
                }

                var activeColsCount = 0;
                for (var i = 1; i < dataTable.getNumberOfColumns(); i++) {
                    if (dataTable.getColumnType(i) == 'number' && activColumns[i] == i) {
                        activeColsCount++;
                    }
                }
                if (activeColsCount == 0)
                    showAllColumns(dataTable, chart, activColumns, series, true);

                return activeColsCount
            }

            function adjustChartSize(id_chart, reportsCount, benchmarkCount) {
                var size = 75 + reportsCount * (25 + (benchmarkCount * 8));
                id_chart.style.height = size + "px";
                id_chart.style.width = "100%";
            }

            function trendUnselect() {
                trend_chart.setSelection(null);
            }

            function drawTrend() {
                var dataTable = new google.visualization.DataTable();

<%def name="tooltip_commit_table(commit)">\\
<h3>${db["commits"][commit]['commit'].full_name.replace('"', '&quot;')} <span class='close_button' onclick='javascript:trendUnselect();' title='Close this tooltip'>[X]</span></h3>\\
<h4>Commit\\
% if 'commit_url' in db:
 (<a href='${db["commit_url"].format(commit=commit)}' target='_blank'>URL</a>)\\
% endif
</h4><table>\\
<tr><td><b>Author:</b></td><td>${cgi.escape(db["commits"][commit]['commit'].author)}</td></tr>\\
<tr><td><b>Commit date:</b></td><td>${db["commits"][commit]['commit'].commit_date}</td></tr>\\
<tr><td><b>Build exit code:</b></td><td bgcolor='${db["commits"][commit]['build_color']}'><center>${db["commits"][commit]['build_error']}</center></td></tr>\\
% if len(db["commits"][commit]['commit'].bugs) > 0:
<tr><td><b>Referenced bugs</b></td><td><ul>\\
% for bug in db["commits"][commit]['commit'].bugs:
<li><a href='${bug.replace('"', '&quot;')}' target='_blank'>${bug.replace('"', '&quot;')}</a></li>\\
% endfor
</ul></td></tr>\\
% endif
% if hasattr(db["commits"][commit]['commit'], "annotation_long"):
<tr><td><b>Annotation:</b></td><td>${cgi.escape(db["commits"][commit]['commit'].annotation_long)}</td></tr>\\
% endif
</table>\\
</%def>

% if len(db['reports']) > 1:
                dataTable.addColumn('string', 'Commit');
                dataTable.addColumn({type: 'string', role: 'tooltip', p: { html: true }});
                % for report in db["reports"]:
                dataTable.addColumn('number', '${report}');
                % endfor
                dataTable.addRows([
                % for commit in db["commits"]:
                    ['${commit}', "${tooltip_commit_table(commit)}<h4>Perf</h4><table>\\
% for report in db["reports"]:
% if report in db["commits"][commit]['reports']:
<tr><td><b>${report}:</b></td><td>${db["commits"][commit]['reports'][report]["average"]} ${output_unit}</td></tr>\\
% endif
% endfor
</table><p></p>"\\
                        % for report in db["reports"]:
                            % if report in db["commits"][commit]['reports']:
, ${db["commits"][commit]['reports'][report]["average"]}\\
                            % else:
, null\\
                            % endif
                        % endfor
],
                % endfor
                ]);
% else:
                <%
                    report = db["reports"][0]
                %>
                dataTable.addColumn('string', 'Commits');
                dataTable.addColumn({type: 'string', role:'annotation'});
                % for benchmark in db["benchmarks"]:
                dataTable.addColumn('number', '${benchmark}');
                dataTable.addColumn({type: 'string', role: 'tooltip', p: { html: true }});
                % endfor

                dataTable.addRows([
                % for commit in db["commits"]:
["${commit}"\\
                    % if hasattr(db["commits"][commit]['commit'], 'annotation'):
, "${db["commits"][commit]['commit'].annotation}"\\
                    %else:
, null\\
                    % endif
                    % for benchmark in db["benchmarks"]:
                        % if benchmark in db["commits"][commit]['reports'][report]:
                        <%
                            diff_target = db["commits"][commit]['reports'][report][benchmark].average * 100 / db['targets'][benchmark]
                            diff_target = "{0:.2f}".format(diff_target)
                        %>
, ${diff_target}, "${tooltip_commit_table(commit)}<h4>Perf</h4><table><tr><td><b>Target</b></td><td>${diff_target} %</td></tr><tr><td><b>Raw value</b></td><td>${db["commits"][commit]['reports'][report][benchmark].average} ${output_unit}</td></tr></table>"\\
                            % else:
, null, "${benchmark}"\\
                            % endif
                    % endfor
],
                % endfor
                ]);
% endif

                var activColumns = [];
                var series = {};
                for (var i = 0; i < dataTable.getNumberOfColumns(); i++) {
                    activColumns.push(i);
                    if (i > 0) {
                        series[i - 1] = {};
                    }
                }

                var options = {
                chart: {
                        title: 'Performance trend across multiple commits'
                    },
                % if len(db['reports']) > 1:
                    focusTarget: 'category',
                    vAxis: {title: 'Average result (${output_unit})'},
                % else:
                    annotations: {style: 'line', textStyle: {fontSize: 12}},
                    vAxis: {title: '% of target (%)'},
                % endif
                    legend: { position: 'top', textStyle: {fontSize: 12}, maxLines: 3},
                    tooltip: {trigger: 'selection', isHtml: true},
                    crosshair: { trigger: 'both' },
                    hAxis: {title: 'Commits', slantedText: true, slantedTextAngle: 45},
                    series: series,
                    chartArea: {left:"6%", width:"95%"}
                };

                trend_chart = new google.visualization.LineChart(document.getElementById('trends_chart'));
                trend_chart.draw(dataTable, options);

                google.visualization.events.addListener(trend_chart, 'select', function () {
                    var sel = trend_chart.getSelection();
                    // See https://developers.google.com/chart/interactive/docs/reference#visgetselection
                    if (sel.length > 0 && typeof sel[0].row === 'object') {
                        handle_selection(sel, dataTable, series, activColumns, trend_chart)

                        // Redraw the chart with the masked columns
                        var view = new google.visualization.DataView(dataTable);
                        view.setColumns(activColumns);
                        trend_chart.draw(view, options);
                    }

                    if (sel.length > 0 && typeof sel[0].row === 'number') {
                        // update the other graph if there were changes
                        var commit = dataTable.getValue(sel[0].row, 0)
                        if (commit != currentCommit) {
                            currentCommit = commit;
                            drawDetails();
                        }
                    }

                    if (sel.length == 0) {
                        trend_chart.setSelection(null);
                    }
                });
            }

           function drawDetails() {
                var dataTable = new google.visualization.DataTable();
                dataTable.addColumn('string', 'Report');
                dataTable.addColumn('number', 'Average');
                dataTable.addColumn({type: 'string', role: 'tooltip', p: { html: true }});
                % for benchmark in db["benchmarks"]:
                dataTable.addColumn('number', '${benchmark}');
                dataTable.addColumn({type: 'string', role: 'tooltip', p: { html: true }});
                % endfor

                % for commit in db["commits"]:
                if (currentCommit == "${commit}") {
                    dataTable.addRows([
                    % for report in db["reports"]:
                        % if report in db["commits"][commit]['reports']:
                             ["${report}", ${db["commits"][commit]['reports'][report]["average"]}, "<h3>${report} - ${benchmark}</h3><p>\\
                             % for r in db["reports"]:
<%
                                     if not r in db["commits"][commit]:
                                         continue
                                     if db["commits"][commit]['reports'][report]["average"] != 0:
                                         diff = db["commits"][commit]['reports'][r]["average"] / db["commits"][commit]['reports'][report]["average"] * 100
                                         diff = float("{0:.2f}".format(diff))
                                     else:
                                        diff = "ERR"
                                     btag = btagend = ""
                                     if r == report:
                                         btag="<b>"
                                         btagend="</b>"
                                 %>\\
${btag}${r}: ${db["commits"][commit]['reports'][r]["average"]} ${output_unit} (${diff}%)${btagend}<br/>\\
                            % endfor
</p>"\\
                            % for benchmark in db["benchmarks"]:
                                % if benchmark in db["commits"][commit]['reports'][report]:
, ${db["commits"][commit]['reports'][report][benchmark].average}, "<h3>${report} - ${benchmark}</h3><p>\\
                                    % for r in db["reports"]:
<%
                                            if not r in db["commits"][commit]['reports'] or benchmark not in db["commits"][commit]['reports'][r]:
                                                continue
                                            if db["commits"][commit]['reports'][report][benchmark].average != 0:
                                                diff = db["commits"][commit]['reports'][r][benchmark].average / db["commits"][commit]['reports'][report][benchmark].average * 100
                                                diff = float("{0:.2f}".format(diff))
                                            else:
                                                diff = "ERR"
                                            btag = btagend = ""
                                            if r == report:
                                                btag="<b>"
                                                btagend="</b>"
                                        %>\\
${btag}${r}: ${db["commits"][commit]['reports'][r][benchmark].average} ${output_unit} (${diff}%)${btagend}<br/>\\
                                    % endfor
</p>"\\
                           % else:
, null, "${benchmark}"\\
                           % endif
                        % endfor
],
                        % endif
                    % endfor
                    ]);
                }
                % endfor

                // adjust the size of the chart to fit the data
                adjustChartSize(details_chart, dataTable.getNumberOfRows(), Math.floor(dataTable.getNumberOfColumns() / 2));

                var activColumns = [];
                var series = {};
                for (var i = 0; i < dataTable.getNumberOfColumns(); i++) {
                    activColumns.push(i);
                    if (i > 0) {
                        series[i - 1] = {};
                    }
                }
                series[0] = {type: 'line'};


                var options = {
                    title : 'Performance of commit ' + currentCommit,
                    legend: {textStyle: {fontSize: 12}},
                    tooltip: {trigger: 'focus', isHtml: true},
                    vAxis: {title: 'Reports', textStyle: {fontSize: 12}},
                    hAxis: {title: 'Average result (${output_unit})', textStyle: {fontSize: 12}},
                    seriesType: 'bars',
                    orientation: 'vertical',
                    series: series
                };

                var chart = new google.visualization.ComboChart(document.getElementById('details_chart'));
                chart.draw(dataTable, options);

                google.visualization.events.addListener(chart, 'select', function () {
                    var sel = chart.getSelection();
                    // See https://developers.google.com/chart/interactive/docs/reference#visgetselection
                    if (sel.length > 0 && typeof sel[0].row === 'object') {
                        activeCols = handle_selection(sel, dataTable, series, activColumns, chart)

                        // reduce the size of the chart to fit the data
                        adjustChartSize(details_chart, dataTable.getNumberOfRows(), activeCols);

                        // Redraw the chart with the masked columns
                        var view = new google.visualization.DataView(dataTable);
                        view.setColumns(activColumns);
                        chart.draw(view, options);
                    }

                    if (sel.length == 0) {
                        chart.setSelection(null);
                    }
                });
            }
        </script>
    </head>

    <body>
        <h1>${title}</h1>

        <h2>Trends</h2>

        <center><div id="trends_chart" style="width: 100%; height: 500px;"></div></center>

        <h2>Details</h2>

        <center><div id="details_chart" style="width: 100%; height: 500px;"></div></center>

        <h2>Benchmarks</h2>

            % for benchmark in db["benchmarks"]:
                <h3>${benchmark.capitalize()}</h3>

                <div class="css-treeview">
                    <%def name="outputtreenode(node, id, label, attr = '')">
                        <li><input type="checkbox" id="${id}" ${attr}/><label class="env_node" for="${id}">+${label}</label><ul>
                            <table>
                            % for child in sorted(node):
                                % if type(node[child]) is str:
                                    <tr><td>${child}</td><td>${node[child]}</td></tr>
                                % endif
                            % endfor
                            </table>
                            % for child in sorted(node):
                                % if type(node[child]) is not str:
                                    ${outputtreenode(node[child], "{}.{}".format(id, child.replace(' ', '_')), child, '')}
                                % endif
                            % endfor
                        </ul></li>
                    </%def>

                    <ul>
                        ${outputtreenode(db["envs"][benchmark], benchmark + "_envroot", "Environment", 'checked="checked"')}
                    </ul>
                </div>

                <table>
                    <tr>
                        <th>Key</th>
                        % for env_set in db["env_sets"][benchmark]:
                        <%
                            users = ""
                            for user in env_set['users']:
                                if len(users) > 0:
                                    users += "<br/>"
                                users += "{}.{}#{}".format(user['log_folder'], user['commit'].sha1, user['run'])
                        %>\\
                        <th>${users}</th>
                        % endfor
                    </tr>
                    % for key in db["env_diff_keys"][benchmark]:
                    <tr>
                        <td>${key}</td>
                        % for env_set in db["env_sets"][benchmark]:
                        % if key in dict(env_set['set']):
                            <td>${dict(env_set['set'])[key]}</td>
                        % else:
                            <td>MISSING</td>
                        % endif
                        % endfor
                    </tr>
                    % endfor
                </table>
            % endfor
    </body>

</html>
"""


# Create the html file
print("Generating the HTML")

if args.title is not None:
    title = args.title
else:
    title = "Performance report on the run named '{run_name}'".format(run_name=report_name)

html = Template(html_template).render(title=title, db=db, output_unit=output_unit,
				      default_commit=list(db["commits"])[-1])

with open(args.output, 'w') as f:
    f.write(html)
    print("Output HTML generated at: {0}".format(args.output))