import plotly.graph_objects as go
from plotly.subplots import make_subplots
import hashlib
def get_color(name):
hash_object = hashlib.md5(name.encode())
color_index = int(hash_object.hexdigest(), 16) % 360
return f'hsl({color_index}, 100%, 50%)'
def plot_results(results, output_file, input_file):
fig = make_subplots(rows=4, cols=1)
for i, (coro_name, x_values) in enumerate(results.items(), start=1):
x_list = []
y_latency_list = []
y_throughput_list = []
y_max_latency_list = []
y_num_callbacks_list = []
latency_hover_text = []
max_latency_hover_text = []
for speedup, experiments in x_values.items():
for experiment in experiments:
completed_callbacks = experiment["latency"]
virtual_run_time = experiment["virtual_run_time"][0]
x_list.append(speedup * 100)
num_callbacks = len(completed_callbacks)
y_num_callbacks_list.append(num_callbacks)
# handle average latency graph
if num_callbacks > 0:
breakdown = "
".join([f" {cb[0]}: {round(cb[1], 4)}" for cb in completed_callbacks])
total_wait = sum([cb[1] for cb in completed_callbacks])
max_cb = max(completed_callbacks, key=lambda cb: cb[1])
latency = total_wait / num_callbacks
y_max_latency_list.append(max_cb[1])
y_latency_list.append(latency)
else:
latency = 0
y_latency_list.append(latency)
latency_hover_text.append(f"{coro_name}
Speedup: {speedup}
Average Wait: {round(latency, 4)}
Breakdown:
{breakdown}")
max_latency_hover_text.append(f"{coro_name}
Speedup: {speedup}
Max Wait: {round(max_cb[1], 4)}
Handle: {max_cb[0]}")
# handle throughput graph
throughput = num_callbacks / virtual_run_time
y_throughput_list.append(throughput)
fig.add_trace(go.Scatter(
x=x_list,
y=y_latency_list,
mode='markers',
name=coro_name,
marker=dict(color=get_color(coro_name)),
hovertext=latency_hover_text,
showlegend=True,
), row=1, col=1)
fig.add_trace(go.Scatter(
x=x_list,
y=y_throughput_list,
mode='markers',
name=coro_name,
marker=dict(color=get_color(coro_name)),
showlegend=False,
), row=2, col=1)
fig.add_trace(go.Scatter(
x=x_list,
y=y_max_latency_list,
mode='markers',
name=coro_name,
marker=dict(color=get_color(coro_name)),
hovertext=max_latency_hover_text,
showlegend=False,
), row=3, col=1)
fig.add_trace(go.Scatter(
x=x_list,
y=y_num_callbacks_list,
mode='markers',
name=coro_name,
marker=dict(color=get_color(coro_name)),
showlegend=False,
), row=4, col=1)
fig.update_layout(title=input_file)
fig.update_xaxes(title_text="speedup (% optimized away)", row=4, col=1)
fig.update_yaxes(title_text="average latency (seconds)", row=1, col=1)
fig.update_yaxes(title_text="throughput (handles per second)", row=2, col=1)
fig.update_yaxes(title_text="maximum latency (seconds)", row=3, col=1)
fig.update_yaxes(title_text="# of callbacks", row=4, col=1)
fig.write_html(output_file)