notebook.ipynb 6.89 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
37
    "import pandas as pd\n",
    "%matplotlib inline"
38
39
40
41
   ]
  },
  {
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
42
   "metadata": {},
43
44
   "source": [
    "## Data Retrieval"
45
46
47
48
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
49
   "execution_count": null,
50
   "metadata": {},
51
52
53
   "outputs": [],
   "source": [
    "config = parse_config()\n",
54
    "data_files = {\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
55
56
    "    \"sender\": \"~/Work/Publications/rtn-2018/eval/20180420_base1/\",\n",
    "    \"receiver\": \"~/Work/Publications/rtn-2018/eval/20180420_base1/\"\n",
57
    "}\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
58
59
    "x= 4050\n",
    "original1 = evaluate(data_files[\"sender\"] + \"sender-1000000.csv\", data_files[\"receiver\"] + \"receiver-1000000.csv\", config=config, kind=0).iloc[0:x]\n",
60
    "original1.name = \"1GHz\"\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
61
    "original2 = evaluate(data_files[\"sender\"] + \"sender-2000000.csv\", data_files[\"receiver\"] + \"receiver-2000000.csv\", config=config, kind=0).iloc[0:x]\n",
62
    "original2.name = \"2GHz\"\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
63
    "original3 = evaluate(data_files[\"sender\"] + \"sender-3000000.csv\", data_files[\"receiver\"] + \"receiver-3000000.csv\", config=config, kind=0).iloc[0:x]\n",
64
    "original3.name = \"3GHz\"\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
65
66
    "\n",
    "data_files = {\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
67
68
    "    \"sender\": \"~/Work/Publications/rtn-2018/eval/20180420_changed/\",\n",
    "    \"receiver\": \"~/Work/Publications/rtn-2018/eval/20180420_changed/\"\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
69
70
71
72
73
74
75
76
77
    "}\n",
    "original4 = evaluate(data_files[\"sender\"] + \"sender-1000000.csv\", data_files[\"receiver\"] + \"receiver-1000000.csv\", config=config, kind=0).iloc[0:x]\n",
    "original4.name = \"1GHz [2]\"\n",
    "original5 = evaluate(data_files[\"sender\"] + \"sender-2000000.csv\", data_files[\"receiver\"] + \"receiver-2000000.csv\", config=config, kind=0).iloc[0:x]\n",
    "original5.name = \"2GHz [2]\"\n",
    "original6 = evaluate(data_files[\"sender\"] + \"sender-3000000.csv\", data_files[\"receiver\"] + \"receiver-3000000.csv\", config=config, kind=0).iloc[0:x]\n",
    "original6.name = \"3GHz [2]\"\n",
    "\n",
    "dfs = [original1, original4, original2, original5, original3, original6]"
78
79
80
   ]
  },
  {
81
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
82
   "metadata": {},
83
   "source": [
84
    "## Traces"
85
86
87
88
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
89
   "execution_count": null,
Andreas Schmidt's avatar
Andreas Schmidt committed
90
   "metadata": {},
Andreas Schmidt's avatar
Andreas Schmidt committed
91
   "outputs": [],
92
   "source": [
93
    "traces(original1, config)"
94
95
96
97
   ]
  },
  {
   "cell_type": "markdown",
Andreas Schmidt's avatar
Andreas Schmidt committed
98
   "metadata": {},
99
100
   "source": [
    "## Jitter Analysis"
101
102
103
104
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
105
   "execution_count": null,
Andreas Schmidt's avatar
Andreas Schmidt committed
106
   "metadata": {},
Andreas Schmidt's avatar
Andreas Schmidt committed
107
   "outputs": [],
108
   "source": [
109
110
111
    "def multi_trace_jitter(dfs, config):\n",
    "    for df in dfs:\n",
    "        print(\"############################ {} ############################\".format(df.name))\n",
Andreas Schmidt's avatar
Andreas Schmidt committed
112
    "        jitter.trace_jitter(df, config=config, threshold=500)\n",
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
    "        \n",
    "multi_trace_jitter(dfs, config)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CDFs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "multi_cdf(dfs, config, export=True)"
131
132
   ]
  },
133
134
135
136
137
138
139
140
141
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Correlation"
   ]
  },
  {
   "cell_type": "code",
Andreas Schmidt's avatar
Andreas Schmidt committed
142
   "execution_count": null,
Andreas Schmidt's avatar
Andreas Schmidt committed
143
   "metadata": {},
Andreas Schmidt's avatar
Andreas Schmidt committed
144
   "outputs": [],
145
   "source": [
146
    "multi_correlation(dfs, config, export=True)"
147
148
   ]
  },
149
150
151
152
153
154
155
156
157
158
159
160
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Latency Criticality"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
161
   "metadata": {},
162
163
   "outputs": [],
   "source": [
164
    "d = analyse(original1, config)"
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
193
194
195
196
197
   ]
  },
  {
   "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"
   ]
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
245
246
247
248
249
  },
  {
   "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)"
   ]
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
  }
 ],
 "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",
268
   "version": "3.6.3"
269
270
271
  },
  "widgets": {
   "state": {
272
    "df95aa8c42974dfeaf8e0a2c05100645": {
273
274
275
276
277
278
279
280
     "views": [
      {
       "cell_index": 6
      }
     ]
    }
   },
   "version": "1.2.0"
281
282
283
284
285
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}