• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{
2 "cells": [
3  {
4   "cell_type": "code",
5   "execution_count": 1,
6   "metadata": {
7    "collapsed": false
8   },
9   "outputs": [],
10   "source": [
11    "import trappy\n",
12    "from trappy import ftrace\n",
13    "from trappy.ftrace import GenericFTrace\n",
14    "import numpy as np\n",
15    "import pandas"
16   ]
17  },
18  {
19   "cell_type": "code",
20   "execution_count": 2,
21   "metadata": {
22    "collapsed": true
23   },
24   "outputs": [],
25   "source": [
26    "lines = [\n",
27    "\"            adbd-5709  [007]  2943.184105: sched_contrib_scale_f: cpu=7 cpu_scale_factor=1\\n\"\n",
28    "\"            adbd-5709  [007]  2943.184105: sched_load_avg_cpu:   cpu=7 util_avg=825\\n\"\n",
29    "\"     ->transport-5713  [006]  2943.184106: sched_load_avg_cpu:   cpu=6 util_avg=292\\n\"\n",
30    "\"     ->transport-5713  [006]  2943.184107: sched_contrib_scale_f: cpu=6 cpu_scale_factor=2\\n\"\n",
31    "\"            adbd-5709  [007]  2943.184108: sched_load_avg_cpu:   cpu=7 util_avg=850\\n\"\n",
32    "\"            adbd-5709  [007]  2943.184109: sched_contrib_scale_f: cpu=7 cpu_scale_factor=3\\n\"\n",
33    "\"            adbd-5709  [007]  2943.184110: sched_load_avg_cpu:   cpu=6 util_avg=315\\n\"\n",
34    "]"
35   ]
36  },
37  {
38   "cell_type": "code",
39   "execution_count": 3,
40   "metadata": {
41    "collapsed": true
42   },
43   "outputs": [],
44   "source": [
45    "with open('/tmp/trappy_mergedf_example.txt', 'w') as fh:\n",
46    "    for line in lines:\n",
47    "        fh.write(line)"
48   ]
49  },
50  {
51   "cell_type": "code",
52   "execution_count": 4,
53   "metadata": {
54    "collapsed": false
55   },
56   "outputs": [
57    {
58     "name": "stdout",
59     "output_type": "stream",
60     "text": [
61      "            adbd-5709  [007]  2943.184105: sched_contrib_scale_f: cpu=7 cpu_scale_factor=1\r\n",
62      "            adbd-5709  [007]  2943.184105: sched_load_avg_cpu:   cpu=7 util_avg=825\r\n",
63      "     ->transport-5713  [006]  2943.184106: sched_load_avg_cpu:   cpu=6 util_avg=292\r\n",
64      "     ->transport-5713  [006]  2943.184107: sched_contrib_scale_f: cpu=6 cpu_scale_factor=2\r\n",
65      "            adbd-5709  [007]  2943.184108: sched_load_avg_cpu:   cpu=7 util_avg=850\r\n",
66      "            adbd-5709  [007]  2943.184109: sched_contrib_scale_f: cpu=7 cpu_scale_factor=3\r\n",
67      "            adbd-5709  [007]  2943.184110: sched_load_avg_cpu:   cpu=6 util_avg=315\r\n"
68     ]
69    }
70   ],
71   "source": [
72    "!cat /tmp/trappy_mergedf_example.txt"
73   ]
74  },
75  {
76   "cell_type": "code",
77   "execution_count": 5,
78   "metadata": {
79    "collapsed": true
80   },
81   "outputs": [],
82   "source": [
83    "trace = ftrace.FTrace('/tmp/trappy_mergedf_example.txt', events=['sched_contrib_scale_f', 'sched_load_avg_cpu'], normalize_time=False)"
84   ]
85  },
86  {
87   "cell_type": "code",
88   "execution_count": 6,
89   "metadata": {
90    "collapsed": false
91   },
92   "outputs": [
93    {
94     "data": {
95      "text/html": [
96       "<div>\n",
97       "<table border=\"1\" class=\"dataframe\">\n",
98       "  <thead>\n",
99       "    <tr style=\"text-align: right;\">\n",
100       "      <th></th>\n",
101       "      <th>cpu</th>\n",
102       "      <th>util_avg</th>\n",
103       "      <th>__line</th>\n",
104       "    </tr>\n",
105       "    <tr>\n",
106       "      <th>Time</th>\n",
107       "      <th></th>\n",
108       "      <th></th>\n",
109       "      <th></th>\n",
110       "    </tr>\n",
111       "  </thead>\n",
112       "  <tbody>\n",
113       "    <tr>\n",
114       "      <th>2943.184105</th>\n",
115       "      <td>7</td>\n",
116       "      <td>825</td>\n",
117       "      <td>1</td>\n",
118       "    </tr>\n",
119       "    <tr>\n",
120       "      <th>2943.184106</th>\n",
121       "      <td>6</td>\n",
122       "      <td>292</td>\n",
123       "      <td>2</td>\n",
124       "    </tr>\n",
125       "    <tr>\n",
126       "      <th>2943.184108</th>\n",
127       "      <td>7</td>\n",
128       "      <td>850</td>\n",
129       "      <td>4</td>\n",
130       "    </tr>\n",
131       "    <tr>\n",
132       "      <th>2943.184110</th>\n",
133       "      <td>6</td>\n",
134       "      <td>315</td>\n",
135       "      <td>6</td>\n",
136       "    </tr>\n",
137       "  </tbody>\n",
138       "</table>\n",
139       "</div>"
140      ],
141      "text/plain": [
142       "             cpu  util_avg  __line\n",
143       "Time                              \n",
144       "2943.184105    7       825       1\n",
145       "2943.184106    6       292       2\n",
146       "2943.184108    7       850       4\n",
147       "2943.184110    6       315       6"
148      ]
149     },
150     "execution_count": 6,
151     "metadata": {},
152     "output_type": "execute_result"
153    }
154   ],
155   "source": [
156    "df1 = trace.sched_load_avg_cpu.data_frame[['cpu', 'util_avg', '__line']]\n",
157    "df1"
158   ]
159  },
160  {
161   "cell_type": "code",
162   "execution_count": 7,
163   "metadata": {
164    "collapsed": false
165   },
166   "outputs": [
167    {
168     "data": {
169      "text/html": [
170       "<div>\n",
171       "<table border=\"1\" class=\"dataframe\">\n",
172       "  <thead>\n",
173       "    <tr style=\"text-align: right;\">\n",
174       "      <th></th>\n",
175       "      <th>cpu</th>\n",
176       "      <th>cpu_scale_factor</th>\n",
177       "      <th>__line</th>\n",
178       "    </tr>\n",
179       "    <tr>\n",
180       "      <th>Time</th>\n",
181       "      <th></th>\n",
182       "      <th></th>\n",
183       "      <th></th>\n",
184       "    </tr>\n",
185       "  </thead>\n",
186       "  <tbody>\n",
187       "    <tr>\n",
188       "      <th>2943.184105</th>\n",
189       "      <td>7</td>\n",
190       "      <td>1</td>\n",
191       "      <td>0</td>\n",
192       "    </tr>\n",
193       "    <tr>\n",
194       "      <th>2943.184107</th>\n",
195       "      <td>6</td>\n",
196       "      <td>2</td>\n",
197       "      <td>3</td>\n",
198       "    </tr>\n",
199       "    <tr>\n",
200       "      <th>2943.184109</th>\n",
201       "      <td>7</td>\n",
202       "      <td>3</td>\n",
203       "      <td>5</td>\n",
204       "    </tr>\n",
205       "  </tbody>\n",
206       "</table>\n",
207       "</div>"
208      ],
209      "text/plain": [
210       "             cpu  cpu_scale_factor  __line\n",
211       "Time                                      \n",
212       "2943.184105    7                 1       0\n",
213       "2943.184107    6                 2       3\n",
214       "2943.184109    7                 3       5"
215      ]
216     },
217     "execution_count": 7,
218     "metadata": {},
219     "output_type": "execute_result"
220    }
221   ],
222   "source": [
223    "df2 = trace.sched_contrib_scale_f.data_frame[['cpu', 'cpu_scale_factor', '__line']]\n",
224    "df2"
225   ]
226  },
227  {
228   "cell_type": "code",
229   "execution_count": 8,
230   "metadata": {
231    "collapsed": false,
232    "scrolled": true
233   },
234   "outputs": [
235    {
236     "name": "stderr",
237     "output_type": "stream",
238     "text": [
239      "/home/joelaf/repo/lisa-aosp/external/trappy/trappy/utils.py:154: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)\n",
240      "  df = pd.concat([pr_df, sec_df], keys=['primary', 'secondary']).sort(columns='__line')\n"
241     ]
242    },
243    {
244     "data": {
245      "text/html": [
246       "<div>\n",
247       "<table border=\"1\" class=\"dataframe\">\n",
248       "  <thead>\n",
249       "    <tr style=\"text-align: right;\">\n",
250       "      <th></th>\n",
251       "      <th>__line</th>\n",
252       "      <th>cpu</th>\n",
253       "      <th>cpu_scale_factor</th>\n",
254       "      <th>util_avg</th>\n",
255       "    </tr>\n",
256       "    <tr>\n",
257       "      <th>Time</th>\n",
258       "      <th></th>\n",
259       "      <th></th>\n",
260       "      <th></th>\n",
261       "      <th></th>\n",
262       "    </tr>\n",
263       "  </thead>\n",
264       "  <tbody>\n",
265       "    <tr>\n",
266       "      <th>2943.184105</th>\n",
267       "      <td>1</td>\n",
268       "      <td>7</td>\n",
269       "      <td>1.0</td>\n",
270       "      <td>825.0</td>\n",
271       "    </tr>\n",
272       "    <tr>\n",
273       "      <th>2943.184106</th>\n",
274       "      <td>2</td>\n",
275       "      <td>6</td>\n",
276       "      <td>NaN</td>\n",
277       "      <td>292.0</td>\n",
278       "    </tr>\n",
279       "    <tr>\n",
280       "      <th>2943.184108</th>\n",
281       "      <td>4</td>\n",
282       "      <td>7</td>\n",
283       "      <td>1.0</td>\n",
284       "      <td>850.0</td>\n",
285       "    </tr>\n",
286       "    <tr>\n",
287       "      <th>2943.184110</th>\n",
288       "      <td>6</td>\n",
289       "      <td>6</td>\n",
290       "      <td>2.0</td>\n",
291       "      <td>315.0</td>\n",
292       "    </tr>\n",
293       "  </tbody>\n",
294       "</table>\n",
295       "</div>"
296      ],
297      "text/plain": [
298       "             __line  cpu  cpu_scale_factor  util_avg\n",
299       "Time                                                \n",
300       "2943.184105       1    7               1.0     825.0\n",
301       "2943.184106       2    6               NaN     292.0\n",
302       "2943.184108       4    7               1.0     850.0\n",
303       "2943.184110       6    6               2.0     315.0"
304      ]
305     },
306     "execution_count": 8,
307     "metadata": {},
308     "output_type": "execute_result"
309    }
310   ],
311   "source": [
312    "trappy.utils.merge_dfs(df1, df2, 'cpu')"
313   ]
314  },
315  {
316   "cell_type": "code",
317   "execution_count": null,
318   "metadata": {
319    "collapsed": true
320   },
321   "outputs": [],
322   "source": []
323  }
324 ],
325 "metadata": {
326  "gist": {
327   "data": {
328    "description": "TRAPpy_MergeDF_API_Example",
329    "public": false
330   },
331   "id": ""
332  },
333  "hide_input": false,
334  "kernelspec": {
335   "display_name": "Python 2",
336   "language": "python",
337   "name": "python2"
338  },
339  "language_info": {
340   "codemirror_mode": {
341    "name": "ipython",
342    "version": 2
343   },
344   "file_extension": ".py",
345   "mimetype": "text/x-python",
346   "name": "python",
347   "nbconvert_exporter": "python",
348   "pygments_lexer": "ipython2",
349   "version": "2.7.13"
350  },
351  "toc": {
352   "colors": {
353    "hover_highlight": "#DAA520",
354    "running_highlight": "#FF0000",
355    "selected_highlight": "#FFD700"
356   },
357   "moveMenuLeft": true,
358   "nav_menu": {
359    "height": "12px",
360    "width": "252px"
361   },
362   "navigate_menu": true,
363   "number_sections": true,
364   "sideBar": true,
365   "threshold": 4,
366   "toc_cell": false,
367   "toc_section_display": "block",
368   "toc_window_display": false
369  }
370 },
371 "nbformat": 4,
372 "nbformat_minor": 1
373}
374