<jupyter_start><jupyter_text>Energy Meter Examples Monsoon Power Monitor*NOTE*: the **monsoon.py** tool is required to collect data from the power monitor.Instructions on how to install it can be found here:https://github.com/ARM-software/lisa/wiki/Energy-Meters-Requirementsmonsoon-power-monitor.<jupyter_code>import logging
from conf import LisaLogging
LisaLogging.setup()<jupyter_output>2017-05-10 16:00:38,824 INFO    : root         : Using LISA logging configuration:
2017-05-10 16:00:38,826 INFO    : root         :   /data/Code/lisa/logging.conf<jupyter_text>Import required modules<jupyter_code># Generate plots inline
%matplotlib inline

import os

# Support to access the remote target
import devlib
from env import TestEnv

# RTApp configurator for generation of PERIODIC tasks
from wlgen import RTA, Ramp<jupyter_output>2017-05-10 16:00:39,606 WARNING : EnergyModel  : Unusual max capacity (1023), overriding capacity_scale<jupyter_text>Target ConfigurationThe target configuration is used to describe and configure your test environment.You can find more details in **examples/utils/testenv_example.ipynb**.<jupyter_code># Let's assume the monsoon binary is installed in the following path
MONSOON_BIN = os.path.join(os.getenv('LISA_HOME'), 'tools', 'scripts', 'monsoon.py')
# Setup target configuration
my_conf = {

    # Target platform and board
    "platform"    : 'android',
    "board"       : 'wahoo',
    
    # Android tools
    "ANDROID_HOME" : "/home/derkling/Code/lisa/tools/android-sdk-linux",
    
    # Folder where all the results will be collected
    "results_dir" : "EnergyMeter_Monsoon",

    # Define devlib modules to load
    "exclude_modules" : [ 'hwmon' ],

    # Energy Meters Configuration for ARM Energy Probe
    "emeter" : {
        "instrument" : "monsoon",
        "conf" : {
            'monsoon_bin' : MONSOON_BIN,
        },
    },
    
    # Tools required by the experiments
    "tools"   : [ 'trace-cmd', 'rt-app' ],
    
    # Comment this line to calibrate RTApp in your own platform
    "rtapp-calib" :  {"0": 360, "1": 142, "2": 138, "3": 352, "4": 352, "5": 353},
}
# Once powered the Monsoon Power Monitor does not enable the output voltage.
# Since the devlib's API expects that the device is powered and available for
# an ADB connection, let's manually power on the device before initializing the TestEnv

# Power on the device
!$MONSOON_BIN --device /dev/ttyACM1 --voltage 4.2

# Enable USB passthrough to be able to connect the device
!$MONSOON_BIN --usbpassthrough on
# Initialize a test environment using:
te = TestEnv(my_conf, wipe=False, force_new=True)
target = te.target
# If your device support charge via USB, let's disable it in order
# to read the overall power consumption from the main output channel

# For example, this is the API for a Pixel phone:
te.target.write_value('/sys/class/power_supply/battery/charging_enabled', 0)<jupyter_output><empty_output><jupyter_text>Workload Execution and Power Consumptions SampingDetailed information on RTApp can be found in **examples/wlgen/rtapp_example.ipynb**.Each **EnergyMeter** derived class has two main methods: **reset** and **report**. - The **reset** method will reset the energy meter and start sampling from channels specified in the target configuration.  - 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.<jupyter_code># Create and RTApp RAMP task
rtapp = RTA(te.target, 'ramp', calibration=te.calibration())
rtapp.conf(kind='profile',
           params={
                'ramp' : Ramp(
                    start_pct =  60,
                    end_pct   =  20,
                    delta_pct =   5,
                    time_s    =   0.5).get()
          })

# EnergyMeter Start
te.emeter.reset()

rtapp.run(out_dir=te.res_dir)

# EnergyMeter Stop and samples collection
nrg_report = te.emeter.report(te.res_dir)
logging.info("Collected data:")
!tree $te.res_dir<jupyter_output>2017-05-10 16:01:07,581 INFO    : root         : Collected data:<jupyter_text>Power Measurements Data<jupyter_code>logging.info("Measured channels energy:")
logging.info("%s", nrg_report.channels)
logging.info("Generated energy file:")
logging.info("  %s", nrg_report.report_file)
!cat $nrg_report.report_file
logging.info("Samples collected for the Output and Battery channels (only first 10)")
samples_file = os.path.join(te.res_dir, 'samples.csv')
!head $samples_file
logging.info("DataFrame of collected samples (only first 5)")
nrg_report.data_frame.head()
logging.info("Plot of collected power samples")
axes = nrg_report.data_frame[('output', 'power')].plot(
                    figsize=(16,8), drawstyle='steps-post');
axes.set_title('Power samples');
axes.set_xlabel('Time [s]');
axes.set_ylabel('Output power [W]');
logging.info("Plot of collected power samples")
nrg_report.data_frame.describe(percentiles=[0.90, 0.95, 0.99]).T
logging.info("Power distribution")
axes = nrg_report.data_frame[('output', 'power')].plot(
                    kind='hist', bins=32,
                    figsize=(16,8));
axes.set_title('Power Histogram');
axes.set_xlabel('Output power [W] buckets');
axes.set_ylabel('Samples per bucket');<jupyter_output>2017-05-10 16:01:19,645 INFO    : root         : Power distribution
{'fraction_non_alphanumeric': 0.10940676399926076, 'fraction_numerical': 0.026612456107928294, 'mean_word_length': 3.9651376146788992, 'pattern_counts': {'":': 6, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '14687', 'license': 'Apache-2.0', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1650, 'n_words': 511, 'path': 'ipynb/examples/energy_meter/EnergyMeter_Monsoon.ipynb', 'repo_name': 'ADVAN-ELAA-8QM-PRC1/platform-external-lisa', 'size': '5411'}