Commit 27d0f7e8 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

~= refactor

parent e5fd2741
Loading
Loading
Loading
Loading
+28 −62
Original line number Diff line number Diff line
%% Cell type:markdown id: tags:

# X-Lap in Action

%% Cell type:markdown id: tags:

## Imports

%% Cell type:code id: tags:

``` python
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from xlap.parse import evaluate, evaluate_side, parse_config
import xlap.analyse.jitter as jitter
from xlap.analyse.cdf import multi_cdf
from xlap.analyse.regress import linear as linear_regression
from xlap.analyse.trace import traces
from xlap.analyse.correlation import correlation, multi_correlation
from xlap.analyse.latency import analyse
import matplotlib.pyplot as plt
import pandas as pd
import copy
%matplotlib inline
colors = ["#E69F00", "#009E73", "#56B4E9",  "#CC79A7", "#D55E00"]
```

%% Cell type:markdown id: tags:

## Data Retrieval

%% Cell type:code id: tags:

``` python
from xlap.parse import evaluate, parse_config
config = parse_config()
data_files = {
    "sender": "rtn2018/20180417_testbed/",
    "receiver": "rtn2018/20180417_testbed/"
}
original1 = evaluate(data_files["sender"] + "sender-1000000.csv", data_files["receiver"] + "receiver-1000000.csv", config=config, kind=0)
original1.name = "1GHz"
original2 = evaluate(data_files["sender"] + "sender-2000000.csv", data_files["receiver"] + "receiver-2000000.csv", config=config, kind=0)
original2.name = "2GHz"
original3 = evaluate(data_files["sender"] + "sender-3000000.csv", data_files["receiver"] + "receiver-3000000.csv", config=config, kind=0)
original3.name = "3GHz"
dfs = [original1, original2, original3]
df_1GHz = evaluate(data_files["sender"] + "sender-1000000.csv", data_files["receiver"] + "receiver-1000000.csv", config=config, kind=0)
df_1GHz.name = "1GHz"
df_2GHz = evaluate(data_files["sender"] + "sender-2000000.csv", data_files["receiver"] + "receiver-2000000.csv", config=config, kind=0)
df_2GHz.name = "2GHz"
df_3GHz = evaluate(data_files["sender"] + "sender-3000000.csv", data_files["receiver"] + "receiver-3000000.csv", config=config, kind=0)
df_3GHz.name = "3GHz"
dfs = [df_1GHz, df_2GHz, df_3GHz]
```

%% Cell type:markdown id: tags:

## Traces

%% Cell type:code id: tags:

``` python
traces(original1, config, global_xaxis=True)
from xlap.analyse.trace import traces
traces(df_1GHz, config, global_xaxis=True)
```

%% Cell type:markdown id: tags:

## Jitter Analysis

%% Cell type:code id: tags:

``` python
def multi_trace_jitter(dfs, config):
    for df in dfs:
        print("############################ {} ############################".format(df.name))
        jitter.trace_jitter(df, config=config, threshold=200)

from xlap.analyse.jitter import multi_trace_jitter
multi_trace_jitter(dfs, config)
```

%% Cell type:markdown id: tags:

## CDFs

%% Cell type:code id: tags:

``` python
from xlap.analyse.cdf import multi_cdf
from xlap.analyse.util import colors
import copy
cfg = copy.deepcopy(config)
d = cfg["durations"]

l=("Decoding","ReceiverIPC","HandlePacket", "Feedback", "SenderIPC","SenderEnqueued","Enqueue")
for e in l:
    if e in l:
        del d[e]

list(map(cfg["durations"].pop, ("Decoding",
                                "ReceiverIPC",
                                "HandlePacket",
                                "Feedback",
                                "SenderIPC",
                                "SenderEnqueued",
                                "Enqueue")))
multi_cdf(dfs, cfg, colors=colors)
```

%% Cell type:markdown id: tags:

## Correlation

%% Cell type:code id: tags:

``` python
from xlap.analyse.correlation import multi_correlation
multi_correlation(dfs, config, colors=colors, figsize=(3.0,2.0), cols=4)
```

%% Cell type:markdown id: tags:

## Latency Criticality

%% Cell type:code id: tags:

``` python
d = analyse(original1, config)
from xlap.analyse.latency import analyse
d = analyse(df_1GHz, config)
```

%% Cell type:markdown id: tags:

