Skip to main content

Scientifically rigorous delta-based energy profiling for Linux workloads

Project description

pywattson

PyPI Python 3.12+ CI License: MIT

Scientifically rigorous, low-overhead, delta-based energy profiling for Linux workloads — video codecs, ML inference, or anything else.

pip install pywattson

Quick Start

Context Manager (primary)

from wattson import EnergyMonitor, BaselineStrategy

with EnergyMonitor(
    gpu_device_indices=0,
    metadata={"codec": "DCVC-RT", "qp": 42, "gop": 32},
    include_dram=True,
    baseline=BaselineStrategy.SEPARATE_SESSION,
) as monitor:
    run_codec_encode(...)

result = monitor.result
print(result.total_energy_j)
print(result.to_csv_row())

Decorator

from wattson import EnergyMonitor

@EnergyMonitor.profile(metadata={"codec": "x265"})
def encode():
    ...

N-Repetition Research Driver

from wattson import run_energy, BaselineStrategy

stats = run_energy(
    workload=encode,          # or command="python encode.py"
    n_repeats=15,
    n_warmup=2,
    gpu_device_indices=0,
    baseline=BaselineStrategy.SEPARATE_SESSION,
    metadata={"codec": "VVC"},
)

print(stats["stats"]["total_energy_j"]["median"])
print(stats["stats"]["total_energy_j"]["iqr"])

Scientific Methodology

Why Delta Counters, Not Power Sampling

Wattson reads hardware energy counters before and after a workload and computes the difference. This pure-delta approach avoids the sampling error and timing jitter inherent in power × time integration.

RAPL Domains

  • Package — total socket energy (cores + uncore).
  • DRAM — memory energy on its own power plane (not double-counted with package).
  • Counters are 32-bit; overflow is corrected automatically: corrected_delta = (max_uj − start_uj) + end_uj.

NVML Calibration

Some GPU drivers underreport or overreport the firmware energy counter. Wattson's calibrate() method compares the counter against integrated nvmlDeviceGetPowerUsage() and warns if they diverge by more than 20%.

Thermal Bias & BaselineStrategy

Measuring idle after a workload gives a thermally elevated baseline. Wattson defaults to SEPARATE_SESSION — idle is measured once in a cool state before any workload runs. Duration normalisation corrects for time.sleep() scheduler overshoot.

Multi-Tenant Caveat

RAPL counters are socket-wide. If other processes share the CPU socket, their energy is included. For accurate measurements, use a dedicated machine or account for background load.

Versioning

This project uses Conventional Commits and Release Please for automated semantic versioning and changelogs.

  • fix: → patch bump
  • feat: → minor bump
  • feat!: or BREAKING CHANGE: → major bump

License

MIT

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

pywattson-0.4.5.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywattson-0.4.5-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file pywattson-0.4.5.tar.gz.

File metadata

  • Download URL: pywattson-0.4.5.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywattson-0.4.5.tar.gz
Algorithm Hash digest
SHA256 962c34ffe7daf16411f3dc09ad6262146d8ebcbca236b790ed206d5a9cb7097a
MD5 3711c1704d993ef84bde7dcf6ec35ea3
BLAKE2b-256 c3e3eea5338ee350108ad9f503b013b854c21d4e5b5275ce2758a045a48db1dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywattson-0.4.5.tar.gz:

Publisher: release.yml on oelghatidoc/wattson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywattson-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: pywattson-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywattson-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5078fb72aff0a1607ce1acded694919781ee3aa9aaec85f59923167161d56545
MD5 c6229949f3c7229f77cf20d1013b3af6
BLAKE2b-256 a7900e4aa2fecfc2fd5b5f1d99feef0a21f74b97f10c3a37b02b88db36a7493e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywattson-0.4.5-py3-none-any.whl:

Publisher: release.yml on oelghatidoc/wattson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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