Skip to main content

No project description provided

Project description

PyRAPL

License: MIT Build Status

About

pyRAPL is a software toolkit to measure the energy footprint of a host machine along the execution of a piece of Python code.

pyRAPL uses the Intel "Running Average Power Limit" (RAPL) technology that estimates power consumption of a CPU. This technology is available on Intel CPU since the Sandy Bridge generation.

More specifically, pyRAPL can measure the energy consumption of the following CPU domains:

  • CPU socket package
  • DRAM (for server architectures)
  • GPU (for client architectures)

Installation

You can install pyRAPL with pip: pip install pyRAPL

Basic usage

Here are some basic usages of pyRAPL. Please note that the reported energy consumption is not only the energy consumption of the code you are running. This includes the global energy consumption of 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 keep only the 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 consumption

To measure the energy consumed by the machine during the execution of the function foo() run the following code:

	import pyRAPL

	pyRAPL.setup() 

	@pyRAPL.measure
	def foo():
		# Instructions to be evaluated.

	foo()

This will print in the console the recorded energy consumption of all the CPU domains during the execution of function foo.

Configure the decorator specifying the device to monitor

You can easily configure which device and which socket to monitor using the parameters of the pyRAPL.setup function. For example, the following example only monitors the CPU power consumption on the CPU socket 1. By default, pyRAPL monitors all the available devices of the CPU sockets.

	import pyRAPL

	pyRAPL.setup(devices=[pyRAPL.Device.PKG], socket_ids=[1])

	@pyRAPL.measure
	def foo():
		# Instructions to be evaluated.

	foo()	

You can append the device pyRAPL.Device.DRAM to the devices parameter list to monitor RAM device too.

Running the test multiple times

For 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:

	import pyRAPL

	pyRAPL.setup()


	@pyRAPL.measure(number=100)
	def foo():
		# Instructions to be evaluated.

	for _ in range(100):
		foo()

Configure the output of the decorator

If you want to handle data with different output than the standard one, you can configure the decorator with an Output instance from the pyRAPL.outputs module.

As an example, if you want to write the recorded energy consumption in a .csv file:

	import pyRAPL

	pyRAPL.setup()

	csv_output = pyRAPL.outputs.CSVOutput('result.csv')

	@pyRAPL.measure(output=csv_output)
	def foo():
		# Instructions to be evaluated.

	for _ in range(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 function fun. Other predefined Output classes exist to export data to MongoDB and Panda dataframe. You can also create your own Output class (see the documentation)

Measure the energy consumption of a piece of code

To measure the energy consumed by the machine during the execution of a given piece of code, run the following code :

	import pyRAPL

	pyRAPL.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 property meter.result, which returns a Result object.

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 block

pyRAPL allows developers to measure a block of instructions using the keyword with as the example below:

	import pyRAPL
	pyRAPL.setup()

	with pyRAPL.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 any Output class that you pass to the Measurement object:

	import pyRAPL
	pyRAPL.setup()

	report = pyRAPL.outputs.DataFrameOutput()

	with pyRAPL.Measurement('bar',output=report):
		# ...
		# Instructions to be evaluated.
		# ...

	report.data.head()

Miscellaneous

About

pyRAPL is an open-source project developed by the Spirals research group (University of Lille and Inria) that is part of the PowerAPI initiative.

The documentation is available here.

Mailing list

You can follow the latest news and asks questions by subscribing to our mailing list.

Contributing

If 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 License

Copyright (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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyRAPL-0.2.3.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

pyRAPL-0.2.3.1-py2.py3-none-any.whl (27.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyRAPL-0.2.3.1.tar.gz.

File metadata

  • Download URL: pyRAPL-0.2.3.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for pyRAPL-0.2.3.1.tar.gz
Algorithm Hash digest
SHA256 c92e7e0644ceee2e55a312d515fc35de8941abd8d810095383e02183afa29b77
MD5 5efb802db54fe82138b037b0870e279f
BLAKE2b-256 f1a0d52262538e60ad9fca62d576277f02d0a689ad0881d8a624487d67f08d82

See more details on using hashes here.

File details

Details for the file pyRAPL-0.2.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pyRAPL-0.2.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for pyRAPL-0.2.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 508c832f7f80fd32e9fdd1194630483c68fdde40bf540537b47502d37295ec76
MD5 9eea05548ba0436673f1e6bb9303a182
BLAKE2b-256 93bdeca5e3464768e560d53b6bb7d77d6dd927035c5dece16fe157f7a04eb642

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page