Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 1 | { |
| 2 | "metadata": { |
| 3 | "kernelspec": { |
| 4 | "display_name": "Python 2", |
| 5 | "language": "python", |
| 6 | "name": "python2" |
| 7 | }, |
| 8 | "language_info": { |
| 9 | "codemirror_mode": { |
| 10 | "name": "ipython", |
| 11 | "version": 2 |
| 12 | }, |
| 13 | "file_extension": ".py", |
| 14 | "mimetype": "text/x-python", |
| 15 | "name": "python", |
| 16 | "nbconvert_exporter": "python", |
| 17 | "pygments_lexer": "ipython2", |
| 18 | "version": "2.7.6" |
| 19 | }, |
Michele Di Giorgio | 6458e4c | 2016-02-16 12:41:59 +0000 | [diff] [blame] | 20 | "name": "" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 21 | }, |
| 22 | "nbformat": 3, |
| 23 | "nbformat_minor": 0, |
| 24 | "worksheets": [ |
| 25 | { |
| 26 | "cells": [ |
| 27 | { |
| 28 | "cell_type": "heading", |
| 29 | "level": 1, |
| 30 | "metadata": {}, |
| 31 | "source": [ |
| 32 | "TRAPpy: Interactive Plotting" |
| 33 | ] |
| 34 | }, |
| 35 | { |
Javi Merino | 0645c1e | 2016-05-09 18:23:45 +0100 | [diff] [blame] | 36 | "cell_type": "markdown", |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 37 | "metadata": {}, |
| 38 | "source": [ |
Javi Merino | 0645c1e | 2016-05-09 18:23:45 +0100 | [diff] [blame] | 39 | "<span style=\"font-size: 150%\">Re Run the cells to generate the graphs</span>" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 40 | ] |
| 41 | }, |
| 42 | { |
| 43 | "cell_type": "code", |
| 44 | "collapsed": false, |
| 45 | "input": [ |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 46 | "import sys,os\n", |
| 47 | "sys.path.append(\"..\")\n", |
Javi Merino | 0a31cd2 | 2016-02-29 18:36:39 +0000 | [diff] [blame] | 48 | "import numpy.random\n", |
Javi Merino | af8ff92 | 2016-01-15 19:25:49 +0000 | [diff] [blame] | 49 | "import pandas as pd\n", |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 50 | "import shutil\n", |
Javi Merino | af8ff92 | 2016-01-15 19:25:49 +0000 | [diff] [blame] | 51 | "import tempfile\n", |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 52 | "import trappy\n", |
| 53 | "trace_thermal = \"./trace.txt\"\n", |
| 54 | "trace_sched = \"../tests/raw_trace.dat\"\n", |
| 55 | "TEMP_BASE = \"/tmp\"" |
| 56 | ], |
| 57 | "language": "python", |
| 58 | "metadata": {}, |
Javi Merino | 0a31cd2 | 2016-02-29 18:36:39 +0000 | [diff] [blame] | 59 | "outputs": [], |
Michele Di Giorgio | 2ffab14 | 2016-03-03 18:49:17 +0000 | [diff] [blame] | 60 | "prompt_number": null |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 61 | }, |
| 62 | { |
| 63 | "cell_type": "code", |
| 64 | "collapsed": true, |
| 65 | "input": [ |
| 66 | "def setup_thermal():\n", |
| 67 | " tDir = tempfile.mkdtemp(dir=\"/tmp\", prefix=\"trappy_doc\", suffix = \".tempDir\")\n", |
| 68 | " shutil.copyfile(trace_thermal, os.path.join(tDir, \"trace.txt\"))\n", |
| 69 | " return tDir\n", |
| 70 | "\n", |
| 71 | "def setup_sched():\n", |
| 72 | " tDir = tempfile.mkdtemp(dir=\"/tmp\", prefix=\"trappy_doc\", suffix = \".tempDir\")\n", |
| 73 | " shutil.copyfile(trace_sched, os.path.join(tDir, \"trace.dat\"))\n", |
| 74 | " return tDir" |
| 75 | ], |
| 76 | "language": "python", |
| 77 | "metadata": {}, |
| 78 | "outputs": [], |
Michele Di Giorgio | 2ffab14 | 2016-03-03 18:49:17 +0000 | [diff] [blame] | 79 | "prompt_number": null |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 80 | }, |
| 81 | { |
| 82 | "cell_type": "code", |
| 83 | "collapsed": true, |
| 84 | "input": [ |
| 85 | "temp_thermal_location = setup_thermal()\n", |
Javi Merino | a6c6adf | 2016-05-09 18:14:43 +0100 | [diff] [blame] | 86 | "trace1 = trappy.FTrace(temp_thermal_location)" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 87 | ], |
| 88 | "language": "python", |
| 89 | "metadata": {}, |
| 90 | "outputs": [], |
Michele Di Giorgio | 2ffab14 | 2016-03-03 18:49:17 +0000 | [diff] [blame] | 91 | "prompt_number": null |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 92 | }, |
| 93 | { |
| 94 | "cell_type": "heading", |
| 95 | "level": 1, |
| 96 | "metadata": {}, |
| 97 | "source": [ |
Michele Di Giorgio | 2ffab14 | 2016-03-03 18:49:17 +0000 | [diff] [blame] | 98 | "Interactive Line Plotting of Data Frames" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 99 | ] |
| 100 | }, |
| 101 | { |
| 102 | "cell_type": "markdown", |
| 103 | "metadata": {}, |
| 104 | "source": [ |
Michele Di Giorgio | 6458e4c | 2016-02-16 12:41:59 +0000 | [diff] [blame] | 105 | "Interactive Line Plots Supports the same API as the LinePlot but provide an interactive plot that can be zoomed by clicking and dragging on the desired area. Double clicking resets the zoom." |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 106 | ] |
| 107 | }, |
| 108 | { |
Javi Merino | af8ff92 | 2016-01-15 19:25:49 +0000 | [diff] [blame] | 109 | "cell_type": "markdown", |
| 110 | "metadata": {}, |
| 111 | "source": [ |
| 112 | "We can create an interactive plot easily from a dataframe by passing the data frame and the columns we want to plot as parameters:" |
| 113 | ] |
| 114 | }, |
| 115 | { |
| 116 | "cell_type": "code", |
| 117 | "collapsed": false, |
| 118 | "input": [ |
| 119 | "columns = [\"tick\", \"tock\"]\n", |
Javi Merino | 0a31cd2 | 2016-02-29 18:36:39 +0000 | [diff] [blame] | 120 | "df = pd.DataFrame(numpy.random.randn(1000, 2), columns=columns).cumsum()\n", |
Javi Merino | af8ff92 | 2016-01-15 19:25:49 +0000 | [diff] [blame] | 121 | "\n", |
| 122 | "trappy.ILinePlot(df, column=columns).view()" |
| 123 | ], |
| 124 | "language": "python", |
| 125 | "metadata": {}, |
| 126 | "outputs": [], |
| 127 | "prompt_number": null |
| 128 | }, |
| 129 | { |
Michele Di Giorgio | 2ffab14 | 2016-03-03 18:49:17 +0000 | [diff] [blame] | 130 | "cell_type": "heading", |
Javi Merino | 0645c1e | 2016-05-09 18:23:45 +0100 | [diff] [blame] | 131 | "level": 2, |
Michele Di Giorgio | 2ffab14 | 2016-03-03 18:49:17 +0000 | [diff] [blame] | 132 | "metadata": {}, |
| 133 | "source": [ |
| 134 | "Plotting independent series" |
| 135 | ] |
| 136 | }, |
| 137 | { |
| 138 | "cell_type": "markdown", |
| 139 | "metadata": {}, |
| 140 | "source": [ |
| 141 | "It is also possible to plot traces with different index values (i.e. x-axis values)" |
| 142 | ] |
| 143 | }, |
| 144 | { |
| 145 | "cell_type": "code", |
| 146 | "collapsed": false, |
| 147 | "input": [ |
| 148 | "columns = [\"tick\", \"tock\", \"bang\"]\n", |
| 149 | "df_len = 1000\n", |
| 150 | "df1 = pd.DataFrame(numpy.random.randn(df_len, 3), columns=columns, index=range(df_len)).cumsum()\n", |
| 151 | "df2 = pd.DataFrame(numpy.random.randn(df_len, 3), columns=columns, index=(numpy.arange(0.5, df_len, 1))).cumsum()" |
| 152 | ], |
| 153 | "language": "python", |
| 154 | "metadata": {}, |
| 155 | "outputs": [], |
| 156 | "prompt_number": null |
| 157 | }, |
| 158 | { |
| 159 | "cell_type": "code", |
| 160 | "collapsed": false, |
| 161 | "input": [ |
| 162 | "trappy.ILinePlot([df1, df2], column=\"tick\").view()" |
| 163 | ], |
| 164 | "language": "python", |
| 165 | "metadata": {}, |
| 166 | "outputs": [], |
| 167 | "prompt_number": null |
| 168 | }, |
| 169 | { |
| 170 | "cell_type": "markdown", |
| 171 | "metadata": {}, |
| 172 | "source": [ |
| 173 | "This does not affect filtering or pivoting in any way" |
| 174 | ] |
| 175 | }, |
| 176 | { |
| 177 | "cell_type": "code", |
| 178 | "collapsed": false, |
| 179 | "input": [ |
| 180 | "df1[\"bang\"] = df1[\"bang\"].apply(lambda x: numpy.random.randint(0, 4))\n", |
| 181 | "df2[\"bang\"] = df2[\"bang\"].apply(lambda x: numpy.random.randint(0, 4))" |
| 182 | ], |
| 183 | "language": "python", |
| 184 | "metadata": {}, |
| 185 | "outputs": [], |
| 186 | "prompt_number": null |
| 187 | }, |
| 188 | { |
| 189 | "cell_type": "code", |
| 190 | "collapsed": false, |
| 191 | "input": [ |
| 192 | "trappy.ILinePlot([df1, df2], column=\"tick\", filters = {'bang' : [2]}, title=\"tick column values for which bang is 2\").view()" |
| 193 | ], |
| 194 | "language": "python", |
| 195 | "metadata": { |
| 196 | "scrolled": true |
| 197 | }, |
| 198 | "outputs": [], |
| 199 | "prompt_number": null |
| 200 | }, |
| 201 | { |
| 202 | "cell_type": "code", |
| 203 | "collapsed": true, |
| 204 | "input": [ |
| 205 | "trappy.ILinePlot([df1, df2], column=\"tick\", pivot=\"bang\", title=\"tick column pivoted on bang column\").view()" |
| 206 | ], |
| 207 | "language": "python", |
| 208 | "metadata": {}, |
| 209 | "outputs": [], |
| 210 | "prompt_number": null |
| 211 | }, |
| 212 | { |
| 213 | "cell_type": "heading", |
| 214 | "level": 1, |
| 215 | "metadata": {}, |
| 216 | "source": [ |
| 217 | "Interactive Line Plotting of Traces" |
| 218 | ] |
| 219 | }, |
| 220 | { |
Javi Merino | af8ff92 | 2016-01-15 19:25:49 +0000 | [diff] [blame] | 221 | "cell_type": "markdown", |
| 222 | "metadata": {}, |
| 223 | "source": [ |
| 224 | "We can also create them from trace objects" |
| 225 | ] |
| 226 | }, |
| 227 | { |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 228 | "cell_type": "code", |
| 229 | "collapsed": false, |
| 230 | "input": [ |
Javi Merino | 1381e3a | 2016-05-09 18:28:29 +0100 | [diff] [blame] | 231 | "map_label = {\n", |
| 232 | " \"00000000,00000006\" : \"A57\",\n", |
| 233 | " \"00000000,00000039\" : \"A53\",\n", |
| 234 | "}\n", |
Kapileshwar Singh | 6787468 | 2015-12-17 11:14:22 +0000 | [diff] [blame] | 235 | "\n", |
Javi Merino | 1381e3a | 2016-05-09 18:28:29 +0100 | [diff] [blame] | 236 | "l = trappy.ILinePlot(\n", |
| 237 | " trace1, # TRAPpy FTrace Object\n", |
| 238 | " trappy.cpu_power.CpuInPower, # TRAPpy Event (maps to a unique word in the Trace)\n", |
| 239 | " column=[ # Column(s)\n", |
| 240 | " \"dynamic_power\",\n", |
| 241 | " \"load1\"],\n", |
| 242 | "\n", |
| 243 | " filters={ # Filter the data \n", |
| 244 | " \"cdev_state\": [\n", |
| 245 | " 1,\n", |
| 246 | " 0]},\n", |
| 247 | " pivot=\"cpus\", # One plot for each pivot will be created\n", |
| 248 | " map_label=map_label, # Optionally, provide an alternative label for pivots\n", |
| 249 | " per_line=1) # Number of graphs per line\n", |
| 250 | "l.view()" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 251 | ], |
| 252 | "language": "python", |
| 253 | "metadata": {}, |
Kapileshwar Singh | 6787468 | 2015-12-17 11:14:22 +0000 | [diff] [blame] | 254 | "outputs": [], |
| 255 | "prompt_number": null |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 256 | }, |
| 257 | { |
| 258 | "cell_type": "markdown", |
| 259 | "metadata": {}, |
| 260 | "source": [ |
| 261 | "You can also change the drawstyle to \"steps-post\" for step plots. These are suited if the data is discrete \n", |
| 262 | "and linear interploation is not required between two data points" |
| 263 | ] |
| 264 | }, |
| 265 | { |
| 266 | "cell_type": "code", |
| 267 | "collapsed": false, |
| 268 | "input": [ |
Javi Merino | 1381e3a | 2016-05-09 18:28:29 +0100 | [diff] [blame] | 269 | "l = trappy.ILinePlot(\n", |
| 270 | " trace1, # TRAPpy FTrace Object\n", |
| 271 | " trappy.cpu_power.CpuInPower, # TRAPpy Event (maps to a unique word in the Trace)\n", |
| 272 | " column=[ # Column(s)\n", |
| 273 | " \"dynamic_power\",\n", |
| 274 | " \"load1\"],\n", |
| 275 | "\n", |
| 276 | " filters={ # Filter the data \n", |
| 277 | " \"cdev_state\": [\n", |
| 278 | " 1,\n", |
| 279 | " 0]},\n", |
| 280 | " pivot=\"cpus\", # One plot for each pivot will be created\n", |
| 281 | "\n", |
| 282 | " per_line=1, # Number of graphs per line\n", |
| 283 | " drawstyle=\"steps-post\") \n", |
| 284 | "l.view()" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 285 | ], |
| 286 | "language": "python", |
| 287 | "metadata": {}, |
Javi Merino | ce5efc8 | 2016-07-06 19:11:15 +0100 | [diff] [blame] | 288 | "outputs": [] |
| 289 | }, |
| 290 | { |
| 291 | "cell_type": "heading", |
| 292 | "level": 2, |
| 293 | "metadata": {}, |
| 294 | "source": [ |
| 295 | "Plots for a given time range" |
| 296 | ] |
| 297 | }, |
| 298 | { |
| 299 | "cell_type": "markdown", |
| 300 | "metadata": {}, |
| 301 | "source": [ |
| 302 | "Performance can suffer if ILinePlot tries to make a huge plot. One way of fixing it is by limiting the period of time plotted using the `xlim` parameter:" |
| 303 | ] |
| 304 | }, |
| 305 | { |
| 306 | "cell_type": "code", |
| 307 | "collapsed": false, |
| 308 | "input": [ |
| 309 | "trappy.ILinePlot(\n", |
| 310 | " trace1,\n", |
Javi Merino | 2ad4f2d | 2016-07-08 14:54:17 +0100 | [diff] [blame] | 311 | " signals=[\"thermal:temp\"],\n", |
Javi Merino | ce5efc8 | 2016-07-06 19:11:15 +0100 | [diff] [blame] | 312 | " xlim=(1, 4), # Only between seconds 1 and 4\n", |
| 313 | ").view()" |
| 314 | ], |
| 315 | "language": "python", |
| 316 | "metadata": { |
| 317 | "run_control": { |
| 318 | "marked": true |
| 319 | } |
| 320 | }, |
| 321 | "outputs": [] |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 322 | }, |
| 323 | { |
| 324 | "cell_type": "heading", |
Javi Merino | d9d8278 | 2016-03-15 17:52:42 +0000 | [diff] [blame] | 325 | "level": 2, |
| 326 | "metadata": {}, |
| 327 | "source": [ |
| 328 | "Synchronized zoom in multiple plots" |
| 329 | ] |
| 330 | }, |
| 331 | { |
| 332 | "cell_type": "markdown", |
| 333 | "metadata": {}, |
| 334 | "source": [ |
Javi Merino | b071d51 | 2016-06-17 20:18:49 +0100 | [diff] [blame] | 335 | "ILinePlots can zoom all at the same time. You can do so using the `group` and `sync_zoom` parameter. All ILinePlots using the same group name zoom at the same time. Note the use of signals with colors." |
Javi Merino | d9d8278 | 2016-03-15 17:52:42 +0000 | [diff] [blame] | 336 | ] |
| 337 | }, |
| 338 | { |
| 339 | "cell_type": "code", |
| 340 | "collapsed": false, |
| 341 | "input": [ |
| 342 | "trappy.ILinePlot(\n", |
| 343 | " trace1,\n", |
Javi Merino | b071d51 | 2016-06-17 20:18:49 +0100 | [diff] [blame] | 344 | " signals=[\"cpu_in_power:dynamic_power:18,140,171\", \"cpu_in_power:load1:0xcf,0x36,0x4a\"],\n", |
Javi Merino | d9d8278 | 2016-03-15 17:52:42 +0000 | [diff] [blame] | 345 | " pivot=\"cpus\",\n", |
| 346 | " group=\"synchronized\",\n", |
| 347 | " sync_zoom=True\n", |
| 348 | ").view()" |
| 349 | ], |
| 350 | "language": "python", |
| 351 | "metadata": {}, |
Brendan Jackman | 74efec0 | 2016-11-04 14:25:39 +0000 | [diff] [blame] | 352 | "outputs": [], |
| 353 | "prompt_number": null |
| 354 | }, |
| 355 | { |
| 356 | "cell_type": "heading", |
| 357 | "level": 2, |
| 358 | "metadata": {}, |
| 359 | "source": [ |
| 360 | "Styling ILinePlots" |
| 361 | ] |
| 362 | }, |
| 363 | { |
| 364 | "cell_type": "markdown", |
| 365 | "metadata": {}, |
| 366 | "source": [ |
| 367 | "Use `fill=True` to colour-fill the space under the line. `fill_alpha` optionally sets the opacity." |
| 368 | ] |
| 369 | }, |
| 370 | { |
| 371 | "cell_type": "code", |
| 372 | "collapsed": false, |
| 373 | "input": [ |
| 374 | "trappy.ILinePlot(\n", |
| 375 | " trace1,\n", |
| 376 | " signals=[\"thermal:temp\"],\n", |
| 377 | " fill=True,\n", |
| 378 | " fill_alpha=0.5\n", |
| 379 | ").view()" |
| 380 | ], |
| 381 | "language": "python", |
| 382 | "metadata": {}, |
| 383 | "outputs": [], |
| 384 | "prompt_number": null |
Javi Merino | d9d8278 | 2016-03-15 17:52:42 +0000 | [diff] [blame] | 385 | }, |
| 386 | { |
| 387 | "cell_type": "heading", |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 388 | "level": 1, |
| 389 | "metadata": {}, |
| 390 | "source": [ |
| 391 | "EventPlot" |
| 392 | ] |
| 393 | }, |
| 394 | { |
| 395 | "cell_type": "markdown", |
| 396 | "metadata": {}, |
| 397 | "source": [ |
| 398 | "TRAPpy's Interactive Plotter features an Interactive Event TimeLine Plot. It accepts an input data of the type\n", |
| 399 | "<pre>\n", |
| 400 | "<code>\n", |
| 401 | " { \"A\" : [\n", |
| 402 | " [event_start, event_end, lane],\n", |
| 403 | " .\n", |
| 404 | " .\n", |
| 405 | " [event_start, event_end, lane],\n", |
| 406 | " ],\n", |
| 407 | " .\n", |
| 408 | " .\n", |
| 409 | " .\n", |
| 410 | "\n", |
| 411 | " \"B\" : [\n", |
| 412 | " [event_start, event_end, lane],\n", |
| 413 | " .\n", |
| 414 | " .\n", |
| 415 | " [event_start, event_end, lane],\n", |
| 416 | " .\n", |
| 417 | " .\n", |
| 418 | " .\n", |
| 419 | " }\n", |
| 420 | " \n", |
| 421 | "</code>\n", |
| 422 | "</pre>\n", |
| 423 | "\n", |
| 424 | "Hovering on the rectangles gives the name of the process element and scrolling on the Plot Area and the window in the summary controls the zoom. One can also click and drag for panning a zoomed graph.\n", |
| 425 | "\n", |
| 426 | "For Example:" |
| 427 | ] |
| 428 | }, |
| 429 | { |
| 430 | "cell_type": "code", |
| 431 | "collapsed": false, |
| 432 | "input": [ |
| 433 | "A = [\n", |
| 434 | " \n", |
| 435 | " [0, 3, 0],\n", |
| 436 | " [4, 5, 2],\n", |
| 437 | "]\n", |
| 438 | "\n", |
| 439 | "B = [\n", |
| 440 | " [0, 2, 1],\n", |
| 441 | " [2, 3, 3],\n", |
| 442 | " [3, 4, 0],\n", |
| 443 | "]\n", |
| 444 | "\n", |
| 445 | "C = [\n", |
| 446 | " [0, 2, 3],\n", |
| 447 | " [2, 3, 2],\n", |
| 448 | " [3, 4, 1],\n", |
| 449 | "]\n", |
| 450 | "\n", |
| 451 | "EVENTS = {}\n", |
| 452 | "EVENTS[\"A\"] = A\n", |
| 453 | "EVENTS[\"B\"] = B\n", |
| 454 | "EVENTS[\"C\"] = C\n", |
| 455 | "\n", |
| 456 | "trappy.EventPlot(EVENTS,\n", |
| 457 | " keys=EVENTS.keys, # Name of the Process Element\n", |
| 458 | " lane_prefix=\"LANE: \", # Name of Each TimeLine\n", |
| 459 | " num_lanes=4, # Number of Timelines\n", |
| 460 | " domain=[0,5] # Time Domain\n", |
| 461 | " ).view()" |
| 462 | ], |
| 463 | "language": "python", |
| 464 | "metadata": {}, |
Kapileshwar Singh | 6787468 | 2015-12-17 11:14:22 +0000 | [diff] [blame] | 465 | "outputs": [], |
| 466 | "prompt_number": null |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 467 | }, |
| 468 | { |
| 469 | "cell_type": "markdown", |
| 470 | "metadata": {}, |
| 471 | "source": [ |
Kapileshwar Singh | 26906d8 | 2015-10-09 11:29:39 +0100 | [diff] [blame] | 472 | "Lane names can also be specified as strings (or hashable objects that have an str representation) as follows" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 473 | ] |
| 474 | }, |
| 475 | { |
| 476 | "cell_type": "code", |
| 477 | "collapsed": false, |
| 478 | "input": [ |
Kapileshwar Singh | 26906d8 | 2015-10-09 11:29:39 +0100 | [diff] [blame] | 479 | "A = [\n", |
| 480 | " \n", |
| 481 | " [0, 3, \"zero\"],\n", |
| 482 | " [4, 5, \"two\"],\n", |
| 483 | "]\n", |
| 484 | "\n", |
| 485 | "B = [\n", |
| 486 | " [0, 2, 1],\n", |
| 487 | " [2, 3, \"three\"],\n", |
| 488 | " [3, 4, \"zero\"],\n", |
| 489 | "]\n", |
| 490 | "\n", |
| 491 | "C = [\n", |
| 492 | " [0, 2, \"three\"],\n", |
| 493 | " [2, 3, \"two\"],\n", |
| 494 | " [3, 4, 1],\n", |
| 495 | "]\n", |
| 496 | "\n", |
| 497 | "EVENTS = {}\n", |
| 498 | "EVENTS[\"A\"] = A\n", |
| 499 | "EVENTS[\"B\"] = B\n", |
| 500 | "EVENTS[\"C\"] = C\n", |
| 501 | "\n", |
| 502 | "trappy.EventPlot(EVENTS,\n", |
| 503 | " keys=EVENTS.keys, # Name of the Process Element\n", |
| 504 | " lanes=[\"zero\", 1, \"two\", \"three\"],\n", |
| 505 | " domain=[0,5] # Time Domain\n", |
| 506 | " ).view()" |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 507 | ], |
| 508 | "language": "python", |
| 509 | "metadata": {}, |
Kapileshwar Singh | 6787468 | 2015-12-17 11:14:22 +0000 | [diff] [blame] | 510 | "outputs": [], |
| 511 | "prompt_number": null |
Kapileshwar Singh | 26906d8 | 2015-10-09 11:29:39 +0100 | [diff] [blame] | 512 | }, |
| 513 | { |
Michele Di Giorgio | 303610e | 2016-07-20 19:28:39 +0100 | [diff] [blame] | 514 | "cell_type": "markdown", |
| 515 | "metadata": {}, |
| 516 | "source": [ |
| 517 | "It is also possible to define a colour map to associate a specific colour to each event. A colour string can be:\n", |
| 518 | "\n", |
| 519 | " - a colour name, `green`, `red`, `blue`, etc.\n", |
| 520 | " \n", |
| 521 | " - the HEX representation of the colour, `#0000FF` for blue, `#FF0000` for red\n", |
| 522 | " " |
| 523 | ] |
| 524 | }, |
| 525 | { |
| 526 | "cell_type": "code", |
| 527 | "collapsed": false, |
| 528 | "input": [ |
| 529 | "# Using colour names\n", |
| 530 | "trappy.EventPlot(EVENTS,\n", |
| 531 | " keys=EVENTS.keys, # Name of the Process Element\n", |
| 532 | " lanes=[\"zero\", 1, \"two\", \"three\"],\n", |
| 533 | " domain=[0,5], # Time Domain\n", |
| 534 | " color_map={\"A\" : \"blue\", \"B\" : \"red\", \"C\" : \"green\"}\n", |
| 535 | " ).view()" |
| 536 | ], |
| 537 | "language": "python", |
| 538 | "metadata": {}, |
| 539 | "outputs": [], |
| 540 | "prompt_number": null |
| 541 | }, |
| 542 | { |
| 543 | "cell_type": "code", |
| 544 | "collapsed": false, |
| 545 | "input": [ |
| 546 | "# Using HEX representation of colours\n", |
| 547 | "trappy.EventPlot(EVENTS,\n", |
| 548 | " keys=EVENTS.keys, # Name of the Process Element\n", |
| 549 | " lanes=[\"zero\", 1, \"two\", \"three\"],\n", |
| 550 | " domain=[0,5], # Time Domain\n", |
| 551 | " color_map={\"A\" : \"\t#ffa07a\", \"B\" : \"#f08080\", \"C\" : \"#add8e6\"}\n", |
| 552 | " ).view()" |
| 553 | ], |
| 554 | "language": "python", |
| 555 | "metadata": {}, |
| 556 | "outputs": [], |
| 557 | "prompt_number": null |
| 558 | }, |
| 559 | { |
Kapileshwar Singh | 26906d8 | 2015-10-09 11:29:39 +0100 | [diff] [blame] | 560 | "cell_type": "heading", |
| 561 | "level": 1, |
| 562 | "metadata": {}, |
| 563 | "source": [ |
| 564 | "TracePlot" |
| 565 | ] |
| 566 | }, |
| 567 | { |
| 568 | "cell_type": "markdown", |
| 569 | "metadata": {}, |
| 570 | "source": [ |
| 571 | "A specification of the EventPlot creates a kernelshark like plot if the sched_switch event is enabled in the traces" |
| 572 | ] |
| 573 | }, |
| 574 | { |
| 575 | "cell_type": "code", |
| 576 | "collapsed": false, |
| 577 | "input": [ |
| 578 | "f = setup_sched()\n", |
| 579 | "trappy.plotter.plot_trace(f)" |
| 580 | ], |
| 581 | "language": "python", |
| 582 | "metadata": {}, |
| 583 | "outputs": [], |
| 584 | "prompt_number": null |
Javi Merino | 9888552 | 2016-05-09 18:55:26 +0100 | [diff] [blame] | 585 | }, |
| 586 | { |
| 587 | "cell_type": "heading", |
| 588 | "level": 1, |
| 589 | "metadata": {}, |
| 590 | "source": [ |
| 591 | "Exporting notebooks with interactive plots to HTML" |
| 592 | ] |
| 593 | }, |
| 594 | { |
| 595 | "cell_type": "markdown", |
| 596 | "metadata": {}, |
| 597 | "source": [ |
| 598 | "Notebooks with ILinePlot or EventPlot can't be exported to HTML using File->Download as->HTML. They need to be converted from the command line:\n", |
| 599 | "```\n", |
| 600 | "jupyter nbconvert --to=trappy.nbexport.HTML notebook.ipynb\n", |
| 601 | "```\n", |
| 602 | "You need nbconvert >= 4.2 and trappy has to be in your `PYTHONPATH`." |
| 603 | ] |
Kapileshwar Singh | 584f88d | 2015-09-03 13:21:19 +0100 | [diff] [blame] | 604 | } |
| 605 | ], |
| 606 | "metadata": {} |
| 607 | } |
| 608 | ] |
Michele Di Giorgio | 2ffab14 | 2016-03-03 18:49:17 +0000 | [diff] [blame] | 609 | } |