Commit 9eccf665 authored by Tomas Krizek's avatar Tomas Krizek Committed by Petr Špaček

histogram: plot histogram of resolver response times

parent 32ec844b
#!/usr/bin/env python3
import argparse
import logging
import math
import pickle
from typing import Dict, List
import lmdb
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
from dbhelper import LMDB
def load_data(txn: lmdb.Transaction) -> Dict[str, List[float]]:
data = {} # type: Dict[str, List[float]]
cursor = txn.cursor()
for value in cursor.iternext(keys=False, values=True):
replies = pickle.loads(value)
for resolver, reply in replies.items():
data.setdefault(resolver, []).append(reply.duration)
return data
def plot_log_percentile_histogram(data: Dict[str, List[float]]):
For graph explanation, see
_, ax = plt.subplots(figsize=(8, 8))
# Distribute sample points along logarithmic X axis
percentiles = np.logspace(-3, 2, num=100)
ax.grid(True, which='major')
ax.grid(True, which='minor', linestyle='dotted', color='#DDDDDD')
ax.set_xlabel('Slowest percentile')
ax.set_ylabel('Response time [ms]')
ax.set_title('Resolver Response Time')
# plot data
for server in data:
# convert to ms and sort
values = sorted([1000 * x for x in data[server]], reverse=True)
[values[math.ceil(pctl * len(values) / 100) - 1] for pctl in percentiles],
lw=2, label=server)
def main():
format='%(levelname)s %(message)s', level=logging.DEBUG)
parser = argparse.ArgumentParser(
description='Plot query response time histogram from answers stored '
'in LMDB')
parser.add_argument('-o', '--output', type=str,
help='output image file (default: histogram.svg)')
parser.add_argument('envdir', type=str,
help='LMDB environment to read answers from')
args = parser.parse_args()
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)
# save to file
plt.savefig(args.output, dpi=300)
if __name__ == '__main__':
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