1{ 2 "cells": [ 3 { 4 "cell_type": "markdown", 5 "metadata": {}, 6 "source": [ 7 "# Test environment API - TestEnv\n", 8 "\n", 9 "The test environment is primarily defined by the target configuration (see **conf** below).\n", 10 "\n", 11 "One can also pass the test configuration - definining which software setups are needed on the hardware target, and a location for the results of the experiments.\n", 12 "\n", 13 "Parameters:\n", 14 " - target configuration\n", 15 " - test configuration - more information on this can be found in **examples/utils/executor_example.ipynb**\n", 16 " - wipe - if to clean up all previous content from the results folder\n", 17 " - force new - if to create a new TestEnv object even if there is one available" 18 ] 19 }, 20 { 21 "cell_type": "code", 22 "execution_count": 1, 23 "metadata": { 24 "collapsed": true 25 }, 26 "outputs": [], 27 "source": [ 28 "# One initial cell for imports\n", 29 "import json\n", 30 "import time\n", 31 "import os\n", 32 "import logging" 33 ] 34 }, 35 { 36 "cell_type": "code", 37 "execution_count": 2, 38 "metadata": { 39 "collapsed": false 40 }, 41 "outputs": [ 42 { 43 "name": "stderr", 44 "output_type": "stream", 45 "text": [ 46 "2016-12-12 11:51:14,376 INFO : root : Using LISA logging configuration:\n", 47 "2016-12-12 11:51:14,376 INFO : root : /home/vagrant/lisa/logging.conf\n" 48 ] 49 } 50 ], 51 "source": [ 52 "from conf import LisaLogging\n", 53 "LisaLogging.setup()\n", 54 "# For debug information use:\n", 55 "# LisaLogging.setup(level=logging.DEBUG)" 56 ] 57 }, 58 { 59 "cell_type": "markdown", 60 "metadata": {}, 61 "source": [ 62 "## Test environment setup" 63 ] 64 }, 65 { 66 "cell_type": "markdown", 67 "metadata": {}, 68 "source": [ 69 "**Target configuration**:\n", 70 "\n", 71 " - **platform** - the currently supported boards are:\n", 72 " - linux - accessed via SSH connection\n", 73 " - android - accessed via ADB connection\n", 74 " - host - ran on local host\n", 75 " \n", 76 " - **board** - the currently supported boards are:\n", 77 " - juno - target is a JUNO board\n", 78 " - tc2 - target is a TC2 board\n", 79 " - oak - target is MT8173 platform model\n", 80 " - pixel - target is a Pixel device\n", 81 " - hikey - target is a Hikey development platform\n", 82 " - nexus5x - target is a Nexus 5X device\n", 83 " \n", 84 " - **host** - target IP or MAC address\n", 85 " \n", 86 " - **device** - target Android device ID\n", 87 " \n", 88 " - **port** - port for Android connection - default port is 5555\n", 89 " \n", 90 " - **ANDROID_HOME** - path to android-sdk-linux\n", 91 " \n", 92 " - **username**\n", 93 " \n", 94 " - **password**\n", 95 " \n", 96 " - **keyfile** - you can either specify a password or a keyfile\n", 97 " \n", 98 " - **rtapp-calib** - these values are not supposed to be specified at the first run on a target.\n", 99 " After the first run, it's best to fill this array with values reported in the log messges for\n", 100 " your specific target, for these not to be obtained again.\n", 101 " \n", 102 " - **tftp** - tftp server from where the target gets kernel/dtb images at each boot\n", 103 " \n", 104 " - **modules** - devlib modules to be enabled\n", 105 " \n", 106 " - **exclude_modules** - devlib modules to be disabled\n", 107 " \n", 108 " - **tools** - binary tools (available under ./tools/$ARCH/) to install by default\n", 109 " \n", 110 " - **ping_time** - wait time before trying to access the target after reboot\n", 111 " \n", 112 " - **reboot_time** - maximum time to wait after rebooting the target\n", 113 " \n", 114 " - **__features__** - list of test environment features to enable\n", 115 " - no-kernel - do not deploy kernel/dtb images\n", 116 " - no-reboot - do not force reboot the target at each configuration change\n", 117 " - debug - enable debugging messages\n", 118 " \n", 119 " - **ftrace** - ftrace configuration\n", 120 " - events\n", 121 " - functions\n", 122 " - buffsize\n", 123 " \n", 124 " - **results_dir** - location of results of the experiments\n" 125 ] 126 }, 127 { 128 "cell_type": "code", 129 "execution_count": 3, 130 "metadata": { 131 "collapsed": false 132 }, 133 "outputs": [], 134 "source": [ 135 "# Setup a target configuration\n", 136 "conf = {\n", 137 "\n", 138 " # Platform\n", 139 " \"platform\" : \"linux\",\n", 140 " # Board\n", 141 " \"board\" : \"juno\",\n", 142 "\n", 143 " # Login credentials\n", 144 " \"host\" : \"192.168.0.1\",\n", 145 " \"username\" : \"root\",\n", 146 " # You can specify either a password or keyfile\n", 147 " \"password\" : \"juno\",\n", 148 " # \"keyfile\" : \"/complete/path/of/your/keyfile\",\n", 149 "\n", 150 " # Tools to deploy\n", 151 " \"tools\" : [ \"rt-app\", \"taskset\" ],\n", 152 "\n", 153 " \"tftp\" : {\n", 154 " \"folder\" : \"/var/lib/tftpboot/\",\n", 155 " \"kernel\" : \"Image\",\n", 156 " \"dtb\" : \"juno.dtb\"\n", 157 " },\n", 158 "\n", 159 " #\"ping_time\" : \"15\",\n", 160 " #\"reboot_time\" : \"180\",\n", 161 "\n", 162 " # RTApp calibration values (comment to let LISA do a calibration run)\n", 163 " \"rtapp-calib\" : {\n", 164 " \"0\": 358, \"1\": 138, \"2\": 138, \"3\": 357, \"4\": 359, \"5\": 355\n", 165 " },\n", 166 "\n", 167 " # FTrace configuration\n", 168 " \"ftrace\" : {\n", 169 " \"events\" : [\n", 170 " \"cpu_idle\",\n", 171 " \"sched_switch\",\n", 172 " ],\n", 173 " \"buffsize\" : 10240,\n", 174 " },\n", 175 " \n", 176 " # Where results are collected\n", 177 " \"results_dir\" : \"TestEnvExample\",\n", 178 "\n", 179 " #\"__features__\" : \"no-kernel no-reboot\"\n", 180 "}" 181 ] 182 }, 183 { 184 "cell_type": "markdown", 185 "metadata": {}, 186 "source": [ 187 "## Test environment initialisation" 188 ] 189 }, 190 { 191 "cell_type": "code", 192 "execution_count": 5, 193 "metadata": { 194 "collapsed": false, 195 "scrolled": false 196 }, 197 "outputs": [], 198 "source": [ 199 "from env import TestEnv\n", 200 "\n", 201 "# Initialize a test environment using the provided configuration\n", 202 "te = TestEnv(conf)" 203 ] 204 }, 205 { 206 "cell_type": "markdown", 207 "metadata": {}, 208 "source": [ 209 "## Attributes\n", 210 "\n", 211 "The initialisation of the test environment pre-initialises some useful environment variables.\n", 212 "\n", 213 "This is some of the information available via the TestEnv object:" 214 ] 215 }, 216 { 217 "cell_type": "code", 218 "execution_count": 6, 219 "metadata": { 220 "collapsed": false 221 }, 222 "outputs": [ 223 { 224 "name": "stdout", 225 "output_type": "stream", 226 "text": [ 227 "{\n", 228 " \"username\": \"root\", \n", 229 " \"ftrace\": {\n", 230 " \"buffsize\": 10240, \n", 231 " \"events\": [\n", 232 " \"cpu_idle\", \n", 233 " \"sched_switch\"\n", 234 " ]\n", 235 " }, \n", 236 " \"rtapp-calib\": {\n", 237 " \"1\": 138, \n", 238 " \"0\": 358, \n", 239 " \"3\": 357, \n", 240 " \"2\": 138, \n", 241 " \"5\": 355, \n", 242 " \"4\": 359\n", 243 " }, \n", 244 " \"host\": \"192.168.0.1\", \n", 245 " \"password\": \"juno\", \n", 246 " \"tools\": [\n", 247 " \"rt-app\", \n", 248 " \"taskset\", \n", 249 " \"trace-cmd\", \n", 250 " \"taskset\", \n", 251 " \"trace-cmd\", \n", 252 " \"perf\", \n", 253 " \"cgroup_run_into.sh\"\n", 254 " ], \n", 255 " \"results_dir\": \"TestEnvExample\", \n", 256 " \"platform\": \"linux\", \n", 257 " \"board\": \"juno\", \n", 258 " \"__features__\": [], \n", 259 " \"tftp\": {\n", 260 " \"kernel\": \"Image\", \n", 261 " \"folder\": \"/var/lib/tftpboot/\", \n", 262 " \"dtb\": \"juno.dtb\"\n", 263 " }\n", 264 "}\n" 265 ] 266 } 267 ], 268 "source": [ 269 "# The complete configuration of the target we have configured\n", 270 "print json.dumps(te.conf, indent=4)" 271 ] 272 }, 273 { 274 "cell_type": "code", 275 "execution_count": 7, 276 "metadata": { 277 "collapsed": false 278 }, 279 "outputs": [ 280 { 281 "name": "stdout", 282 "output_type": "stream", 283 "text": [ 284 "None\n", 285 "None\n" 286 ] 287 } 288 ], 289 "source": [ 290 "# Last configured kernel and DTB image\n", 291 "print te.kernel\n", 292 "print te.dtb" 293 ] 294 }, 295 { 296 "cell_type": "code", 297 "execution_count": 8, 298 "metadata": { 299 "collapsed": false 300 }, 301 "outputs": [ 302 { 303 "name": "stdout", 304 "output_type": "stream", 305 "text": [ 306 "192.168.0.1\n", 307 "None\n" 308 ] 309 } 310 ], 311 "source": [ 312 "# The IP and MAC address of the target\n", 313 "print te.ip\n", 314 "print te.mac" 315 ] 316 }, 317 { 318 "cell_type": "code", 319 "execution_count": 9, 320 "metadata": { 321 "collapsed": false 322 }, 323 "outputs": [ 324 { 325 "name": "stdout", 326 "output_type": "stream", 327 "text": [ 328 "{\n", 329 " \"nrg_model\": {\n", 330 " \"big\": {\n", 331 " \"cluster\": {\n", 332 " \"nrg_max\": 64\n", 333 " }, \n", 334 " \"cpu\": {\n", 335 " \"cap_max\": 1024, \n", 336 " \"nrg_max\": 616\n", 337 " }\n", 338 " }, \n", 339 " \"little\": {\n", 340 " \"cluster\": {\n", 341 " \"nrg_max\": 57\n", 342 " }, \n", 343 " \"cpu\": {\n", 344 " \"cap_max\": 447, \n", 345 " \"nrg_max\": 93\n", 346 " }\n", 347 " }\n", 348 " }, \n", 349 " \"clusters\": {\n", 350 " \"big\": [\n", 351 " 1, \n", 352 " 2\n", 353 " ], \n", 354 " \"little\": [\n", 355 " 0, \n", 356 " 3, \n", 357 " 4, \n", 358 " 5\n", 359 " ]\n", 360 " }, \n", 361 " \"cpus_count\": 6, \n", 362 " \"freqs\": {\n", 363 " \"big\": [\n", 364 " 450000, \n", 365 " 625000, \n", 366 " 800000, \n", 367 " 950000, \n", 368 " 1100000\n", 369 " ], \n", 370 " \"little\": [\n", 371 " 450000, \n", 372 " 575000, \n", 373 " 700000, \n", 374 " 775000, \n", 375 " 850000\n", 376 " ]\n", 377 " }, \n", 378 " \"topology\": [\n", 379 " [\n", 380 " 0, \n", 381 " 3, \n", 382 " 4, \n", 383 " 5\n", 384 " ], \n", 385 " [\n", 386 " 1, \n", 387 " 2\n", 388 " ]\n", 389 " ]\n", 390 "}\n" 391 ] 392 } 393 ], 394 "source": [ 395 "# A full platform descriptor\n", 396 "print json.dumps(te.platform, indent=4)" 397 ] 398 }, 399 { 400 "cell_type": "code", 401 "execution_count": 10, 402 "metadata": { 403 "collapsed": false 404 }, 405 "outputs": [ 406 { 407 "data": { 408 "text/plain": [ 409 "'/home/vagrant/lisa/results/TestEnvExample'" 410 ] 411 }, 412 "execution_count": 10, 413 "metadata": {}, 414 "output_type": "execute_result" 415 } 416 ], 417 "source": [ 418 "# This is a pre-created folder to host the tests results generated using this\n", 419 "# test environment. Notice that the suite could add additional information\n", 420 "# in this folder, like for example a copy of the target configuration\n", 421 "# and other target specific collected information.\n", 422 "te.res_dir" 423 ] 424 }, 425 { 426 "cell_type": "code", 427 "execution_count": 11, 428 "metadata": { 429 "collapsed": false 430 }, 431 "outputs": [ 432 { 433 "data": { 434 "text/plain": [ 435 "'/data/local/schedtest'" 436 ] 437 }, 438 "execution_count": 11, 439 "metadata": {}, 440 "output_type": "execute_result" 441 } 442 ], 443 "source": [ 444 "# The working directory on the target\n", 445 "te.workdir" 446 ] 447 }, 448 { 449 "cell_type": "code", 450 "execution_count": 12, 451 "metadata": { 452 "collapsed": false 453 }, 454 "outputs": [ 455 { 456 "data": { 457 "text/plain": [ 458 "cluster [[0, 3, 4, 5], [1, 2]]\n", 459 "cpu [[0], [1], [2], [3], [4], [5]]" 460 ] 461 }, 462 "execution_count": 12, 463 "metadata": {}, 464 "output_type": "execute_result" 465 } 466 ], 467 "source": [ 468 "# The target topology, which can be used to build BART assertions\n", 469 "te.topology" 470 ] 471 }, 472 { 473 "cell_type": "markdown", 474 "metadata": {}, 475 "source": [ 476 "## Functions\n", 477 "\n", 478 "Some methods are also exposed to test developers which could be used to ease the creation of tests.\n", 479 "\n", 480 "These are some of the methods available:" 481 ] 482 }, 483 { 484 "cell_type": "code", 485 "execution_count": 13, 486 "metadata": { 487 "collapsed": false, 488 "scrolled": true 489 }, 490 "outputs": [ 491 { 492 "data": { 493 "text/plain": [ 494 "{0: 358, 1: 138, 2: 138, 3: 357, 4: 359, 5: 355}" 495 ] 496 }, 497 "execution_count": 13, 498 "metadata": {}, 499 "output_type": "execute_result" 500 } 501 ], 502 "source": [ 503 "# Calibrate RT-App (if required) and get the most updated calibration value\n", 504 "te.calibration()" 505 ] 506 }, 507 { 508 "cell_type": "code", 509 "execution_count": 14, 510 "metadata": { 511 "collapsed": false 512 }, 513 "outputs": [ 514 { 515 "data": { 516 "text/plain": [ 517 "({'clusters': {'big': [1, 2], 'little': [0, 3, 4, 5]},\n", 518 " 'cpus_count': 6,\n", 519 " 'freqs': {'big': [450000, 625000, 800000, 950000, 1100000],\n", 520 " 'little': [450000, 575000, 700000, 775000, 850000]},\n", 521 " 'nrg_model': {u'big': {u'cluster': {u'nrg_max': 64},\n", 522 " u'cpu': {u'cap_max': 1024, u'nrg_max': 616}},\n", 523 " u'little': {u'cluster': {u'nrg_max': 57},\n", 524 " u'cpu': {u'cap_max': 447, u'nrg_max': 93}}},\n", 525 " 'topology': [[0, 3, 4, 5], [1, 2]]},\n", 526 " '/tmp/platform.json')" 527 ] 528 }, 529 "execution_count": 14, 530 "metadata": {}, 531 "output_type": "execute_result" 532 } 533 ], 534 "source": [ 535 "# Generate a JSON file with the complete platform description\n", 536 "te.platform_dump(dest_dir='/tmp')" 537 ] 538 }, 539 { 540 "cell_type": "code", 541 "execution_count": 15, 542 "metadata": { 543 "collapsed": false, 544 "scrolled": false 545 }, 546 "outputs": [ 547 { 548 "name": "stderr", 549 "output_type": "stream", 550 "text": [ 551 "2016-12-12 11:56:15,281 INFO : TestEnv : Target (00:02:f7:00:5d:d7) at IP address: 192.168.0.1\n", 552 "2016-12-12 11:56:16,087 INFO : TestEnv : Waiting up to 360[s] for target [192.168.0.1] to reboot...\n", 553 "2016-12-12 11:57:21,143 INFO : TestEnv : Devlib modules to load: ['bl', 'hwmon', 'cpufreq']\n", 554 "2016-12-12 11:57:21,144 INFO : TestEnv : Connecting linux target:\n", 555 "2016-12-12 11:57:21,145 INFO : TestEnv : username : root\n", 556 "2016-12-12 11:57:21,146 INFO : TestEnv : host : 192.168.0.1\n", 557 "2016-12-12 11:57:21,146 INFO : TestEnv : password : juno\n", 558 "2016-12-12 11:57:21,147 INFO : TestEnv : Connection settings:\n", 559 "2016-12-12 11:57:21,147 INFO : TestEnv : {'username': 'root', 'host': '192.168.0.1', 'password': 'juno'}\n", 560 "2016-12-12 11:57:37,176 INFO : TestEnv : Initializing target workdir:\n", 561 "2016-12-12 11:57:37,177 INFO : TestEnv : /root/devlib-target\n", 562 "2016-12-12 11:57:43,908 INFO : TestEnv : Topology:\n", 563 "2016-12-12 11:57:43,908 INFO : TestEnv : [[0, 3, 4, 5], [1, 2]]\n", 564 "2016-12-12 11:57:45,155 INFO : TestEnv : Loading default EM:\n", 565 "2016-12-12 11:57:45,156 INFO : TestEnv : /home/vagrant/lisa/libs/utils/platforms/juno.json\n", 566 "2016-12-12 11:57:48,681 INFO : TestEnv : Enabled tracepoints:\n", 567 "2016-12-12 11:57:48,684 INFO : TestEnv : cpu_idle\n", 568 "2016-12-12 11:57:48,685 INFO : TestEnv : sched_switch\n", 569 "2016-12-12 11:57:48,688 INFO : EnergyMeter : Scanning for HWMON channels, may take some time...\n", 570 "2016-12-12 11:57:48,691 INFO : EnergyMeter : Channels selected for energy sampling:\n", 571 "2016-12-12 11:57:48,691 INFO : EnergyMeter : BOARDBIG_energy\n", 572 "2016-12-12 11:57:48,692 INFO : EnergyMeter : BOARDLITTLE_energy\n" 573 ] 574 } 575 ], 576 "source": [ 577 "# Force a reboot of the target (and wait specified [s] before reconnect)\n", 578 "# Keep in mind that a reboot can be disabled from __features__ in the target configuration\n", 579 "te.reboot(reboot_time=360, ping_time=15)" 580 ] 581 }, 582 { 583 "cell_type": "code", 584 "execution_count": 18, 585 "metadata": { 586 "collapsed": false 587 }, 588 "outputs": [ 589 { 590 "name": "stderr", 591 "output_type": "stream", 592 "text": [ 593 "06:03:00 INFO : HostResolver - Target (00:02:F7:00:5A:5B) at IP address: 192.168.0.1\n" 594 ] 595 }, 596 { 597 "data": { 598 "text/plain": [ 599 "('00:02:F7:00:5A:5B', '192.168.0.1')" 600 ] 601 }, 602 "execution_count": 15, 603 "metadata": {}, 604 "output_type": "execute_result" 605 } 606 ], 607 "source": [ 608 "# Resolve a MAC address into an IP address\n", 609 "te.resolv_host(host='00:02:F7:00:5A:5B')" 610 ] 611 }, 612 { 613 "cell_type": "code", 614 "execution_count": 16, 615 "metadata": { 616 "collapsed": false 617 }, 618 "outputs": [ 619 { 620 "name": "stderr", 621 "output_type": "stream", 622 "text": [ 623 "06:03:00 INFO : TFTP - Deploy /etc/group into /var/lib/tftpboot/group\n" 624 ] 625 } 626 ], 627 "source": [ 628 "# Copy the specified file into the TFTP server folder defined by configuration\n", 629 "te.tftp_deploy('/etc/group')" 630 ] 631 }, 632 { 633 "cell_type": "markdown", 634 "metadata": {}, 635 "source": [ 636 "\n", 637 "## Attributes: target\n", 638 "### Access to the devlib API\n", 639 "\n", 640 "A special attribute of TestEnv is **target**, which represents a devlib instance. Using the target attribute we have access to the full set of devlib provided functionalities. A small set of these are exemplified below. For a more extensive set check the **examples/devlib** notebooks." 641 ] 642 }, 643 { 644 "cell_type": "code", 645 "execution_count": 16, 646 "metadata": { 647 "collapsed": false 648 }, 649 "outputs": [ 650 { 651 "data": { 652 "text/plain": [ 653 "'Hello Test Environment'" 654 ] 655 }, 656 "execution_count": 16, 657 "metadata": {}, 658 "output_type": "execute_result" 659 } 660 ], 661 "source": [ 662 "# Run a command on the target\n", 663 "te.target.execute(\"echo -n 'Hello Test Environment'\", as_root=False)" 664 ] 665 }, 666 { 667 "cell_type": "code", 668 "execution_count": 17, 669 "metadata": { 670 "collapsed": false 671 }, 672 "outputs": [ 673 { 674 "data": { 675 "text/plain": [ 676 "''" 677 ] 678 }, 679 "execution_count": 17, 680 "metadata": {}, 681 "output_type": "execute_result" 682 } 683 ], 684 "source": [ 685 "# Spawn a command in background on the target\n", 686 "te.target.kick_off(\"sleep 10\", as_root=True)" 687 ] 688 }, 689 { 690 "cell_type": "code", 691 "execution_count": 18, 692 "metadata": { 693 "collapsed": false 694 }, 695 "outputs": [ 696 { 697 "name": "stdout", 698 "output_type": "stream", 699 "text": [ 700 "ABI : arm64\n", 701 "big Core Family : A57\n", 702 "LITTLE Core Family : A53\n", 703 "CPU's Clusters IDs : [0, 1, 1, 0, 0, 0]\n", 704 "CPUs type : ['A53', 'A57', 'A57', 'A53', 'A53', 'A53']\n" 705 ] 706 } 707 ], 708 "source": [ 709 "# Acces to many target specific information\n", 710 "print \"ABI : \", te.target.abi\n", 711 "print \"big Core Family : \", te.target.big_core\n", 712 "print \"LITTLE Core Family : \", te.target.little_core\n", 713 "print \"CPU's Clusters IDs : \", te.target.core_clusters\n", 714 "print \"CPUs type : \", te.target.core_names" 715 ] 716 }, 717 { 718 "cell_type": "code", 719 "execution_count": 19, 720 "metadata": { 721 "collapsed": false 722 }, 723 "outputs": [ 724 { 725 "name": "stdout", 726 "output_type": "stream", 727 "text": [ 728 "big CPUs IDs : [1, 2]\n", 729 "LITTLE CPUs IDs : [0, 3, 4, 5]\n", 730 "big CPUs freqs : 450000\n", 731 "big CPUs governor : interactive\n" 732 ] 733 } 734 ], 735 "source": [ 736 "# Access to big.LITTLE specific information\n", 737 "print \"big CPUs IDs : \", te.target.bl.bigs\n", 738 "print \"LITTLE CPUs IDs : \", te.target.bl.littles\n", 739 "print \"big CPUs freqs : {}\".format(te.target.bl.get_bigs_frequency())\n", 740 "print \"big CPUs governor : {}\".format(te.target.bl.get_bigs_governor())" 741 ] 742 }, 743 { 744 "cell_type": "markdown", 745 "metadata": {}, 746 "source": [ 747 "## Attributes: emeter (energy meter)\n", 748 "\n", 749 "In order to sample energy from the target:" 750 ] 751 }, 752 { 753 "cell_type": "code", 754 "execution_count": 20, 755 "metadata": { 756 "collapsed": false, 757 "scrolled": false 758 }, 759 "outputs": [ 760 { 761 "name": "stdout", 762 "output_type": "stream", 763 "text": [ 764 "First read: {\n", 765 " \"BOARDBIG\": {\n", 766 " \"total\": 0.03712299999999935, \n", 767 " \"last\": 5.61159, \n", 768 " \"delta\": 0.019406000000000034\n", 769 " }, \n", 770 " \"BOARDLITTLE\": {\n", 771 " \"total\": 0.017602000000000118, \n", 772 " \"last\": 4.954883, \n", 773 " \"delta\": 0.008766999999999747\n", 774 " }\n", 775 "}\n", 776 "Second read: {\n", 777 " \"BOARDBIG\": {\n", 778 " \"total\": 0.11209199999999964, \n", 779 " \"last\": 5.686559, \n", 780 " \"delta\": 0.018203999999999887\n", 781 " }, \n", 782 " \"BOARDLITTLE\": {\n", 783 " \"total\": 0.06513600000000075, \n", 784 " \"last\": 5.002417, \n", 785 " \"delta\": 0.009789000000000492\n", 786 " }\n", 787 "}\n" 788 ] 789 } 790 ], 791 "source": [ 792 "# Reset and sample energy counters\n", 793 "te.emeter.reset()\n", 794 "nrg = te.emeter.sample()\n", 795 "nrg = json.dumps(te.emeter.sample(), indent=4)\n", 796 "print \"First read: \", nrg\n", 797 "time.sleep(2)\n", 798 "nrg = te.emeter.sample()\n", 799 "nrg = json.dumps(te.emeter.sample(), indent=4)\n", 800 "print \"Second read: \", nrg" 801 ] 802 }, 803 { 804 "cell_type": "markdown", 805 "metadata": {}, 806 "source": [ 807 "## Attribute: ftrace\n", 808 "\n", 809 "You can configure FTrace for a specific experiment using the following:" 810 ] 811 }, 812 { 813 "cell_type": "code", 814 "execution_count": 21, 815 "metadata": { 816 "collapsed": false 817 }, 818 "outputs": [ 819 { 820 "name": "stderr", 821 "output_type": "stream", 822 "text": [ 823 "2016-12-12 11:58:44,190 INFO : TestEnv : Enabled tracepoints:\n", 824 "2016-12-12 11:58:44,192 INFO : TestEnv : cpu_idle\n", 825 "2016-12-12 11:58:44,193 INFO : TestEnv : cpu_capacity\n", 826 "2016-12-12 11:58:44,194 INFO : TestEnv : cpu_frequency\n", 827 "2016-12-12 11:58:44,194 INFO : TestEnv : sched_switch\n" 828 ] 829 } 830 ], 831 "source": [ 832 "# Configure a specific set of events to trace\n", 833 "te.ftrace_conf(\n", 834 " { \n", 835 " \"events\" : [ \n", 836 " \"cpu_idle\", \n", 837 " \"cpu_capacity\",\n", 838 " \"cpu_frequency\",\n", 839 " \"sched_switch\",\n", 840 " ], \n", 841 " \"buffsize\" : 10240 \n", 842 " }\n", 843 ")" 844 ] 845 }, 846 { 847 "cell_type": "code", 848 "execution_count": 22, 849 "metadata": { 850 "collapsed": false 851 }, 852 "outputs": [], 853 "source": [ 854 "# Start/Stop a FTrace session\n", 855 "te.ftrace.start()\n", 856 "te.target.execute(\"uname -a\")\n", 857 "te.ftrace.stop()" 858 ] 859 }, 860 { 861 "cell_type": "code", 862 "execution_count": 23, 863 "metadata": { 864 "collapsed": false 865 }, 866 "outputs": [], 867 "source": [ 868 "# Collect and visualize the trace\n", 869 "trace_file = os.path.join(te.res_dir, 'trace.dat')\n", 870 "te.ftrace.get_trace(trace_file)\n", 871 "\n", 872 "# There might be a different display value on your machine\n", 873 "# Check by issuing \"echo $DISPLAY\" in the LISA VM\n", 874 "output = os.popen(\"DISPLAY=:10.0 kernelshark {}\".format(trace_file))" 875 ] 876 } 877 ], 878 "metadata": { 879 "kernelspec": { 880 "display_name": "Python 2", 881 "language": "python", 882 "name": "python2" 883 }, 884 "language_info": { 885 "codemirror_mode": { 886 "name": "ipython", 887 "version": 2 888 }, 889 "file_extension": ".py", 890 "mimetype": "text/x-python", 891 "name": "python", 892 "nbconvert_exporter": "python", 893 "pygments_lexer": "ipython2", 894 "version": "2.7.6" 895 } 896 }, 897 "nbformat": 4, 898 "nbformat_minor": 0 899} 900