jitter.py 2.15 KB
Newer Older
1
2
3
4
5
6
7
8
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (16,9)
plt.rcParams.update({'figure.autolayout': True})

from xlap.analyse.common import get_outlier_treshold, extract_durations
from xlap.analyse import box

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

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

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

Andreas Schmidt's avatar
Andreas Schmidt committed
17
def jitter_causes(df, export=False, file_name=None):
18
19
20
21
    stats = df["EndToEndTime"].describe()
    tresh = get_outlier_treshold(stats)
    outliers = df[df["EndToEndTime"] > tresh]

Andreas Schmidt's avatar
Andreas Schmidt committed
22
    # TODO: Refactor lines out.
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
    reasons = ["SendTime",
               "PrrtTransmitTime",
               "LinkTransmitTime",
               "SubmitTime",
               "SenderIPCTime",
               "SenderEnqueuedTime",
               #"EncodingTime",
               "EnqueueTime",
               "DecodingTime",
               "HandlePacketTime",
               "ReceiverIPCTime",
               "FeedbackTime"]

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

    for r in reasons:
        r_tresh = get_outlier_treshold(df[r].describe())
        df_reasons[r] = 0
        df_reasons[r] = outliers[outliers[r] > r_tresh].notnull()


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

Andreas Schmidt's avatar
Andreas Schmidt committed
54
55
56
57
58
def trace_jitter(df_filtered, export=False, file_name=None):
    thresh = get_outlier_treshold(df_filtered["EndToEndTime"].describe())
    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)))
59
60
61
    fig = plt.gcf()
    fig.canvas.set_window_title('Jitter Analysis')
    plt.show()
Andreas Schmidt's avatar
Andreas Schmidt committed
62
63
64
65
66

def prep(df, config):
    columns = extract_durations(config)
    df_filtered = df[columns]
    return df_filtered