Package: pyRAPL
PyRAPLAboutpyRAPLis a software toolkit to measure the energy footprint of a host machine along the execution of a piece of Python code.pyRAPLuses the Intel "Running Average Power Limit" (RAPL) technology that estimates power consumption of a CPU.
This technology is available on Intel CPU since theSandy Bridge generation.More specifically, pyRAPL can measure the energy consumption of the following CPU domains:CPU socket packageDRAM (for server architectures)GPU (for client architectures)InstallationYou can installpyRAPLwith pip:pip install pyRAPLBasic usageHere are some basic usages ofpyRAPL. Please note that the reported energy consumption is not only the energy consumption of the code you are running. This includes theglobal energy consumptionof all the process running on the machine during this period, thus including the operating system and other applications.
That is why we recommend to eliminate any extra programs that may alter the energy consumption of the machine hosting experiments and to keeponlythe code under measurement (i.e., no extra applications, such as graphical interface, background running task...). This will give the closest measure to the real energy consumption of the measured code.Decorate a function to measure its energy consumptionTo measure the energy consumed by the machine during the execution of the functionfoo()run the following code:importpyRAPLpyRAPL.setup()@pyRAPL.measuredeffoo():# Instructions to be evaluated.foo()This will print in the console the recorded energy consumption of all the CPU domains during the execution of functionfoo.Configure the decorator specifying the device to monitorYou can easily configure which device and which socket to monitor using the parameters of thepyRAPL.setupfunction.
For example, the following example only monitors the CPU power consumption on the CPU socket1.
By default,pyRAPLmonitors all the available devices of the CPU sockets.importpyRAPLpyRAPL.setup(devices=[pyRAPL.Device.PKG],socket_ids=[1])@pyRAPL.measuredeffoo():# Instructions to be evaluated.foo()You can append the devicepyRAPL.Device.DRAMto thedevicesparameter list to monitor RAM device too.Running the test multiple timesFor short functions, you can configure the number of runs and it will calculate the mean energy consumption of all runs.
As an example, if you want to run the evaluation 100 times:importpyRAPLpyRAPL.setup()@pyRAPL.measure(number=100)deffoo():# Instructions to be evaluated.for_inrange(100):foo()Configure the output of the decoratorIf you want to handle data with different output than the standard one, you can configure the decorator with anOutputinstance from thepyRAPL.outputsmodule.As an example, if you want to write the recorded energy consumption in a .csv file:importpyRAPLpyRAPL.setup()csv_output=pyRAPL.outputs.CSVOutput('result.csv')@pyRAPL.measure(output=csv_output)deffoo():# Instructions to be evaluated.for_inrange(100):foo()csv_output.save()This will produce a csv file of 100 lines. Each line containing the energy
consumption recorded during one execution of the functionfun.
Other predefinedOutputclasses exist to export data toMongoDBandPandadataframe.
You can also create your own Output class (see thedocumentation)Measure the energy consumption of a piece of codeTo measure the energy consumed by the machine during the execution of a given
piece of code, run the following code :importpyRAPLpyRAPL.setup()meter=pyRAPL.Measurement('bar')meter.begin()# ...# Instructions to be evaluated.# ...meter.end()You can also access the result of the measurements by using the propertymeter.result, which returns aResultobject.You can also use an output to handle this results, for example with the .csv output:meter.export(csv_output)Measure the energy consumption of a blockpyRAPLallows developers to measure a block of instructions using the keywordwithas the example below:importpyRAPLpyRAPL.setup()withpyRAPL.Measurement('bar'):# ...# Instructions to be evaluated.# ...This will report the energy consumption of the block. To process the measurements instead of printing them, you can use anyOutputclass that you pass to theMeasurementobject:importpyRAPLpyRAPL.setup()report=pyRAPL.outputs.DataFrameOutput()withpyRAPL.Measurement('bar',output=report):# ...# Instructions to be evaluated.# ...report.data.head()MiscellaneousAboutpyRAPLis an open-source project developed by theSpirals research group(University of Lille and Inria) that is part of thePowerAPIinitiative.The documentation is availablehere.Mailing listYou can follow the latest news and asks questions by subscribing to ourmailing list.ContributingIf you would like to contribute code, you can do so via GitHub by forking the repository and sending a pull request.When submitting code, please make every effort to follow existing coding conventions and style in order to keep the code as readable as possible.MIT LicenseCopyright (c) 2018, INRIA
Copyright (c) 2018, University of Lille
All rights reserved.Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.