__init__.py 3.31 KB
Newer Older
Andreas Schmidt's avatar
Andreas Schmidt committed
1
2
import math
import numpy as np
3
import matplotlib.pyplot as plt
Andreas Schmidt's avatar
Andreas Schmidt committed
4
5

plt.rcParams["figure.figsize"] = (16, 9)
6
7
plt.rcParams.update({'figure.autolayout': True})

Andreas Schmidt's avatar
Andreas Schmidt committed
8

Andreas Schmidt's avatar
Andreas Schmidt committed
9
10
# TODO: Refactor.

11

Andreas Schmidt's avatar
Andreas Schmidt committed
12
13

def trace(df, title, export=False):
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    fig, ax = plt.subplots(figsize=(8, 4.5))
    plt.grid()

    base = df["PrrtSendStart_T"]

    sender_color = "#AAAAAA"
    receiver_color = "#888888"

    series = np.transpose(np.array([
        ["PrrtSendStart_T", "PrrtDeliver_T", "black", "EndToEnd"],
        ["PrrtSendStart_T", "LinkTransmitEnd_T", sender_color, "SenderTotal"],
        ["PrrtSendStart_T", "PrrtSendEnd_T", sender_color, "Send"],
        ["PrrtSendStart_T", "PrrtSubmitPackage_T", sender_color, "Submit"],
        ["PrrtSubmitPackage_T", "PrrtTransmitStart_T", sender_color, "SenderIPC"],
        ["PrrtSubmitPackage_T", "PrrtSendEnd_T", sender_color, "Enqueue"],
        ["PrrtSendEnd_T", "LinkTransmitStart_T", sender_color, "SenderEnqueued"],
        ["PrrtTransmitStart_T", "PrrtTransmitEnd_T", sender_color, "PrrtTransmit"],
        ["LinkTransmitStart_T", "LinkTransmitEnd_T", sender_color, "LinkTransmit"],
        ["LinkReceive_T", "PrrtDeliver_T", receiver_color, "ReceiverTotal"],
Andreas Schmidt's avatar
Andreas Schmidt committed
33
        # ["DecodeStart_T", "DecodeEnd_T", receiver_color, "Decoding"],
34
35
36
37
38
39
40
        ["HandlePacketStart_T", "HandlePacketEnd_T", receiver_color, "HandlePacket"],
        ["PrrtReturnPackage_T", "PrrtReceivePackage_T", receiver_color, "ReceiverIPC"],
        ["SendFeedbackStart_T", "SendFeedbackEnd_T", receiver_color, "Feedback"],
    ]))
    n = series.shape[1]
    starts = df[series[0]] - base
    ends = df[series[1]] - base
Andreas Schmidt's avatar
Andreas Schmidt committed
41
    plt.hlines(range(n), starts, ends, series[2], linewidths=[5])
42
43
44
45
46
47
    plt.xlabel("Time [us]")
    fig.canvas.draw()

    ax.set_yticklabels(series[3])
    ax.yaxis.set_ticks(np.arange(0, n, 1))

Andreas Schmidt's avatar
Andreas Schmidt committed
48
49
    if export:
        plt.savefig(title)
50
51
    plt.show()

Andreas Schmidt's avatar
Andreas Schmidt committed
52
53
54
55

def box(df_data, export=False, title=None):
    ax = df_data.plot.box(vert=False, grid=True)
    fig = ax.get_figure()
56
    ax.set_yticklabels(list(map(lambda x: x.get_text().replace("_D", ""), ax.get_yticklabels())))
57
58
    plt.xlabel("Time [us]")
    fig.set_size_inches(8, 4.5, forward=True)
Andreas Schmidt's avatar
Andreas Schmidt committed
59
    if export and title is not None:
60
61
        fig.savefig(title)

Andreas Schmidt's avatar
Andreas Schmidt committed
62

63
64
def describe_table(df):
    stats = df.describe()
Andreas Schmidt's avatar
Andreas Schmidt committed
65
    stats.drop(["count"], inplace=True)
66
    stats.columns = list(map(lambda x: x.replace("_D", ""), stats.columns))
67
68
69
70
    table = stats.to_latex(float_format=lambda x: "%.3f" % x)
    print(table)
    return stats

Andreas Schmidt's avatar
Andreas Schmidt committed
71
72

def correlation(df_data, title="Correlation.pdf"):
73
    columns = list(["Sender_D",
74
75
76
                    "SendTime",
                    "SenderIPCTime",
                    "LinkTransmitTime",
77
                    "Receiver_D",
78
79
80
81
82
                    "ReceiverIPCTime",
                    "HandlePacketTime",
                    "FeedbackTime",
                    ])

Andreas Schmidt's avatar
Andreas Schmidt committed
83
84
    cols = 4
    rows = int(math.ceil(len(columns) / cols))
85
    fig, axes = plt.subplots(nrows=rows, ncols=cols)
Andreas Schmidt's avatar
Andreas Schmidt committed
86
    fig.set_size_inches(4 * cols, 3.5 * rows, forward=True)
87
88
89

    i = 0
    for column in columns:
Andreas Schmidt's avatar
Andreas Schmidt committed
90
91
        ax = df_data.plot.scatter(ax=axes[i // cols, i % cols], y="EndToEndTime", x=column, grid=True, marker="+",
                                  color="black")
92
        ax.set_ylabel("EndToEnd [us]")
Andreas Schmidt's avatar
Andreas Schmidt committed
93
        ax.margins(0.1, 0.1)
94
        ax.set_xlabel("{} [us]".format(column.replace("_D", "")))
95
96
        i += 1
    fig.savefig(title)