#!/usr/bin/python3 import collections import csv import os import sys doc_template = """ {header}

{header}

{test_part} """ table_template = """

{caption}

{header} {rows}
""" def tr(x): return '' + str(x) + '' def td(x): return '' + str(x) + '' def th(x): return '' + str(x) + '' def table_row(r): return tr(''.join([td(f) for f in r])) def table_header(r): return tr(''.join([th(f) for f in r])) def tsv_rows(n): result = '' with open(n, encoding='utf-8') as fd: for row in csv.reader(fd, delimiter="\t", quotechar='"'): result += table_row(row) return result params = collections.defaultdict(str) params['header'] = "ClickHouse Performance Comparison" params['test_part'] = ( table_template.format( caption = 'Tested commits', header = table_header(['Old', 'New']), rows = table_row([open('left-commit.txt').read(), open('right-commit.txt').read()]) ) + table_template.format( caption = 'Changes in performance', header = table_header(['Old, s', 'New, s', 'Relative difference (new - old)/old', 'Randomization distribution quantiles [5%, 50%, 95%]', 'Query']), rows = tsv_rows('changed-perf.tsv')) + table_template.format( caption = 'Slow on client', header = table_header(['Client time, s', 'Server time, s', 'Ratio', 'Query']), rows = tsv_rows('slow-on-client.tsv')) + table_template.format( caption = 'Unstable queries', header = table_header(['Old, s', 'New, s', 'Relative difference (new - old)/old', 'Randomization distribution quantiles [5%, 50%, 95%]', 'Query']), rows = tsv_rows('unstable-queries.tsv')) + table_template.format( caption = 'Run errors', header = table_header(['A', 'B']), rows = tsv_rows('run-errors.log')) + table_template.format( caption = 'Tests with most unstable queries', header = table_header(['Test', 'Unstable', 'Changed perf', 'Total']), rows = tsv_rows('bad-tests.tsv')) + table_template.format( caption = 'Tests with most unstable queries', header = table_header(['Test', 'Total client time, s', 'Number of queries', 'Time per query, s']), rows = tsv_rows('test-times.tsv')) ) print(doc_template.format_map(params))