__init__.py 3.63 KB
Newer Older
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (16,9)
plt.rcParams.update({'figure.autolayout': True})

def hist(df):
    return df.hist(cumulative=True, normed=1,bins=200)

def scatter(df,column):
    plt.scatter(df.index,df[column],grid=True)

def regress(df,column):
    x = df.index.values.reshape(-1,1)
    y = df[column].values

    model = linear_model.LinearRegression()
    model.fit(x,y)
    print("R-Score:", model.score(x,y))
    plt.scatter(x,y)
    plt.grid()
    plt.plot(x,model.predict(x),color="red",linewidth=3)

def trace(df,title):
    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"],
        #["DecodeStart_T", "DecodeEnd_T", receiver_color, "Decoding"],
        ["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
    plt.hlines(range(n), starts, ends, series[2],linewidths=[5])
    plt.xlabel("Time [us]")
    fig.canvas.draw()

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

    plt.savefig(title)
    plt.show()

def box(df_data,title=None):
    ax = df_data.plot.box(vert=False,grid=True)
    fig=ax.get_figure()
    ax.set_yticklabels(list(map(lambda x: x.get_text().replace("Time", ""), ax.get_yticklabels())))
    plt.xlabel("Time [us]")
    fig.set_size_inches(8, 4.5, forward=True)
    if title is not None:
        fig.savefig(title)

def describe_table(df):
    stats = df.describe()
    stats.drop(["count"],inplace=True)
    stats.columns = list(map(lambda x: x.replace("Time", ""), stats.columns))
    table = stats.to_latex(float_format=lambda x: "%.3f" % x)
    print(table)
    return stats

def correlation(df_data,title="Correlation.pdf"):
    columns = list(["SenderTotalTime",
                    "SendTime",
                    "SenderIPCTime",
                    "LinkTransmitTime",
                    "ReceiverTotalTime",
                    "ReceiverIPCTime",
                    "HandlePacketTime",
                    "FeedbackTime",
                    ])

    cols=4
    rows=math.ceil(len(columns) / cols)
    fig, axes = plt.subplots(nrows=rows, ncols=cols)
    fig.set_size_inches(4*cols, 3.5*rows, forward=True)

    i = 0
    for column in columns:
        ax = df_data.plot.scatter(ax=axes[i//cols,i % cols],y="EndToEndTime",x=column,grid=True,marker="+",color="black")
        fig2 = ax.get_figure()
        ax.set_ylabel("EndToEnd [us]")
        ax.margins(0.1,0.1)
        ax.set_xlabel("{} [us]".format(column.replace("Time", "")))
        i += 1
    fig.savefig(title)