Commit f073800b authored by Tomas Krizek's avatar Tomas Krizek

histogram: support custom colors

In order to have graphs with stable colors, allow users to specify
custom colors in config.

Fixes knot/resolver-benchmarking#31
parent 6da15218
......@@ -59,6 +59,7 @@ _CFGFMT_SERVER = {
'ip': (ipaddr_check, True),
'port': (int, True),
'transport': (transport_opt, True),
'graph_color': (str, False),
}
......
......@@ -9,6 +9,7 @@ from typing import Dict, List
import lmdb
import numpy as np
import cfg
from dbhelper import LMDB
# Force matplotlib to use a different backend to handle machines without a display
......@@ -29,7 +30,7 @@ def load_data(txn: lmdb.Transaction) -> Dict[str, List[float]]:
return data
def plot_log_percentile_histogram(data: Dict[str, List[float]]):
def plot_log_percentile_histogram(data: Dict[str, List[float]], config=None):
"""
For graph explanation, see
https://blog.powerdns.com/2017/11/02/dns-performance-metrics-the-logarithmic-percentile-histogram/
......@@ -52,12 +53,17 @@ def plot_log_percentile_histogram(data: Dict[str, List[float]]):
ax.set_title('Resolver Response Time')
# plot data
for server in data:
for server in sorted(data):
try:
color = config[server]['graph_color']
except KeyError:
color = None
# convert to ms and sort
values = sorted([1000 * x for x in data[server]], reverse=True)
ax.plot(percentiles,
[values[math.ceil(pctl * len(values) / 100) - 1] for pctl in percentiles],
lw=2, label=server)
lw=2, label=server, color=color)
plt.legend()
......@@ -71,15 +77,18 @@ def main():
parser.add_argument('-o', '--output', type=str,
default='histogram.svg',
help='output image file (default: histogram.svg)')
parser.add_argument('-c', '--config', default='respdiff.cfg', dest='cfgpath',
help='config file (default: respdiff.cfg)')
parser.add_argument('envdir', type=str,
help='LMDB environment to read answers from')
args = parser.parse_args()
config = cfg.read_cfg(args.cfgpath)
with LMDB(args.envdir, readonly=True) as lmdb_:
adb = lmdb_.open_db(LMDB.ANSWERS)
with lmdb_.env.begin(adb) as txn:
data = load_data(txn)
plot_log_percentile_histogram(data)
plot_log_percentile_histogram(data, config)
# save to file
plt.savefig(args.output, dpi=300)
......
......@@ -18,6 +18,8 @@ names = google, surfnet, cznic
ip = 8.8.8.8
port = 53
transport = tcp
# optional graph color: common names or hex (#00FFFF) allowed
graph_color = cyan
[surfnet]
ip = 145.100.185.15
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment