An energy consumption measuring and reporting tool
Project description
Scenario Energy Report
Authors: Delano Flipse, Rodin Haker, Aron Hoogeveen
Setup
This project uses Python 3.10.
Description
This tool offers developers a method to gauge energy and power consumption at a per-function level. By default it leverages the spec-power-model developed by Green Coding Solutions for power measurement, utilizing CPU utilization of the program executing the function under test.
The tool automatically detects the hardware specification of the system it is used on and trains the model to accurately capture the energy consumption patterns. This process utilizes the TDP list provided by CodeCarbon to retrieve the TDP for the CPU.
The measuring process can be started in two ways, as discussed in Usage. It will then proceed to measure the program from a separate process.
Finally, you can set up the tool to output a JSON file, print the report in the terminal, both, or neither.
Dependencies
Windows
As of now, no specific requirements are identified.
Linux
- lm-sensors - the command
sensors -j
is used for extracting information about the CPU temperature.
Installation
Using Poetry (Recommended)
poetry add energy_consumption_reporter
Using PIP
pip install energy_consumption_reporter
Submodule / Download
Alternatively, you have the option to download this repository or add it as a submodule and integrate it into your own projects. This approach allows you to customize the tool according to your preferences and make any necessary adjustments as needed.
Add submodule
git submodule add https://github.com/aron-hoogeveen/energy-consumption-reporter.git <destination-folder>
Pull submodule
git submodule update --init
Update submodule
git submodule update --remote --merge
Usage
First you must import the module:
from energy_consumption_reporter.energy_tester import EnergyTester, OutputType
There are two main ways to use this project:
- Implement the decorator to test a function. You can specify the number of iterations as a parameter.
@EnergyTest.energy_test(2)
def test_func():
def fib(n):
if n <= 1:
return n
else:
return fib(n-1) + fib(n-2)
assert fib(37) == 24157817, "Not equal"
- Utilize a with statement to test a specific code segment once.
def test_func3():
with EnergyTest() as test:
def fib(n):
if n <= 1:
return n
else:
return fib(n-1) + fib(n-2)
assert fib(35) == 9227465, "Not equal"
You have the flexibility to configure the following custom parameters:
- Model (default = spec-power-model by Green Coding Solutions)
- Report name (default = CPU Energy Test Report)
- Report description (default = empty)
- Option to save a report in JSON format (default = NONE)
These parameters need to be configured before calling the functions. Refer to the example.py file for more details and examples.
EnergyTest().set_model(MyCustomModel)
EnergyTest().set_report_name("Custom Report Name")
EnergyTest().set_report_description("Custom Report Description")
EnergyTest().set_save_report(OutputType.PRINT_JSON)
If the option 'set_save_report' is set to True, the tool will generate a JSON file containing the output data. When set to False it prints the same information to the terminal.
Pytest plugin
This tool has been integrated into pytest-energy-reporter, a pytest plugin designed to seamlessly incorporate energy metrics into pytest's reporting capabilities.
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
Built Distribution
File details
Details for the file energy_consumption_reporter-0.1.7.tar.gz
.
File metadata
- Download URL: energy_consumption_reporter-0.1.7.tar.gz
- Upload date:
- Size: 3.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.5.0-26-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4be47807fde313944de96c99cf0dbe50e513df0b1e548f5e7d99b845468522eb |
|
MD5 | ff551df1e6399d078cf3d0224bb72e1a |
|
BLAKE2b-256 | cad371a0fded0035f5eed8d81eb4e5d114fea51261a001b42fb054368d4fade5 |
File details
Details for the file energy_consumption_reporter-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: energy_consumption_reporter-0.1.7-py3-none-any.whl
- Upload date:
- Size: 3.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.5.0-26-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff659910fa1ef98c16fa3c5ba5d303375c827ae9b4df5952daebd094e4074334 |
|
MD5 | 5f4a62e98af3530a1cc82a07eb2440b0 |
|
BLAKE2b-256 | 0a73e2566435b045c0ffb39c1119b1549c8b8d66c30b237460030597dad0919f |