Skip to main content

Python bindings to native energymon libraries

Project description

EnergyMon Python Bindings

This project provides Python bindings to energymon libraries.

If using this project for other scientific works or publications, please reference:

Dependencies

The energymon libraries should be installed to the system and on the library search path (e.g., LD_LIBRARY_PATH).

The latest energymon C libraries can be found at https://github.com/energymon/energymon.

Building

To install from source:

pip install .

Usage

The module exposes an energymon class, which is a binding to the energymon C struct. First, users are responsible for loading an energymon library using ctypes. For example:

from ctypes import CDLL
from ctypes.util import find_library

# maybe try to find the library by name:
lib_path = find_library("energymon-default")
if lib_path is None:
    # maybe fall back on a relative or absolute path
    lib_path = "libenergymon-default.so"
lib = CDLL(lib_path, use_errno=True)

The module exposes some utilities to simplify usage, e.g., to "get" the energymon, handle pointers, convert data types, check for errors, and raise exceptions. For example:

from energymon import util

em = util.get_energymon(lib, 'energymon_get_default')
print(util.get_source(em))
util.init(em)
try:
    print(util.get_uj(em))
finally:
    util.finish(em)

Direct bindings

To directly use the energymon API, create and "get" the struct to populate its function pointers, then initialize, do work, and cleanup when finished. For example:

from ctypes import pointer, create_string_buffer, sizeof, set_errno, get_errno
from energymon import energymon

em = energymon()
pem = pointer(em)

if lib.energymon_get_default(pem) != 0:
    # handle error...
    exit(1)

name = create_string_buffer(256)
if not em.fsource(name, sizeof(name)):
    # handle error
    exit(1)

print(name.value.decode())
if em.finit(pem) != 0:
    # handle error
    exit(1)

set_errno(0)
uj = em.fread(pem)
if uj == 0 and get_errno() != 0:
    # handle error (but don't skip cleanup!)
    pass

if em.ffinish(pem) != 0:
    # handle error
    exit(1)

Project Source

Find this and related project sources at the energymon organization on GitHub.
This project originates at: https://github.com/energymon/energymon-py

Bug reports and pull requests for bug fixes and enhancements are welcome.

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

energymon-0.0.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

energymon-0.0.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file energymon-0.0.1.tar.gz.

File metadata

  • Download URL: energymon-0.0.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.2

File hashes

Hashes for energymon-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9e0da98046a6e24586ddf3f8a6d522c0d8b7d3f9a3df868bff98ea70dfabcfeb
MD5 0e3bc21d0e9eb860dea42e62686583b4
BLAKE2b-256 22cb36d0fd2c7c7c12b379d14e6102cc79fd8e00a88eae256b5da87aa6287b53

See more details on using hashes here.

File details

Details for the file energymon-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: energymon-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.2

File hashes

Hashes for energymon-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad5f16e60b7b51c49028e170252f85e05173125840d8fea61a39b8ed02b836bb
MD5 fabbb04ac3a0b4706cd01ae9187a5563
BLAKE2b-256 53c832d90dfa33ca78ff7955a72713a38e2e203a6b8cd2449df32fe672f0d3b2

See more details on using hashes here.

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