jitter.py 2.15 KB
Newer Older
1
2
import pandas as pd
import matplotlib.pyplot as plt
3
4

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

7
from xlap.analyse.common import get_outlier_threshold, extract_durations
8
9
from xlap.analyse import box

10

Andreas Schmidt's avatar
Andreas Schmidt committed
11
12
# TODO: Refactor.

13
14
15
def _dn(x):
    return x + "Time"

16

17
18
19
def _filter(x, durations, source):
    return durations[x]["Source"] == source

20

Andreas Schmidt's avatar
Andreas Schmidt committed
21
def jitter_causes(df, export=False, file_name=None):
22
    stats = df["EndToEndTime"].describe()
23
    tresh = get_outlier_threshold(stats)
24
25
    outliers = df[df["EndToEndTime"] > tresh]

Andreas Schmidt's avatar
Andreas Schmidt committed
26
    # TODO: Refactor lines out.
27
28
29
30
31
32
33
34
35
36
37
38
    reasons = ["Send_D",
               "PrrtTransmit_D",
               "LinkTransmit_D",
               "Submit_D",
               "SenderIPC_D",
               "SenderEnqueued_D",
               # "EncodingTime",
               "Enqueue_D",
               "Decoding_D",
               "HandlePacket_D",
               "ReceiverIPC_D",
               "Feedback_D"]
39
40
41
42

    df_reasons = pd.DataFrame(index=outliers.index)

    for r in reasons:
43
        r_tresh = get_outlier_threshold(df[r].describe())
44
45
46
47
        df_reasons[r] = 0
        df_reasons[r] = outliers[outliers[r] > r_tresh].notnull()

    df_sum = df_reasons.sum().sort_values(ascending=False)
48
49
    ax = df_sum.plot.bar(x="Reason", y="Frequency", rot=45, grid=True, legend=False, color="black")
    fig = ax.get_figure()
50
    plt.ylabel("Frequency")
51
    ax.set_xticklabels(list(map(lambda x: x.get_text().replace("_D", ""), ax.get_xticklabels())))
52
    fig.set_size_inches(8, 3, forward=True)
Andreas Schmidt's avatar
Andreas Schmidt committed
53
54
    if export:
        fig.savefig(file_name)
55
56
    print("Outliers:", len(outliers), ";", "Threshold[us]:", tresh)

57

Andreas Schmidt's avatar
Andreas Schmidt committed
58
def trace_jitter(df_filtered, export=False, file_name=None):
59
    thresh = get_outlier_threshold(df_filtered["EndToEndTime"].describe())
Andreas Schmidt's avatar
Andreas Schmidt committed
60
61
62
    df_no_outliers = df_filtered[df_filtered["EndToEndTime"] <= thresh]
    box(df_no_outliers, export, file_name)
    print("{} / {} are no outliers.".format(len(df_no_outliers), len(df_filtered)))
63
64
65
    fig = plt.gcf()
    fig.canvas.set_window_title('Jitter Analysis')
    plt.show()
Andreas Schmidt's avatar
Andreas Schmidt committed
66

67

Andreas Schmidt's avatar
Andreas Schmidt committed
68
69
70
71
def prep(df, config):
    columns = extract_durations(config)
    df_filtered = df[columns]
    return df_filtered