• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{
2 "cells": [
3  {
4   "cell_type": "markdown",
5   "metadata": {},
6   "source": [
7    "# Energy Meter Examples\n",
8    "\n",
9    "## BayLibre's ACME Cape and IIOCapture\n",
10    "\n",
11    "More information can be found at https://github.com/ARM-software/lisa/wiki/Energy-Meters-Requirements#iiocapture---baylibre-acme-cape."
12   ]
13  },
14  {
15   "cell_type": "code",
16   "execution_count": 1,
17   "metadata": {
18    "collapsed": false
19   },
20   "outputs": [
21    {
22     "name": "stderr",
23     "output_type": "stream",
24     "text": [
25      "2016-12-08 12:39:45,242 INFO    : root         : Using LISA logging configuration:\n",
26      "2016-12-08 12:39:45,243 INFO    : root         :   /home/vagrant/lisa/logging.conf\n"
27     ]
28    }
29   ],
30   "source": [
31    "import logging\n",
32    "from conf import LisaLogging\n",
33    "LisaLogging.setup()"
34   ]
35  },
36  {
37   "cell_type": "markdown",
38   "metadata": {},
39   "source": [
40    "#### Import required modules"
41   ]
42  },
43  {
44   "cell_type": "code",
45   "execution_count": 2,
46   "metadata": {
47    "collapsed": false
48   },
49   "outputs": [],
50   "source": [
51    "# Generate plots inline\n",
52    "%matplotlib inline\n",
53    "\n",
54    "import os\n",
55    "\n",
56    "# Support to access the remote target\n",
57    "import devlib\n",
58    "from env import TestEnv\n",
59    "\n",
60    "# RTApp configurator for generation of PERIODIC tasks\n",
61    "from wlgen import RTA, Ramp"
62   ]
63  },
64  {
65   "cell_type": "markdown",
66   "metadata": {},
67   "source": [
68    "## Target Configuration\n",
69    "The target configuration is used to describe and configure your test environment.\n",
70    "You can find more details in **examples/utils/testenv_example.ipynb**."
71   ]
72  },
73  {
74   "cell_type": "code",
75   "execution_count": 3,
76   "metadata": {
77    "collapsed": false
78   },
79   "outputs": [],
80   "source": [
81    "# Setup target configuration\n",
82    "my_conf = {\n",
83    "\n",
84    "    # Target platform and board\n",
85    "    \"platform\"    : 'linux',\n",
86    "    \"board\"       : 'juno',\n",
87    "    \"host\"        : '192.168.0.1',\n",
88    "\n",
89    "    # Folder where all the results will be collected\n",
90    "    \"results_dir\" : \"EnergyMeter_IIOCapture\",\n",
91    "\n",
92    "    # Define devlib modules to load\n",
93    "    \"modules\" : [\"cpufreq\"], # Required by rt-app calibration\n",
94    "    \"exclude_modules\" : [ 'hwmon' ],\n",
95    "\n",
96    "    # Energy Meters Configuration for BayLibre's ACME Cape\n",
97    "    \"emeter\" : {\n",
98    "        \"instrument\" : \"acme\",\n",
99    "        \"conf\" : {\n",
100    "            #'iio-capture' : '/usr/bin/iio-capture',\n",
101    "            #'ip_address' : 'baylibre-acme.local',\n",
102    "        },\n",
103    "        'channel_map' : {\n",
104    "            'Device0' : 0,\n",
105    "            'Device1' : 1,\n",
106    "        }\n",
107    "    },\n",
108    "    \n",
109    "    # Tools required by the experiments\n",
110    "    \"tools\"   : [ 'trace-cmd', 'rt-app' ],\n",
111    "    \n",
112    "    # Comment this line to calibrate RTApp in your own platform\n",
113    "    # \"rtapp-calib\" :  {\"0\": 360, \"1\": 142, \"2\": 138, \"3\": 352, \"4\": 352, \"5\": 353},\n",
114    "}"
115   ]
116  },
117  {
118   "cell_type": "code",
119   "execution_count": 4,
120   "metadata": {
121    "collapsed": false,
122    "scrolled": false
123   },
124   "outputs": [
125    {
126     "name": "stderr",
127     "output_type": "stream",
128     "text": [
129      "06:32:20  INFO    :         Target - Using base path: /home/derkling/Code/lisa\n",
130      "06:32:20  INFO    :         Target - Loading custom (inline) target configuration\n",
131      "06:32:20  INFO    :         Target - Devlib modules to load: ['bl', 'cpufreq']\n",
132      "06:32:20  INFO    :         Target - Connecting linux target:\n",
133      "06:32:20  INFO    :         Target -   username : root\n",
134      "06:32:20  INFO    :         Target -       host : 192.168.0.1\n",
135      "06:32:20  INFO    :         Target -   password : \n",
136      "06:32:20  INFO    :         Target - Connection settings:\n",
137      "06:32:20  INFO    :         Target -    {'username': 'root', 'host': '192.168.0.1', 'password': ''}\n",
138      "06:32:24  INFO    :         Target - Initializing target workdir:\n",
139      "06:32:24  INFO    :         Target -    /root/devlib-target\n",
140      "06:32:31  INFO    :         Target - Topology:\n",
141      "06:32:31  INFO    :         Target -    [[0, 3, 4, 5], [1, 2]]\n",
142      "06:32:33  INFO    :       Platform - Loading default EM:\n",
143      "06:32:33  INFO    :       Platform -    /home/derkling/Code/lisa/libs/utils/platforms/juno.json\n",
144      "06:32:33  WARNING :         Target - Using configuration provided RTApp calibration\n",
145      "06:32:33  INFO    :         Target - Using RT-App calibration values:\n",
146      "06:32:33  INFO    :         Target -    {\"0\": 360, \"1\": 142, \"2\": 138, \"3\": 352, \"4\": 352, \"5\": 353}\n",
147      "06:32:33  INFO    :           ACME - ACME configuration:\n",
148      "06:32:33  INFO    :           ACME -     binary: iio-capture\n",
149      "06:32:33  INFO    :           ACME -     device: baylibre-acme.local\n",
150      "06:32:33  INFO    :           ACME -   channels:\n",
151      "06:32:33  INFO    :           ACME -      Device1 (iio:device1)\n",
152      "06:32:33  INFO    :           ACME -      Device0 (iio:device0)\n",
153      "06:32:33  INFO    :        TestEnv - Set results folder to:\n",
154      "06:32:33  INFO    :        TestEnv -    /home/derkling/Code/lisa/results/EnergyMeter_IIOCapture\n",
155      "06:32:33  INFO    :        TestEnv - Experiment results available also in:\n",
156      "06:32:33  INFO    :        TestEnv -    /home/derkling/Code/lisa/results_latest\n"
157     ]
158    }
159   ],
160   "source": [
161    "# Initialize a test environment using:\n",
162    "te = TestEnv(my_conf, wipe=False, force_new=True)\n",
163    "target = te.target"
164   ]
165  },
166  {
167   "cell_type": "markdown",
168   "metadata": {},
169   "source": [
170    "## Workload Execution and Power Consumptions Samping\n",
171    "\n",
172    "Detailed information on RTApp can be found in **examples/wlgen/rtapp_example.ipynb**.\n",
173    "\n",
174    "Each **EnergyMeter** derived class has two main methods: **reset** and **report**.\n",
175    " - The **reset** method will reset the energy meter and start sampling from channels specified in the target configuration. <br>\n",
176    " - 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."
177   ]
178  },
179  {
180   "cell_type": "code",
181   "execution_count": 5,
182   "metadata": {
183    "collapsed": false
184   },
185   "outputs": [
186    {
187     "name": "stderr",
188     "output_type": "stream",
189     "text": [
190      "06:32:33  INFO    :          WlGen - Setup new workload ramp\n",
191      "06:32:33  INFO    :          RTApp - Workload duration defined by longest task\n",
192      "06:32:33  INFO    :          RTApp - Default policy: SCHED_OTHER\n",
193      "06:32:33  INFO    :          RTApp - ------------------------\n",
194      "06:32:33  INFO    :          RTApp - task [ramp], sched: using default policy\n",
195      "06:32:33  INFO    :          RTApp -  | calibration CPU: 1\n",
196      "06:32:33  INFO    :          RTApp -  | loops count: 1\n",
197      "06:32:33  INFO    :          RTApp - + phase_000001: duration 0.500000 [s] (5 loops)\n",
198      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  60 %\n",
199      "06:32:33  INFO    :          RTApp - |  run_time  60000 [us], sleep_time  40000 [us]\n",
200      "06:32:33  INFO    :          RTApp - + phase_000002: duration 0.500000 [s] (5 loops)\n",
201      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  55 %\n",
202      "06:32:33  INFO    :          RTApp - |  run_time  55000 [us], sleep_time  45000 [us]\n",
203      "06:32:33  INFO    :          RTApp - + phase_000003: duration 0.500000 [s] (5 loops)\n",
204      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  50 %\n",
205      "06:32:33  INFO    :          RTApp - |  run_time  50000 [us], sleep_time  50000 [us]\n",
206      "06:32:33  INFO    :          RTApp - + phase_000004: duration 0.500000 [s] (5 loops)\n",
207      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  45 %\n",
208      "06:32:33  INFO    :          RTApp - |  run_time  45000 [us], sleep_time  55000 [us]\n",
209      "06:32:33  INFO    :          RTApp - + phase_000005: duration 0.500000 [s] (5 loops)\n",
210      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  40 %\n",
211      "06:32:33  INFO    :          RTApp - |  run_time  40000 [us], sleep_time  60000 [us]\n",
212      "06:32:33  INFO    :          RTApp - + phase_000006: duration 0.500000 [s] (5 loops)\n",
213      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  35 %\n",
214      "06:32:33  INFO    :          RTApp - |  run_time  35000 [us], sleep_time  65000 [us]\n",
215      "06:32:33  INFO    :          RTApp - + phase_000007: duration 0.500000 [s] (5 loops)\n",
216      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  30 %\n",
217      "06:32:33  INFO    :          RTApp - |  run_time  30000 [us], sleep_time  70000 [us]\n",
218      "06:32:33  INFO    :          RTApp - + phase_000008: duration 0.500000 [s] (5 loops)\n",
219      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  25 %\n",
220      "06:32:33  INFO    :          RTApp - |  run_time  25000 [us], sleep_time  75000 [us]\n",
221      "06:32:33  INFO    :          RTApp - + phase_000009: duration 0.500000 [s] (5 loops)\n",
222      "06:32:33  INFO    :          RTApp - |  period   100000 [us], duty_cycle  20 %\n",
223      "06:32:33  INFO    :          RTApp - |  run_time  20000 [us], sleep_time  80000 [us]\n",
224      "06:32:34  INFO    :          WlGen - Workload execution START:\n",
225      "06:32:34  INFO    :          WlGen -    /root/devlib-target/bin/rt-app /root/devlib-target/ramp_00.json 2>&1\n",
226      "06:32:41  INFO    :           ACME - Device1 (iio:device1)\n",
227      "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",
228      "06:32:42  INFO    :           ACME - Device0 (iio:device0)\n",
229      "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"
230     ]
231    }
232   ],
233   "source": [
234    "# Create and RTApp RAMP task\n",
235    "rtapp = RTA(te.target, 'ramp', calibration=te.calibration())\n",
236    "rtapp.conf(kind='profile',\n",
237    "           params={\n",
238    "                'ramp' : Ramp(\n",
239    "                    start_pct =  60,\n",
240    "                    end_pct   =  20,\n",
241    "                    delta_pct =   5,\n",
242    "                    time_s    =   0.5).get()\n",
243    "          })\n",
244    "\n",
245    "# EnergyMeter Start\n",
246    "te.emeter.reset()\n",
247    "\n",
248    "rtapp.run(out_dir=te.res_dir)\n",
249    "\n",
250    "# EnergyMeter Stop and samples collection\n",
251    "nrg_report = te.emeter.report(te.res_dir)"
252   ]
253  },
254  {
255   "cell_type": "code",
256   "execution_count": 6,
257   "metadata": {
258    "collapsed": false
259   },
260   "outputs": [
261    {
262     "name": "stderr",
263     "output_type": "stream",
264     "text": [
265      "06:32:42  INFO    : Collected data:\n"
266     ]
267    },
268    {
269     "name": "stdout",
270     "output_type": "stream",
271     "text": [
272      "\u001b[01;34m/home/derkling/Code/lisa/results/EnergyMeter_IIOCapture\u001b[00m\r\n",
273      "├── energy.json\r\n",
274      "├── energy_stats.json\r\n",
275      "├── output.log\r\n",
276      "├── ramp_00.json\r\n",
277      "├── rt-app-ramp-0.log\r\n",
278      "├── samples_Device0.csv\r\n",
279      "└── samples_Device1.csv\r\n",
280      "\r\n",
281      "0 directories, 7 files\r\n"
282     ]
283    }
284   ],
285   "source": [
286    "logging.info(\"Collected data:\")\n",
287    "!tree $te.res_dir"
288   ]
289  },
290  {
291   "cell_type": "markdown",
292   "metadata": {},
293   "source": [
294    "## Power Measurements Data"
295   ]
296  },
297  {
298   "cell_type": "code",
299   "execution_count": 7,
300   "metadata": {
301    "collapsed": false
302   },
303   "outputs": [
304    {
305     "name": "stderr",
306     "output_type": "stream",
307     "text": [
308      "06:32:42  INFO    : Measured channels energy:\n",
309      "06:32:42  INFO    : {'Device1': '324.56', 'Device0': '220.83'}\n"
310     ]
311    }
312   ],
313   "source": [
314    "logging.info(\"Measured channels energy:\")\n",
315    "logging.info(\"%s\", nrg_report.channels)"
316   ]
317  },
318  {
319   "cell_type": "code",
320   "execution_count": 8,
321   "metadata": {
322    "collapsed": false
323   },
324   "outputs": [
325    {
326     "name": "stderr",
327     "output_type": "stream",
328     "text": [
329      "06:32:42  INFO    : Returned energy file:\n",
330      "06:32:42  INFO    :   /home/derkling/Code/lisa/results/EnergyMeter_IIOCapture/energy.json\n"
331     ]
332    },
333    {
334     "name": "stdout",
335     "output_type": "stream",
336     "text": [
337      "{\r\n",
338      "    \"Device0\": \"220.83\", \r\n",
339      "    \"Device1\": \"324.56\"\r\n",
340      "}"
341     ]
342    }
343   ],
344   "source": [
345    "logging.info(\"Returned energy file:\")\n",
346    "logging.info(\"  %s\", nrg_report.report_file)\n",
347    "!cat $nrg_report.report_file"
348   ]
349  },
350  {
351   "cell_type": "code",
352   "execution_count": 9,
353   "metadata": {
354    "collapsed": false
355   },
356   "outputs": [
357    {
358     "name": "stderr",
359     "output_type": "stream",
360     "text": [
361      "06:32:42  INFO    : Complete energy stats:\n",
362      "06:32:42  INFO    :   /home/derkling/Code/lisa/results/EnergyMeter_IIOCapture/energy_stats.json\n"
363     ]
364    },
365    {
366     "name": "stdout",
367     "output_type": "stream",
368     "text": [
369      "{\r\n",
370      "    \"Device0\": {\r\n",
371      "        \"cmax\": \"15.00\", \r\n",
372      "        \"cmin\": \"00.00\", \r\n",
373      "        \"energy\": \"220.83\", \r\n",
374      "        \"pavg\": \"32.78\", \r\n",
375      "        \"pmax\": \"100.00\", \r\n",
376      "        \"pmin\": \"00.00\", \r\n",
377      "        \"vmax\": \"4390.00\"\r\n",
378      "    }, \r\n",
379      "    \"Device1\": {\r\n",
380      "        \"cmax\": \"22.00\", \r\n",
381      "        \"cmin\": \"-1.00\", \r\n",
382      "        \"energy\": \"324.56\", \r\n",
383      "        \"pavg\": \"57.81\", \r\n",
384      "        \"pmax\": \"125.00\", \r\n",
385      "        \"pmin\": \"00.00\", \r\n",
386      "        \"vmax\": \"4390.00\"\r\n",
387      "    }\r\n",
388      "}"
389     ]
390    }
391   ],
392   "source": [
393    "stats_file = nrg_report.report_file.replace('.json', '_stats.json')\n",
394    "logging.info(\"Complete energy stats:\")\n",
395    "logging.info(\"  %s\", stats_file)\n",
396    "!cat $stats_file"
397   ]
398  },
399  {
400   "cell_type": "code",
401   "execution_count": 10,
402   "metadata": {
403    "collapsed": false
404   },
405   "outputs": [
406    {
407     "name": "stderr",
408     "output_type": "stream",
409     "text": [
410      "06:32:43  INFO    : Device0 stats (head)\n"
411     ]
412    },
413    {
414     "name": "stdout",
415     "output_type": "stream",
416     "text": [
417      "\"vshunt mV\", \"vbus mV\", \"power mW\", \"current mA\", \"timestamp ms\"\r\n",
418      "35.0, 4387.5, 25.0, 4.0, 0.0\r\n",
419      "-42.5, 4386.2, 25.0, -4.0, 10.5\r\n",
420      "50.0, 4385.0, 25.0, 3.0, 20.7\r\n",
421      "32.5, 4386.2, 0.0, 9.0, 30.8\r\n",
422      "92.5, 4387.5, 25.0, 0.0, 41.1\r\n",
423      "2.5, 4387.5, 25.0, 6.0, 51.2\r\n",
424      "17.5, 4390.0, 50.0, 2.0, 61.1\r\n",
425      "35.0, 4386.2, 25.0, 4.0, 71.2\r\n",
426      "72.5, 4388.8, 50.0, 7.0, 81.1\r\n"
427     ]
428    }
429   ],
430   "source": [
431    "logging.info(\"Device0 stats (head)\")\n",
432    "samples_file = os.path.join(te.res_dir, 'samples_Device0.csv')\n",
433    "!head $samples_file"
434   ]
435  },
436  {
437   "cell_type": "code",
438   "execution_count": 11,
439   "metadata": {
440    "collapsed": false
441   },
442   "outputs": [
443    {
444     "name": "stderr",
445     "output_type": "stream",
446     "text": [
447      "06:32:43  INFO    : Device1 stats (head)\n"
448     ]
449    },
450    {
451     "name": "stdout",
452     "output_type": "stream",
453     "text": [
454      "\"vshunt mV\", \"vbus mV\", \"power mW\", \"current mA\", \"timestamp ms\"\r\n",
455      "115.0, 4388.8, 50.0, 12.0, 0.0\r\n",
456      "75.0, 4386.2, 50.0, 18.0, 9.5\r\n",
457      "177.5, 4387.5, 50.0, 11.0, 19.8\r\n",
458      "112.5, 4388.8, 75.0, 16.0, 29.7\r\n",
459      "85.0, 4388.8, 50.0, 9.0, 39.8\r\n",
460      "182.5, 4388.8, 75.0, 18.0, 49.7\r\n",
461      "65.0, 4390.0, 50.0, 7.0, 59.8\r\n",
462      "95.0, 4388.8, 50.0, 14.0, 69.8\r\n",
463      "135.0, 4390.0, 50.0, 5.0, 79.7\r\n"
464     ]
465    }
466   ],
467   "source": [
468    "logging.info(\"Device1 stats (head)\")\n",
469    "samples_file = os.path.join(te.res_dir, 'samples_Device1.csv')\n",
470    "!head $samples_file"
471   ]
472  }
473 ],
474 "metadata": {
475  "kernelspec": {
476   "display_name": "Python 2",
477   "language": "python",
478   "name": "python2"
479  },
480  "language_info": {
481   "codemirror_mode": {
482    "name": "ipython",
483    "version": 2
484   },
485   "file_extension": ".py",
486   "mimetype": "text/x-python",
487   "name": "python",
488   "nbconvert_exporter": "python",
489   "pygments_lexer": "ipython2",
490   "version": "2.7.6"
491  },
492  "toc": {
493   "toc_cell": false,
494   "toc_number_sections": true,
495   "toc_threshold": 6,
496   "toc_window_display": false
497  }
498 },
499 "nbformat": 4,
500 "nbformat_minor": 0
501}
502