Skip to content

Instantly share code, notes, and snippets.

@bjackman
Created May 9, 2017 13:14
Show Gist options
  • Save bjackman/abbbd25dd36e00e91fa608975e632903 to your computer and use it in GitHub Desktop.
Save bjackman/abbbd25dd36e00e91fa608975e632903 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"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\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parse trace"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"lh = os.getenv('LISA_HOME')\n",
"d = \"{}/ipynb/tutorial/example_results/\".format(lh)\n",
"# with open(\"{}/platform.json\".format(d)) as f:\n",
"with open('{}/ignored/foo.json'.format(lh)) as f:\n",
" platform = json.load(f)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"trace = Trace(platform, '/home/brendan/Downloads/joel_trace/trace.html'.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": {
"collapsed": true,
"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": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"wake_pid 22.0\n",
"switch_in_pid NaN\n",
"Name: 0.587284, dtype: float64\n",
"wake_pid 22.0\n",
"switch_in_pid NaN\n",
"Name: 0.587284, dtype: float64\n",
"wake_pid 22.0\n",
"switch_in_pid NaN\n",
"Name: 0.587284, dtype: float64\n",
"wake_pid 22.0\n",
"switch_in_pid NaN\n",
"Name: 0.587284, dtype: float64\n",
"1 loop, best of 3: 9.84 s per loop\n"
]
}
],
"source": [
"wakeup_times = {}\n",
"results = []\n",
"index = []\n",
"def f(row):\n",
" time = row.name\n",
" if time == 0.58728400000000391:\n",
" print row\n",
" if not np.isnan(row.wake_pid):\n",
" wakeup_times[row.wake_pid] = time\n",
" else:\n",
" pid = row.switch_in_pid\n",
" if pid in wakeup_times:\n",
" lat = time - wakeup_times[pid]\n",
" results.append((pid, lat))\n",
" index.append(wakeup_times[pid])\n",
"\n",
"def g():\n",
" 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'})\n",
" df.apply(f, axis=1)\n",
" return pd.DataFrame(results, index=index, columns=['pid', 'wakeup_latency'])\n",
"%timeit ldf = g()"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment