Python package for monitoring and recording power usage, energy consumption, and performance metrics from hardware components such as GPUs and CPUs
Project description
wattameter is a Python package for monitoring and recording power usage over time, among other metrics. It enables time series data collection on hardware components such as CPUs and GPUs.
Current Features
- Track power usage for CPU (using RAPL) and GPU (using nvidia-ml-py)
- Track GPU utilization and temperature
- Periodically log time series data to file
- Customizable logging and output options
- Command-line interface for easy usage
- Integration with SLURM for HPC environments
Installation
You can install wattameter via pip:
pip install wattameter
Usage
As a Python module
from wattameter import Tracker
from wattameter.readers import NVMLReader
tracker = Tracker(
reader=NVMLReader((Power,)),
dt_read=0.1, # Time interval for reading power data (seconds)
freq_write=600, # Frequency (# reads) for writing power data to file
output="power_log.txt",
)
tracker.start()
# ... your code ...
tracker.stop()
# ... or ...
with Tracker(
reader=NVMLReader((Power,)),
dt_read=0.1,
freq_write=600,
output="power_log.txt",
) as tracker:
# ... your code ...
Command-line interface
wattameter --suffix test --id 0 --dt-read 0.1 --freq-write 600 --log-level info
| Option | Short | Default | Description |
|---|---|---|---|
| --suffix | -s | None | Suffix for output files |
| --id | -i | None | Identifier for the experiment |
| --dt-read | -t | 1 | Time interval (seconds) between readings |
| --freq-write | -f | 3600 | Frequency (# reads) for writing data to file |
| --log-level | -l | warning | Logging level: debug, info, warning, error, critical |
| --help | -h | Show the help message and exit |
Command-line interface with SLURM
For asynchronous usage with SLURM, we recommend using wattameter.sh. Follow the example examples/slurm.sh, i.e.,
#SBATCH --signal=USR1@0 # Send USR1 signal at the end of the job to stop wattameter
# Load Python environment with wattameter installed...
# Get the path of the wattameter script
WATTAPATH=$(python -c 'import wattameter; import os; print(os.path.dirname(wattameter.__file__))')
WATTASCRIPT="${WATTAPATH}/utils/wattameter.sh"
WATTAWAIT="${WATTAPATH}/utils/wattawait.sh"
# Run wattameter on all nodes
srun --overlap --wait=0 --nodes=$SLURM_JOB_NUM_NODES --ntasks-per-node=1 "${WATTAWAIT}" $SLURM_JOB_ID &
WAIT_PID=$!
srun --overlap --wait=0 --output=slurm-$SLURM_JOB_ID-wattameter.txt --nodes=$SLURM_JOB_NUM_NODES --ntasks-per-node=1 "${WATTASCRIPT}" -i $SLURM_JOB_ID & # Use other options here as needed
wait $WAIT_PID
# Run your script here...
# Cancel the job to stop wattameter
scancel $SLURM_JOB_ID
All options are the same as the regular command-line interface. The script will automatically handle the output file naming based on the provided SLURM_JOB_ID and node information.
Contributing
Contributions are welcome! Please open issues or submit pull requests.
License
See the LICENSE file for details.
NREL Software Record number: SWR-25-101
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wattameter-0.7.2.tar.gz.
File metadata
- Download URL: wattameter-0.7.2.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bc23373756cd1a19c038f77d1b26d1d714fc1cc963eabf470bb40bda8928da5
|
|
| MD5 |
7e37a05858e4ec7f2e336610b744e09f
|
|
| BLAKE2b-256 |
a36fb1b984b4e843013688bb132e9e358d586c9af30b68a4713af46c45d46083
|
Provenance
The following attestation bundles were made for wattameter-0.7.2.tar.gz:
Publisher:
python-publish.yml on NREL/WattAMeter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wattameter-0.7.2.tar.gz -
Subject digest:
1bc23373756cd1a19c038f77d1b26d1d714fc1cc963eabf470bb40bda8928da5 - Sigstore transparency entry: 701523406
- Sigstore integration time:
-
Permalink:
NREL/WattAMeter@1225bad6e1ab8ac30cbb8c3688a6f7cf070a5f57 -
Branch / Tag:
refs/tags/v0.7.2 - Owner: https://github.com/NREL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1225bad6e1ab8ac30cbb8c3688a6f7cf070a5f57 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wattameter-0.7.2-py3-none-any.whl.
File metadata
- Download URL: wattameter-0.7.2-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
981bbe47151e00e02913fda4271af5e8523ab296fec4d2dd5bf54141ce6b693e
|
|
| MD5 |
69f11515284f29e2035ee228972ac1f6
|
|
| BLAKE2b-256 |
05efdb90aa8fd546d525fd06995856369e1e2b2c148a81a98d23ecdc182017b3
|
Provenance
The following attestation bundles were made for wattameter-0.7.2-py3-none-any.whl:
Publisher:
python-publish.yml on NREL/WattAMeter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wattameter-0.7.2-py3-none-any.whl -
Subject digest:
981bbe47151e00e02913fda4271af5e8523ab296fec4d2dd5bf54141ce6b693e - Sigstore transparency entry: 701523409
- Sigstore integration time:
-
Permalink:
NREL/WattAMeter@1225bad6e1ab8ac30cbb8c3688a6f7cf070a5f57 -
Branch / Tag:
refs/tags/v0.7.2 - Owner: https://github.com/NREL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1225bad6e1ab8ac30cbb8c3688a6f7cf070a5f57 -
Trigger Event:
release
-
Statement type: