notebook.ipynb 6.34 KB
Newer Older
1
2
{
 "cells": [
3
4
  {
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
5
   "metadata": {},
6
7
8
9
10
11
   "source": [
    "# X-Lap in Action"
   ]
  },
  {
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
12
   "metadata": {},
13
14
15
16
   "source": [
    "## Imports"
   ]
  },
17
18
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
19
   "execution_count": null,
20
   "metadata": {},
21
22
   "outputs": [],
   "source": [
Andreas Schmidt's avatar
Andreas Schmidt committed
23
24
25
    "import logging\n",
    "logger = logging.getLogger()\n",
    "logger.setLevel(logging.DEBUG)\n",
26
27
    "from ipywidgets import interact, interactive, fixed, interact_manual\n",
    "import ipywidgets as widgets\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
28
    "from xlap.parse import evaluate, evaluate_side, parse_config\n",
29
    "import xlap.analyse.jitter as jitter\n",
30
    "from xlap.analyse.cdf import multi_cdf\n",
31
    "from xlap.analyse.regress import linear as linear_regression\n",
32
    "from xlap.analyse.trace import traces\n",
33
    "from xlap.analyse.correlation import correlation, multi_correlation\n",
34
    "from xlap.analyse.latency import analyse\n",
35
    "import matplotlib.pyplot as plt\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
36
    "import pandas as pd\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
37
38
39
    "import copy\n",
    "%matplotlib inline\n",
    "colors = [\"#E69F00\", \"#009E73\", \"#56B4E9\",  \"#CC79A7\", \"#D55E00\"]"
40
41
42
43
   ]
  },
  {
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
44
   "metadata": {},
45
46
   "source": [
    "## Data Retrieval"
47
48
49
50
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
51
   "execution_count": null,
52
   "metadata": {},
53
54
55
   "outputs": [],
   "source": [
    "config = parse_config()\n",
56
    "data_files = {\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
57
58
    "    \"sender\": \"rtn2018/20180417_testbed/\",\n",
    "    \"receiver\": \"rtn2018/20180417_testbed/\"\n",
59
    "}\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
60
    "original1 = evaluate(data_files[\"sender\"] + \"sender-1000000.csv\", data_files[\"receiver\"] + \"receiver-1000000.csv\", config=config, kind=0)\n",
61
    "original1.name = \"1GHz\"\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
62
    "original2 = evaluate(data_files[\"sender\"] + \"sender-2000000.csv\", data_files[\"receiver\"] + \"receiver-2000000.csv\", config=config, kind=0)\n",
63
    "original2.name = \"2GHz\"\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
64
    "original3 = evaluate(data_files[\"sender\"] + \"sender-3000000.csv\", data_files[\"receiver\"] + \"receiver-3000000.csv\", config=config, kind=0)\n",
65
    "original3.name = \"3GHz\"\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
66
    "dfs = [original1, original2, original3]"
67
68
69
   ]
  },
  {
70
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
71
   "metadata": {},
72
   "source": [
73
    "## Traces"
74
75
76
77
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
78
   "execution_count": null,
Andreas Schmidt's avatar
Andreas Schmidt committed
79
   "metadata": {},
Andreas Schmidt's avatar
Andreas Schmidt committed
80
   "outputs": [],
81
   "source": [
Andreas Schmidt's avatar
Andreas Schmidt committed
82
    "traces(original1, config, global_xaxis=True)"
83
84
85
86
   ]
  },
  {
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
87
   "metadata": {},
88
89
   "source": [
    "## Jitter Analysis"
90
91
92
93
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
94
   "execution_count": null,
Andreas Schmidt's avatar
Andreas Schmidt committed
95
   "metadata": {},
Andreas Schmidt's avatar
Andreas Schmidt committed
96
   "outputs": [],
97
   "source": [
98
99
100
    "def multi_trace_jitter(dfs, config):\n",
    "    for df in dfs:\n",
    "        print(\"############################ {} ############################\".format(df.name))\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
101
    "        jitter.trace_jitter(df, config=config, threshold=200)\n",
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    "        \n",
    "multi_trace_jitter(dfs, config)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CDFs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
Andreas Schmidt's avatar
Andreas Schmidt committed
119
120
121
122
123
124
125
126
127
    "cfg = copy.deepcopy(config)\n",
    "d = cfg[\"durations\"]\n",
    "\n",
    "l=(\"Decoding\",\"ReceiverIPC\",\"HandlePacket\", \"Feedback\", \"SenderIPC\",\"SenderEnqueued\",\"Enqueue\")\n",
    "for e in l:\n",
    "    if e in l:\n",
    "        del d[e]\n",
    "\n",
    "multi_cdf(dfs, cfg, colors=colors)"
128
129
   ]
  },
130
131
132
133
134
135
136
137
138
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Correlation"
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
139
   "execution_count": null,
Andreas Schmidt's avatar
Andreas Schmidt committed
140
   "metadata": {},
Andreas Schmidt's avatar
Andreas Schmidt committed
141
   "outputs": [],
142
   "source": [
Andreas Schmidt's avatar
Andreas Schmidt committed
143
    "multi_correlation(dfs, config, colors=colors, figsize=(3.0,2.0), cols=4)"
144
145
   ]
  },
146
147
  {
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
148
   "metadata": {},
149
150
151
152
153
154
155
   "source": [
    "## Latency Criticality"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
156
   "metadata": {},
157
158
   "outputs": [],
   "source": [
159
    "d = analyse(original1, config)"
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Correlations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "d.corr.sort_values(ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Control Flow Graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "d.cfg"
   ]
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Kolmogorov\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy import stats\n",
    "from xlap.analyse.util import extract_durations\n",
    "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)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "timing_behaviour(original1, original3, config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "timing_behaviour(original2, original3, config)"
   ]
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
Andreas Schmidt's avatar
Andreas Schmidt committed
263
   "version": "3.6.8"
264
265
266
  },
  "widgets": {
   "state": {
267
    "df95aa8c42974dfeaf8e0a2c05100645": {
268
269
270
271
272
273
274
275
     "views": [
      {
       "cell_index": 6
      }
     ]
    }
   },
   "version": "1.2.0"
276
277
278
279
280
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}