### Correlations

%% Cell type:code id: tags:

``` python
d.corr.sort_values(ascending=False)
```

%% Cell type:markdown id: tags:

### Control Flow Graph

%% Cell type:code id: tags:

``` python
d.cfg
```

%% Cell type:markdown id: tags:

# Kolmogorov

%% Cell type:code id: tags:

``` python
from scipy import stats
from xlap.analyse.util import extract_durations
import numpy as np

def timing_behaviour(df1, df2, config, confidence=0.9):
    durations = [x + "_D" for x in extract_durations(config)]

    norm = lambda x: x / np.max(x)

    for duration in durations:
        rvs1 = norm(df1[duration])
        rvs2 = norm(df2[duration])
        stat, pvalue = stats.ks_2samp(rvs1, rvs2)
        result = "CANNOT REJECT"
        if pvalue < 1 - confidence:
            result = "REJECT"
        print(duration.ljust(20), "{:.6f}".format(pvalue), result, sep="\t\t")

timing_behaviour(original1, original2, config)
from xlap.analyse.timing import timing_behaviour
timing_behaviour(df_1GHz, df_2GHz, config)
```

%% Cell type:code id: tags:

``` python
timing_behaviour(original1, original3, config)
timing_behaviour(df_1GHz, df_3GHz, config)
```

%% Cell type:code id: tags:

``` python
timing_behaviour(original2, original3, config)
timing_behaviour(df_2GHz, df_3GHz, config)
```
+7 −2
Original line number Diff line number Diff line
@@ -38,10 +38,15 @@ def trace_jitter(data_frame, config=None, threshold=None, export=False, file_nam
    if threshold is None:
        threshold = get_outlier_threshold(data_frame["EndToEnd_D"].describe())
    df_no_outliers = data_frame[data_frame["EndToEnd_D"] <= threshold]
    fig = plt.gcf()
    ax, fig = box(df_no_outliers, (0, threshold), export, file_name, figsize)
    fig.set_size_inches(figsize[0], figsize[1])
    box(df_no_outliers, (0, threshold), export, file_name, figsize)
    print("{} / {} are no outliers.".format(len(df_no_outliers), len(data_frame)))
    fig.canvas.set_window_title('Jitter Analysis')
    plt.show()
    plt.close()
    return None

def multi_trace_jitter(dfs, config):
    for df in dfs:
        print("############################ {} ############################".format(df.name))
        trace_jitter(df, config=config, threshold=200)

xlap/analyse/timing.py

0 → 100644
+16 −0
Original line number Diff line number Diff line
from scipy import stats
from xlap.analyse.util import extract_durations
import numpy as np

def timing_behaviour(df1, df2, config, confidence=0.9):
    durations = [x + "_D" for x in extract_durations(config)]

    norm = lambda x: x / np.max(x)

    for duration in durations:
        rvs1 = norm(df1[duration])
        rvs2 = norm(df2[duration])
        stat, pvalue = stats.ks_2samp(rvs1, rvs2)
        result = ("REJECT" if pvalue < 1 - confidence else
                  "CANNOT REJECT")
        print(duration.ljust(20), "{:.6f}".format(pvalue), result, sep="\t\t")
+1 −1
Original line number Diff line number Diff line
@@ -92,6 +92,6 @@ def traces(df, config, figsize=(10, 4.5), global_xaxis=False):
    if global_xaxis:
        t_max = df["EndToEnd_D"].max()

    @interact(seq_no=widgets.IntSlider(min=1, max=len(df), step=1, value=47))
    @interact(seq_no=widgets.IntSlider(min=1, max=len(df), step=1, value=47,description="Seq. No."))
    def _f(seq_no):
        trace(df.iloc[seq_no], config, figsize=figsize, t_max=t_max)
+3 −1
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@ import matplotlib.pyplot as plt
import numpy as np
import math

colors = ["#E69F00", "#009E73", "#56B4E9",  "#CC79A7", "#D55E00"]

def cdf(values, ax=None, grid=False, **kwargs):
    if ax is None:
        ax = plt
@@ -54,7 +56,7 @@ def box(data_frame, xlim=None, export=False, file_name=None, figsize=(8, 4.5)):
    plt.tight_layout()
    if export and file_name is not None:
        fig.savefig(file_name)

    return ax, fig

def describe_table(df):
    stats = df.describe()