{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Energy Meter Examples\n", "\n", "## BayLibre's ACME Cape and IIOCapture\n", "\n", "More information can be found at https://github.com/ARM-software/lisa/wiki/Energy-Meters-Requirements#iiocapture---baylibre-acme-cape." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2016-12-08 12:39:45,242 INFO : root : Using LISA logging configuration:\n", "2016-12-08 12:39:45,243 INFO : root : /home/vagrant/lisa/logging.conf\n" ] } ], "source": [ "import logging\n", "from conf import LisaLogging\n", "LisaLogging.setup()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Import required modules" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Generate plots inline\n", "%matplotlib inline\n", "\n", "import os\n", "\n", "# Support to access the remote target\n", "import devlib\n", "from env import TestEnv\n", "\n", "# RTApp configurator for generation of PERIODIC tasks\n", "from wlgen import RTA, Ramp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Target Configuration\n", "The target configuration is used to describe and configure your test environment.\n", "You can find more details in **examples/utils/testenv_example.ipynb**." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Setup target configuration\n", "my_conf = {\n", "\n", " # Target platform and board\n", " \"platform\" : 'linux',\n", " \"board\" : 'juno',\n", " \"host\" : '192.168.0.1',\n", "\n", " # Folder where all the results will be collected\n", " \"results_dir\" : \"EnergyMeter_IIOCapture\",\n", "\n", " # Define devlib modules to load\n", " \"modules\" : [\"cpufreq\"], # Required by rt-app calibration\n", " \"exclude_modules\" : [ 'hwmon' ],\n", "\n", " # Energy Meters Configuration for BayLibre's ACME Cape\n", " \"emeter\" : {\n", " \"instrument\" : \"acme\",\n", " \"conf\" : {\n", " #'iio-capture' : '/usr/bin/iio-capture',\n", " #'ip_address' : 'baylibre-acme.local',\n", " },\n", " 'channel_map' : {\n", " 'Device0' : 0,\n", " 'Device1' : 1,\n", " }\n", " },\n", " \n", " # Tools required by the experiments\n", " \"tools\" : [ 'trace-cmd', 'rt-app' ],\n", " \n", " # Comment this line to calibrate RTApp in your own platform\n", " # \"rtapp-calib\" : {\"0\": 360, \"1\": 142, \"2\": 138, \"3\": 352, \"4\": 352, \"5\": 353},\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:20 INFO : Target - Using base path: /home/derkling/Code/lisa\n", "06:32:20 INFO : Target - Loading custom (inline) target configuration\n", "06:32:20 INFO : Target - Devlib modules to load: ['bl', 'cpufreq']\n", "06:32:20 INFO : Target - Connecting linux target:\n", "06:32:20 INFO : Target - username : root\n", "06:32:20 INFO : Target - host : 192.168.0.1\n", "06:32:20 INFO : Target - password : \n", "06:32:20 INFO : Target - Connection settings:\n", "06:32:20 INFO : Target - {'username': 'root', 'host': '192.168.0.1', 'password': ''}\n", "06:32:24 INFO : Target - Initializing target workdir:\n", "06:32:24 INFO : Target - /root/devlib-target\n", "06:32:31 INFO : Target - Topology:\n", "06:32:31 INFO : Target - [[0, 3, 4, 5], [1, 2]]\n", "06:32:33 INFO : Platform - Loading default EM:\n", "06:32:33 INFO : Platform - /home/derkling/Code/lisa/libs/utils/platforms/juno.json\n", "06:32:33 WARNING : Target - Using configuration provided RTApp calibration\n", "06:32:33 INFO : Target - Using RT-App calibration values:\n", "06:32:33 INFO : Target - {\"0\": 360, \"1\": 142, \"2\": 138, \"3\": 352, \"4\": 352, \"5\": 353}\n", "06:32:33 INFO : ACME - ACME configuration:\n", "06:32:33 INFO : ACME - binary: iio-capture\n", "06:32:33 INFO : ACME - device: baylibre-acme.local\n", "06:32:33 INFO : ACME - channels:\n", "06:32:33 INFO : ACME - Device1 (iio:device1)\n", "06:32:33 INFO : ACME - Device0 (iio:device0)\n", "06:32:33 INFO : TestEnv - Set results folder to:\n", "06:32:33 INFO : TestEnv - /home/derkling/Code/lisa/results/EnergyMeter_IIOCapture\n", "06:32:33 INFO : TestEnv - Experiment results available also in:\n", "06:32:33 INFO : TestEnv - /home/derkling/Code/lisa/results_latest\n" ] } ], "source": [ "# Initialize a test environment using:\n", "te = TestEnv(my_conf, wipe=False, force_new=True)\n", "target = te.target" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Workload Execution and Power Consumptions Samping\n", "\n", "Detailed information on RTApp can be found in **examples/wlgen/rtapp_example.ipynb**.\n", "\n", "Each **EnergyMeter** derived class has two main methods: **reset** and **report**.\n", " - The **reset** method will reset the energy meter and start sampling from channels specified in the target configuration.
\n", " - The **report** method will stop capture and will retrieve the energy consumption data. This returns an EnergyReport composed of the measured channels energy and the report file. Each of the samples can also be obtained, as you can see below." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:33 INFO : WlGen - Setup new workload ramp\n", "06:32:33 INFO : RTApp - Workload duration defined by longest task\n", "06:32:33 INFO : RTApp - Default policy: SCHED_OTHER\n", "06:32:33 INFO : RTApp - ------------------------\n", "06:32:33 INFO : RTApp - task [ramp], sched: using default policy\n", "06:32:33 INFO : RTApp - | calibration CPU: 1\n", "06:32:33 INFO : RTApp - | loops count: 1\n", "06:32:33 INFO : RTApp - + phase_000001: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 60 %\n", "06:32:33 INFO : RTApp - | run_time 60000 [us], sleep_time 40000 [us]\n", "06:32:33 INFO : RTApp - + phase_000002: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 55 %\n", "06:32:33 INFO : RTApp - | run_time 55000 [us], sleep_time 45000 [us]\n", "06:32:33 INFO : RTApp - + phase_000003: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 50 %\n", "06:32:33 INFO : RTApp - | run_time 50000 [us], sleep_time 50000 [us]\n", "06:32:33 INFO : RTApp - + phase_000004: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 45 %\n", "06:32:33 INFO : RTApp - | run_time 45000 [us], sleep_time 55000 [us]\n", "06:32:33 INFO : RTApp - + phase_000005: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 40 %\n", "06:32:33 INFO : RTApp - | run_time 40000 [us], sleep_time 60000 [us]\n", "06:32:33 INFO : RTApp - + phase_000006: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 35 %\n", "06:32:33 INFO : RTApp - | run_time 35000 [us], sleep_time 65000 [us]\n", "06:32:33 INFO : RTApp - + phase_000007: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 30 %\n", "06:32:33 INFO : RTApp - | run_time 30000 [us], sleep_time 70000 [us]\n", "06:32:33 INFO : RTApp - + phase_000008: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 25 %\n", "06:32:33 INFO : RTApp - | run_time 25000 [us], sleep_time 75000 [us]\n", "06:32:33 INFO : RTApp - + phase_000009: duration 0.500000 [s] (5 loops)\n", "06:32:33 INFO : RTApp - | period 100000 [us], duty_cycle 20 %\n", "06:32:33 INFO : RTApp - | run_time 20000 [us], sleep_time 80000 [us]\n", "06:32:34 INFO : WlGen - Workload execution START:\n", "06:32:34 INFO : WlGen - /root/devlib-target/bin/rt-app /root/devlib-target/ramp_00.json 2>&1\n", "06:32:41 INFO : ACME - Device1 (iio:device1)\n", "06:32:41 INFO : ACME - {'cmin': '-1.00', 'energy': '324.56', 'pavg': '57.81', 'pmin': '00.00', 'vmax': '4390.00', 'cmax': '22.00', 'pmax': '125.00'}\n", "06:32:42 INFO : ACME - Device0 (iio:device0)\n", "06:32:42 INFO : ACME - {'cmin': '00.00', 'energy': '220.83', 'pavg': '32.78', 'pmin': '00.00', 'vmax': '4390.00', 'cmax': '15.00', 'pmax': '100.00'}\n" ] } ], "source": [ "# Create and RTApp RAMP task\n", "rtapp = RTA(te.target, 'ramp', calibration=te.calibration())\n", "rtapp.conf(kind='profile',\n", " params={\n", " 'ramp' : Ramp(\n", " start_pct = 60,\n", " end_pct = 20,\n", " delta_pct = 5,\n", " time_s = 0.5).get()\n", " })\n", "\n", "# EnergyMeter Start\n", "te.emeter.reset()\n", "\n", "rtapp.run(out_dir=te.res_dir)\n", "\n", "# EnergyMeter Stop and samples collection\n", "nrg_report = te.emeter.report(te.res_dir)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:42 INFO : Collected data:\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[01;34m/home/derkling/Code/lisa/results/EnergyMeter_IIOCapture\u001b[00m\r\n", "├── energy.json\r\n", "├── energy_stats.json\r\n", "├── output.log\r\n", "├── ramp_00.json\r\n", "├── rt-app-ramp-0.log\r\n", "├── samples_Device0.csv\r\n", "└── samples_Device1.csv\r\n", "\r\n", "0 directories, 7 files\r\n" ] } ], "source": [ "logging.info(\"Collected data:\")\n", "!tree $te.res_dir" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Power Measurements Data" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:42 INFO : Measured channels energy:\n", "06:32:42 INFO : {'Device1': '324.56', 'Device0': '220.83'}\n" ] } ], "source": [ "logging.info(\"Measured channels energy:\")\n", "logging.info(\"%s\", nrg_report.channels)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:42 INFO : Returned energy file:\n", "06:32:42 INFO : /home/derkling/Code/lisa/results/EnergyMeter_IIOCapture/energy.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{\r\n", " \"Device0\": \"220.83\", \r\n", " \"Device1\": \"324.56\"\r\n", "}" ] } ], "source": [ "logging.info(\"Returned energy file:\")\n", "logging.info(\" %s\", nrg_report.report_file)\n", "!cat $nrg_report.report_file" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:42 INFO : Complete energy stats:\n", "06:32:42 INFO : /home/derkling/Code/lisa/results/EnergyMeter_IIOCapture/energy_stats.json\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{\r\n", " \"Device0\": {\r\n", " \"cmax\": \"15.00\", \r\n", " \"cmin\": \"00.00\", \r\n", " \"energy\": \"220.83\", \r\n", " \"pavg\": \"32.78\", \r\n", " \"pmax\": \"100.00\", \r\n", " \"pmin\": \"00.00\", \r\n", " \"vmax\": \"4390.00\"\r\n", " }, \r\n", " \"Device1\": {\r\n", " \"cmax\": \"22.00\", \r\n", " \"cmin\": \"-1.00\", \r\n", " \"energy\": \"324.56\", \r\n", " \"pavg\": \"57.81\", \r\n", " \"pmax\": \"125.00\", \r\n", " \"pmin\": \"00.00\", \r\n", " \"vmax\": \"4390.00\"\r\n", " }\r\n", "}" ] } ], "source": [ "stats_file = nrg_report.report_file.replace('.json', '_stats.json')\n", "logging.info(\"Complete energy stats:\")\n", "logging.info(\" %s\", stats_file)\n", "!cat $stats_file" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:43 INFO : Device0 stats (head)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\"vshunt mV\", \"vbus mV\", \"power mW\", \"current mA\", \"timestamp ms\"\r\n", "35.0, 4387.5, 25.0, 4.0, 0.0\r\n", "-42.5, 4386.2, 25.0, -4.0, 10.5\r\n", "50.0, 4385.0, 25.0, 3.0, 20.7\r\n", "32.5, 4386.2, 0.0, 9.0, 30.8\r\n", "92.5, 4387.5, 25.0, 0.0, 41.1\r\n", "2.5, 4387.5, 25.0, 6.0, 51.2\r\n", "17.5, 4390.0, 50.0, 2.0, 61.1\r\n", "35.0, 4386.2, 25.0, 4.0, 71.2\r\n", "72.5, 4388.8, 50.0, 7.0, 81.1\r\n" ] } ], "source": [ "logging.info(\"Device0 stats (head)\")\n", "samples_file = os.path.join(te.res_dir, 'samples_Device0.csv')\n", "!head $samples_file" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "06:32:43 INFO : Device1 stats (head)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\"vshunt mV\", \"vbus mV\", \"power mW\", \"current mA\", \"timestamp ms\"\r\n", "115.0, 4388.8, 50.0, 12.0, 0.0\r\n", "75.0, 4386.2, 50.0, 18.0, 9.5\r\n", "177.5, 4387.5, 50.0, 11.0, 19.8\r\n", "112.5, 4388.8, 75.0, 16.0, 29.7\r\n", "85.0, 4388.8, 50.0, 9.0, 39.8\r\n", "182.5, 4388.8, 75.0, 18.0, 49.7\r\n", "65.0, 4390.0, 50.0, 7.0, 59.8\r\n", "95.0, 4388.8, 50.0, 14.0, 69.8\r\n", "135.0, 4390.0, 50.0, 5.0, 79.7\r\n" ] } ], "source": [ "logging.info(\"Device1 stats (head)\")\n", "samples_file = os.path.join(te.res_dir, 'samples_Device1.csv')\n", "!head $samples_file" ] } ], "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" }, "toc": { "toc_cell": false, "toc_number_sections": true, "toc_threshold": 6, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 0 }