Created
May 6, 2017 14:55
-
-
Save bjackman/dae4b6a264ca46f74989a257dfd27bf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from trace import Trace" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import json" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import os" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Parse trace" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"d = \"{}/ipynb/tutorial/example_results/\".format(os.getenv('LISA_HOME'))\n", | |
"with open(\"{}/platform.json\".format(d)) as f:\n", | |
" platform = json.load(f)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"trace = Trace(platform, '{}/trace.dat'.format(d), ['sched_switch', 'sched_wakeup'])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Get DataFrame with `sched_switch` & `sched_wakeup`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"switch_in = trace.data_frame.trace_event('sched_switch')[['next_pid']]\n", | |
"wake = trace.data_frame.trace_event('sched_wakeup')[['pid']]\n", | |
"df = wake.join(switch_in, how='outer')\n", | |
"df = df.rename(columns={'next_pid': 'switch_in_pid', 'pid': 'wake_pid'})" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Find wakeup latencies" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"wakeup_times = {}\n", | |
"lats = []\n", | |
"def f(row):\n", | |
" time = row.name\n", | |
" if not np.isnan(row.wake_pid):\n", | |
" wakeup_times[row.wake_pid] = time\n", | |
" lats.append(None)\n", | |
" else:\n", | |
" if row.switch_in_pid in wakeup_times:\n", | |
" lats.append(time - wakeup_times[row.switch_in_pid])\n", | |
" else:\n", | |
" lats.append(None)\n", | |
"df.apply(f, axis=1)\n", | |
"ldf = pd.DataFrame({'latency': lats, 'pid': df.switch_in_pid}).dropna()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment