Commit 116a01bd authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

More appealing API for use in Juypter.

parent d4a0d13b
Loading
Loading
Loading
Loading
+32 −1
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.regress import linear as linear_regression
from xlap.analyse.trace import traces
from xlap.analyse.correlation import correlation
from xlap.analyse.latency import analyse
import pandas as pd
%matplotlib inline
```

%% Cell type:markdown id: tags:

## Data Retrieval

%% Cell type:code id: tags:

``` python
config = parse_config()
data_files = config["data_files"]
original = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)[:4094]
original = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)
```

%% Cell type:markdown id: tags:

## Traces

%% Cell type:code id: tags:

``` python
traces(original, config)
```

%% Cell type:markdown id: tags:

## Jitter Analysis

%% Cell type:code id: tags:

``` python
df = jitter.prep(original, config=config)
jitter.trace_jitter(df, threshold=500)
```

%% Cell type:markdown id: tags:

## Correlation

%% Cell type:code id: tags:

``` python
correlation(df[df["EndToEnd_D"] < 500], config)
```

%% Cell type:markdown id: tags:

## Latency Criticality

%% Cell type:code id: tags:

``` python
d = analyse(original, 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:code id: tags:

``` python
```
+66 −57
Original line number Diff line number Diff line
import pandas as pd
import matplotlib.pyplot as plt
from xlap.analyse.util import get_outlier_threshold, extract_durations, box
from scipy.stats.stats import pearsonr
import numpy as np
import sys
import graphviz


class LatencyAnalysis():
    def __init__(self, cfg=None, hdb=None):
        self.cfg = cfg

        correlations = []
        labels = []
        for x in hdb:
            correlations += [x["Correlation"]]
            labels += ["{} -> {}".format(x["Start"], x["End"])]

        corr = pd.Series(correlations, index=labels)

        self.corr = corr


def _get_thread_for_event(config, e):
    name = str(e)[:-2]
    try:
@@ -112,13 +126,13 @@ def _plot_controlflow_graph(df, hdb):
    generate the control flow graph using dot
    """
    t_columns = [x for x in df.columns if x.endswith("_T")]
    d = graphviz.Digraph(filename="graph", format="pdf")
    graph = graphviz.Digraph(filename="graph", format="pdf")
    for event1 in df[t_columns]:
        d.node(str(event1)[:-2])
        graph.node(str(event1)[:-2])
    for edge in hdb:
        d.edge(edge["Start"][:-2], edge["End"][:-2])
    d.render()  # saves to graph.pdf in local folder
    return d
        graph.edge(edge["Start"][:-2], edge["End"][:-2])
    graph.render()  # saves to graph.pdf in local folder
    return graph


# Taken from: http://composition.al/blog/2015/11/29/a-better-way-to-add-labels-to-bar-charts-with-matplotlib/
@@ -147,14 +161,11 @@ def autolabel(rects, ax, labels):
        ax.text(label_position, rect.get_y(), labels[i], ha=align, va='bottom', rotation=0, color=color)


def _plot_critical_regions(df, hdb):
def _plot_critical_regions(hdb):
    """
    plot regions, sorted by latency criticality
    """
    plt.rcParams["font.family"] = "serif"
    for region in sorted(hdb, key=lambda x: -x['Correlation']):
        print("%-10f %10s -> %10s" % (region['Correlation'], region['Start'], region['End']), file=sys.stderr)

    relevant = sorted([x for x in hdb if x['Correlation'] > 0], key=lambda x: -x['Correlation'], reverse=True)
    x = np.arange(len(relevant))

@@ -198,7 +209,5 @@ def _plot_critical_regions(df, hdb):
                hdb += [{'Start': str(event1), 'End': str(event2), 'Correlation': correlation}]

    cfg = _plot_controlflow_graph(df, hdb)
        _plot_critical_regions(df, hdb)
        return {
            "cfg": cfg
        }
    _plot_critical_regions(hdb)
    return LatencyAnalysis(cfg=cfg, hdb=hdb)
+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ def main():
                print(output)
        elif command == "latency":
            df_data = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)
            latency.analyse(df_data, config)
            a = latency.analyse(df_data, config)
            print(a.corr.sort_values(ascending=False))
        else:
            df_data = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)