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

~= refactor

parent e5fd2741
...@@ -7,36 +7,13 @@ ...@@ -7,36 +7,13 @@
"# X-Lap in Action" "# X-Lap in Action"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"import logging\n", "%matplotlib inline"
"logger = logging.getLogger()\n",
"logger.setLevel(logging.DEBUG)\n",
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
"import ipywidgets as widgets\n",
"from xlap.parse import evaluate, evaluate_side, parse_config\n",
"import xlap.analyse.jitter as jitter\n",
"from xlap.analyse.cdf import multi_cdf\n",
"from xlap.analyse.regress import linear as linear_regression\n",
"from xlap.analyse.trace import traces\n",
"from xlap.analyse.correlation import correlation, multi_correlation\n",
"from xlap.analyse.latency import analyse\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import copy\n",
"%matplotlib inline\n",
"colors = [\"#E69F00\", \"#009E73\", \"#56B4E9\", \"#CC79A7\", \"#D55E00\"]"
] ]
}, },
{ {
...@@ -52,18 +29,19 @@ ...@@ -52,18 +29,19 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from xlap.parse import evaluate, parse_config\n",
"config = parse_config()\n", "config = parse_config()\n",
"data_files = {\n", "data_files = {\n",
" \"sender\": \"rtn2018/20180417_testbed/\",\n", " \"sender\": \"rtn2018/20180417_testbed/\",\n",
" \"receiver\": \"rtn2018/20180417_testbed/\"\n", " \"receiver\": \"rtn2018/20180417_testbed/\"\n",
"}\n", "}\n",
"original1 = evaluate(data_files[\"sender\"] + \"sender-1000000.csv\", data_files[\"receiver\"] + \"receiver-1000000.csv\", config=config, kind=0)\n", "df_1GHz = evaluate(data_files[\"sender\"] + \"sender-1000000.csv\", data_files[\"receiver\"] + \"receiver-1000000.csv\", config=config, kind=0)\n",
"original1.name = \"1GHz\"\n", "df_1GHz.name = \"1GHz\"\n",
"original2 = evaluate(data_files[\"sender\"] + \"sender-2000000.csv\", data_files[\"receiver\"] + \"receiver-2000000.csv\", config=config, kind=0)\n", "df_2GHz = evaluate(data_files[\"sender\"] + \"sender-2000000.csv\", data_files[\"receiver\"] + \"receiver-2000000.csv\", config=config, kind=0)\n",
"original2.name = \"2GHz\"\n", "df_2GHz.name = \"2GHz\"\n",
"original3 = evaluate(data_files[\"sender\"] + \"sender-3000000.csv\", data_files[\"receiver\"] + \"receiver-3000000.csv\", config=config, kind=0)\n", "df_3GHz = evaluate(data_files[\"sender\"] + \"sender-3000000.csv\", data_files[\"receiver\"] + \"receiver-3000000.csv\", config=config, kind=0)\n",
"original3.name = \"3GHz\"\n", "df_3GHz.name = \"3GHz\"\n",
"dfs = [original1, original2, original3]" "dfs = [df_1GHz, df_2GHz, df_3GHz]"
] ]
}, },
{ {
...@@ -79,7 +57,8 @@ ...@@ -79,7 +57,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"traces(original1, config, global_xaxis=True)" "from xlap.analyse.trace import traces\n",
"traces(df_1GHz, config, global_xaxis=True)"
] ]
}, },
{ {
...@@ -95,11 +74,7 @@ ...@@ -95,11 +74,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"def multi_trace_jitter(dfs, config):\n", "from xlap.analyse.jitter import multi_trace_jitter\n",
" for df in dfs:\n",
" print(\"############################ {} ############################\".format(df.name))\n",
" jitter.trace_jitter(df, config=config, threshold=200)\n",
" \n",
"multi_trace_jitter(dfs, config)" "multi_trace_jitter(dfs, config)"
] ]
}, },
...@@ -116,14 +91,17 @@ ...@@ -116,14 +91,17 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from xlap.analyse.cdf import multi_cdf\n",
"from xlap.analyse.util import colors\n",
"import copy\n",
"cfg = copy.deepcopy(config)\n", "cfg = copy.deepcopy(config)\n",
"d = cfg[\"durations\"]\n", "list(map(cfg[\"durations\"].pop, (\"Decoding\",\n",
"\n", " \"ReceiverIPC\",\n",
"l=(\"Decoding\",\"ReceiverIPC\",\"HandlePacket\", \"Feedback\", \"SenderIPC\",\"SenderEnqueued\",\"Enqueue\")\n", " \"HandlePacket\", \n",
"for e in l:\n", " \"Feedback\", \n",
" if e in l:\n", " \"SenderIPC\",\n",
" del d[e]\n", " \"SenderEnqueued\",\n",
"\n", " \"Enqueue\")))\n",
"multi_cdf(dfs, cfg, colors=colors)" "multi_cdf(dfs, cfg, colors=colors)"
] ]
}, },
...@@ -140,6 +118,7 @@ ...@@ -140,6 +118,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from xlap.analyse.correlation import multi_correlation\n",
"multi_correlation(dfs, config, colors=colors, figsize=(3.0,2.0), cols=4)" "multi_correlation(dfs, config, colors=colors, figsize=(3.0,2.0), cols=4)"
] ]
}, },
...@@ -156,7 +135,8 @@ ...@@ -156,7 +135,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"d = analyse(original1, config)" "from xlap.analyse.latency import analyse\n",
"d = analyse(df_1GHz, config)"
] ]
}, },
{ {
...@@ -204,25 +184,8 @@ ...@@ -204,25 +184,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from scipy import stats\n", "from xlap.analyse.timing import timing_behaviour\n",
"from xlap.analyse.util import extract_durations\n", "timing_behaviour(df_1GHz, df_2GHz, config)"
"import numpy as np\n",
"\n",
"def timing_behaviour(df1, df2, config, confidence=0.9):\n",
" durations = [x + \"_D\" for x in extract_durations(config)]\n",
" \n",
" norm = lambda x: x / np.max(x)\n",
" \n",
" for duration in durations:\n",
" rvs1 = norm(df1[duration])\n",
" rvs2 = norm(df2[duration])\n",
" stat, pvalue = stats.ks_2samp(rvs1, rvs2)\n",
" result = \"CANNOT REJECT\"\n",
" if pvalue < 1 - confidence:\n",
" result = \"REJECT\"\n",
" print(duration.ljust(20), \"{:.6f}\".format(pvalue), result, sep=\"\\t\\t\")\n",
"\n",
"timing_behaviour(original1, original2, config)"
] ]
}, },
{ {
...@@ -231,7 +194,7 @@ ...@@ -231,7 +194,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"timing_behaviour(original1, original3, config)" "timing_behaviour(df_1GHz, df_3GHz, config)"
] ]
}, },
{ {
...@@ -240,7 +203,7 @@ ...@@ -240,7 +203,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"timing_behaviour(original2, original3, config)" "timing_behaviour(df_2GHz, df_3GHz, config)"
] ]
} }
], ],
......
...@@ -38,10 +38,15 @@ def trace_jitter(data_frame, config=None, threshold=None, export=False, file_nam ...@@ -38,10 +38,15 @@ def trace_jitter(data_frame, config=None, threshold=None, export=False, file_nam
if threshold is None: if threshold is None:
threshold = get_outlier_threshold(data_frame["EndToEnd_D"].describe()) threshold = get_outlier_threshold(data_frame["EndToEnd_D"].describe())
df_no_outliers = data_frame[data_frame["EndToEnd_D"] <= threshold] 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]) 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))) print("{} / {} are no outliers.".format(len(df_no_outliers), len(data_frame)))
fig.canvas.set_window_title('Jitter Analysis') fig.canvas.set_window_title('Jitter Analysis')
plt.show() plt.show()
plt.close()
return None return None
def multi_trace_jitter(dfs, config):
for df in dfs:
print("############################ {} ############################".format(df.name))
trace_jitter(df, config=config, threshold=200)
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")
...@@ -92,6 +92,6 @@ def traces(df, config, figsize=(10, 4.5), global_xaxis=False): ...@@ -92,6 +92,6 @@ def traces(df, config, figsize=(10, 4.5), global_xaxis=False):
if global_xaxis: if global_xaxis:
t_max = df["EndToEnd_D"].max() 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): def _f(seq_no):
trace(df.iloc[seq_no], config, figsize=figsize, t_max=t_max) trace(df.iloc[seq_no], config, figsize=figsize, t_max=t_max)
...@@ -2,6 +2,8 @@ import matplotlib.pyplot as plt ...@@ -2,6 +2,8 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
import math import math
colors = ["#E69F00", "#009E73", "#56B4E9", "#CC79A7", "#D55E00"]
def cdf(values, ax=None, grid=False, **kwargs): def cdf(values, ax=None, grid=False, **kwargs):
if ax is None: if ax is None:
ax = plt ax = plt
...@@ -54,7 +56,7 @@ def box(data_frame, xlim=None, export=False, file_name=None, figsize=(8, 4.5)): ...@@ -54,7 +56,7 @@ def box(data_frame, xlim=None, export=False, file_name=None, figsize=(8, 4.5)):
plt.tight_layout() plt.tight_layout()
if export and file_name is not None: if export and file_name is not None:
fig.savefig(file_name) fig.savefig(file_name)
return ax, fig
def describe_table(df): def describe_table(df):
stats = df.describe() stats = df.describe()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment