Created
June 28, 2019 05:29
-
-
Save cosven/5856e46245b903ba8a79720441e3e299 to your computer and use it in GitHub Desktop.
sysbench 结果统计
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
from collections import defaultdict | |
def get_query_per_sec(line): | |
""" | |
>>> s = 'queries: 17493427 (58309.95 per sec.)' | |
>>> get_query_per_sec(s) | |
58309.95 | |
""" | |
return float(line.split('(')[1].split(' ')[0]) | |
def get_p95_latency(line): | |
""" | |
>>> s = "95th percentile: 2.35" | |
>>> get_p95_latency(s) | |
2.35 | |
""" | |
return float(line.split(':')[1].strip()) | |
def calc_per_dir(dirname): | |
"""计算每个目录的结果 | |
每个目录有三个 sysbench 结果文件 | |
""" | |
query_per_sec_sum = 0 | |
latency_list = [] | |
for fname in os.listdir(dirname): | |
if not fname.endswith('.out'): | |
continue | |
fpath = os.path.join(dirname, fname) | |
with open(fpath) as f: | |
for line in f: | |
line = line.strip() | |
if line.startswith('queries:'): | |
query_per_sec = get_query_per_sec(line) | |
query_per_sec_sum += query_per_sec | |
if line.startswith('95th'): | |
latency = get_p95_latency(line) | |
latency_list.append(latency) | |
assert len(latency_list) == 3 | |
latency_mid = sorted(latency_list)[1] | |
return query_per_sec_sum, latency_mid | |
def get_threads_count_from_dirname(dirname): | |
"""获取 threads 数目""" | |
return int(dirname.split('_')[-3]) | |
def get_type_from_dirname(dirname): | |
"""获取实验类型 -- 比如:oltp-point-select""" | |
return '-'.join(dirname.split('_')[1:-3]) | |
def show(result): | |
"""展示结果""" | |
for result_type, results in result.items(): | |
print(result_type) | |
results = sorted(results, key=lambda each: each[0]) | |
for each in results: | |
threads = each[0] | |
qps, latency = each[1] | |
print('{} \t {:.2f} \t {}'.format(each[0], qps, latency)) | |
def show_as_md_table(result): | |
"""展示结果 markdown table""" | |
for result_type, results in result.items(): | |
print(result_type) | |
print() | |
results = sorted(results, key=lambda each: each[0]) | |
print('| threads | qps | latency |') | |
print('| ------- | --- | ------- |') | |
for each in results: | |
threads = each[0] | |
qps, latency = each[1] | |
print('| {} | {:.2f} | {} |'.format(each[0], qps, latency)) | |
print() | |
def calc_all_v21(): | |
result = defaultdict(list) | |
for fname in os.listdir('.'): | |
if fname.startswith('2.1_oltp'): | |
dirname = fname | |
threads_count = get_threads_count_from_dirname(dirname) | |
result_type = get_type_from_dirname(dirname) | |
_result = (threads_count * 3, calc_per_dir(dirname)) | |
result[result_type].append(_result) | |
show_as_md_table(result) | |
def calc_all_v3(): | |
result = defaultdict(list) | |
for fname in os.listdir('.'): | |
if fname.startswith('oltp'): | |
dirname = fname | |
threads_count = get_threads_count_from_dirname(dirname) | |
result_type = '-'.join(dirname.split('_')[:-3]) | |
_result = (threads_count * 3, calc_per_dir(dirname)) | |
result[result_type].append(_result) | |
show(result) | |
if __name__ == '__main__': | |
calc_all_v3() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
脚本测试时的目录结构