Commit 842a71dc authored by Florian Fischer's avatar Florian Fischer
Browse files

add median to tikz plot and latency summary cli option

parent 4a8dcf8d
......@@ -2,16 +2,17 @@
import argparse
import pathlib
from string import Template
import sys
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.pyplot as plt
import plot_utils
CSV_FIELDS = {'total': 0, 'after-send': 1, 'after-send-dispatch': 2}
def get_bar_data(latency_files, latency):
def get_bar_data(latency_files, latency='total', include_raw_data=False):
field = CSV_FIELDS[latency]
prctl = [50, 95, 99, 99.99, 99.999]
......@@ -38,6 +39,9 @@ def get_bar_data(latency_files, latency):
99.999: p99_999
}
if include_raw_data:
data[impl]['latencies'] = ns
return data
......@@ -53,13 +57,13 @@ def plot_tail_latency_bar_tikz(latency_files, latency):
ybar,
enlargelimits=0.15,
legend style={
at={(0.5,-0.15)},
at={(0.5,-0.25)},
anchor=north,
legend columns=-1},
legend columns=2},
ylabel={latency in ms},
xlabel={percentiles},
cycle list name=barvibrant,
symbolic x coords={95\\%,99\\%,99.99\\%,99.999\\%},
symbolic x coords={50\\%,95\\%,99\\%,99.99\\%,99.999\\%},
xtick=data,
nodes near coords,
nodes near coords align={horizontal},
......@@ -68,7 +72,7 @@ def plot_tail_latency_bar_tikz(latency_files, latency):
""")
addplot = Template(
"\\addplot coordinates {(95\\%, $p95) (99\\%, $p99) (99.99\\%, $p99_99) (99.999\\%, $p99_999)};"
"\\addplot coordinates {(50\\%, $p50) (95\\%, $p95) (99\\%, $p99) (99.99\\%, $p99_99) (99.999\\%, $p99_999)};"
)
tail = Template("""\\legend{$labels}
......@@ -79,11 +83,12 @@ def plot_tail_latency_bar_tikz(latency_files, latency):
labels = ''
plots = []
for impl, data in get_bar_data(latency_files, latency).items():
for impl, data in get_bar_data(latency_files, latency=latency).items():
impl_label = plot_utils.subst_runtime_name(impl)
labels += f'{impl_label}, '
# convert to ms
p95, p99, p99_99, p99_999 = np.array([
p50, p95, p99, p99_99, p99_999 = np.array([
data['median'],
data[95],
data[99],
data[99.99],
......@@ -91,7 +96,8 @@ def plot_tail_latency_bar_tikz(latency_files, latency):
]) // 1000000
plots.append(
addplot.substitute(p95=p95,
addplot.substitute(p50=p50,
p95=p95,
p99=p99,
p99_99=p99_99,
p99_999=p99_999))
......@@ -107,8 +113,8 @@ def plot_tail_latency_bar(latency_files, latency):
width = 1 / (n_impls + 1)
impl_bars = []
for i, (impl,
data) in enumerate(get_bar_data(latency_files, latency).items()):
for i, (impl, data) in enumerate(
get_bar_data(latency_files, latency=latency).items()):
x_base = np.arange(1, len(data) + 1)
x = x_base + width / 2 + (i * width)
......@@ -165,6 +171,48 @@ def plot_tail_latency_linear(latency_files, latency):
plt.show()
def summarize(latency_files, latency):
bar_data = get_bar_data(latency_files,
latency=latency,
include_raw_data=True)
impls = list(bar_data.keys())
impls.sort()
for impl in impls:
data = bar_data[impl]
latencies = data['latencies'] / 1000000
# convert to ms
median, p95, p99, p99_99, p99_999 = np.array([
data['median'],
data[95],
data[99],
data[99.99],
data[99.999],
]) / 1000000
name = impl.replace('-io', '').replace('emper-',
'').replace('-0us-1ms', '')
data_min = min(latencies)
data_max = max(latencies)
print(f'{name}-min: {data_min:.2f}')
print(f'{name}-max: {data_max:.2f}')
print(f'{name}-mean: {np.mean(latencies):.2f}')
print(f'{name}-median: {median:.2f}')
print(f'{name}-p95: {p95:.2f}')
print(f'{name}-p99: {p99:.2f}')
print(f'{name}-p99.99: {p99_99:.2f}')
print(f'{name}-p99.999: {p99_999:.2f}')
bin_edge_candidates = [
data_min, median, 100, 500, 1000, 1750, 2500, 5000, 7500, 10000,
data_max
]
bin_edges = [c for c in bin_edge_candidates if c <= data_max]
hist, bin_edges = np.histogram(latencies, bin_edges)
print(f'{name}-hist: {list(hist)}')
print(f'{name}-hist-bin-edges: {[f"{e:.2f}" for e in bin_edges]}')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("data_files", nargs='+')
......@@ -174,9 +222,14 @@ if __name__ == '__main__':
parser.add_argument("--plot",
choices=['line', 'bar', 'bar-tikz'],
default='line')
parser.add_argument("--summarize", action='store_true')
args = parser.parse_args()
if args.summarize:
summarize(args.data_files, args.latency)
sys.exit(0)
if args.plot == 'bar':
plot_tail_latency_bar(args.data_files, args.latency)
elif args.plot == 'line':
......
Supports Markdown
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