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

{header}

{test_part} """ table_template = """

{caption}

{header} {rows}
""" table_anchor = 0 row_anchor = 0 def nextTableAnchor(): global table_anchor table_anchor += 1 return str(table_anchor) def nextRowAnchor(): global row_anchor global table_anchor row_anchor += 1 return str(table_anchor) + "." + str(row_anchor) def tr(x): a = nextRowAnchor() #return '{x}'.format(a=a, x=str(x)) return '{x}'.format(a=a, x=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( anchor = nextTableAnchor(), caption = 'Tested commits', header = table_header(['Old', 'New']), rows = table_row([open('left-commit.txt').read(), open('right-commit.txt').read()]) ) + table_template.format( anchor = nextTableAnchor(), caption = 'Changes in performance', header = table_header(['Old, s', 'New, s', 'Relative difference (new - old)/old', 'Randomization distribution quantiles [5%, 50%, 95%]', 'Test', 'Query']), rows = tsv_rows('changed-perf.tsv')) + table_template.format( anchor = nextTableAnchor(), 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( anchor = nextTableAnchor(), caption = 'Unstable queries', header = table_header(['Old, s', 'New, s', 'Relative difference (new - old)/old', 'Randomization distribution quantiles [5%, 50%, 95%]', 'Test', 'Query']), rows = tsv_rows('unstable-queries.tsv')) + table_template.format( anchor = nextTableAnchor(), caption = 'Run errors', header = table_header(['A', 'B']), rows = tsv_rows('run-errors.log')) + table_template.format( anchor = nextTableAnchor(), caption = 'Tests with most unstable queries', header = table_header(['Test', 'Unstable', 'Changed perf', 'Total not OK']), rows = tsv_rows('bad-tests.tsv')) + table_template.format( anchor = nextTableAnchor(), caption = 'Tests times', header = table_header(['Test', 'Wall clock time, s', 'Total client time, s', 'Total queries', 'Ignored short queries', 'Longest query
(sum for all runs), s', 'Avg wall clock time
(sum for all runs), s', 'Shortest query
(sum for all runs), s']), rows = tsv_rows('test-times.tsv')) ) print(doc_template.format_map(params))