summaryrefslogtreecommitdiff
path: root/nemesis/html_gen.py
blob: 44c7d563f0a1a2e90daa86f1eadc900e37b5b36f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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, filename):
    fig = make_subplots(rows=3, cols=1, shared_xaxes=True)

    for i, (coro_name, x_values) in enumerate(results.items(), start=1):
        x_list = []
        y_starve_list = []
        y_throughput_list = []
        y_time_in_coro_list = []
        starve_hover_text = []
        throughput_hover_text = []

        for speedup, experiments in x_values.items():
            for experiment in experiments:
                starve = experiment["time_starving"]
                processed = experiment["processed"]
                time_in_coro = experiment["time_in_coro"]
                real_duration = experiment["real_duration"]

                x_list.append(speedup)

                # handle starve graph
                starve_time = sum(starve.values())
                y_starve_list.append(starve_time)

                breakdown = "<br>".join([f"  {key[0]} ({key[1]}): {round(value, 4)}" for key, value in starve.items()])
                starve_hover_text.append(f"({speedup}, {round(starve_time, 4)})<br>{coro_name}<br>Breakdown:<br>{breakdown}")

                # handle throughput graph
                throughput = (speedup * processed) / real_duration
                y_throughput_list.append(throughput)

                throughput_hover_text.append(f"({speedup}, {round(throughput, 4 )})<br>{coro_name}<br>True experiment duration: {round(real_duration, 4)}<br>Total Processed: {processed}")

                # handle time in coro graph
                y_time_in_coro_list.append(time_in_coro / speedup)

        fig.add_trace(go.Scatter(
            x=x_list,
            y=y_starve_list,
            mode='markers',
            name=coro_name,
            hoverinfo='text',
            hovertext=starve_hover_text,
            marker=dict(color=get_color(coro_name)),
            showlegend=True,
        ), row=1, col=1)

        fig.add_trace(go.Scatter(
            x=x_list,
            y=y_throughput_list,
            mode='markers',
            name=coro_name,
            hovertext=throughput_hover_text,
            marker=dict(color=get_color(coro_name)),
            showlegend=False,
        ), row=2, col=1)

        fig.add_trace(go.Scatter(
            x=x_list,
            y=y_time_in_coro_list,
            mode='markers',
            name=coro_name,
            marker=dict(color=get_color(coro_name)),
            showlegend=False,
        ), row=3, col=1)

    fig.update_xaxes(title_text="Speedup (times faster)", row=1, col=1)
    fig.update_xaxes(title_text="Speedup (times faster)", row=2, col=1)
    fig.update_xaxes(title_text="Speedup (times faster)", row=3, col=1)
    fig.update_yaxes(title_text="Total Starvation Time (seconds)", row=1, col=1)
    fig.update_yaxes(title_text="Total Throughput (handles per second)", row=2, col=1)
    fig.update_yaxes(title_text="Synchronous Time in Coroutine (seconds)", row=3, col=1)

    fig.write_html(filename)