sensor.py 1.34 KB
Newer Older
1 2 3 4 5 6 7
"""Sensor Module:
    provide the core functionalities related to measuring power, energy,
    temperature and other information about the local node, using our internal
    version of the coolr code.

    This module should be the only one interfacing with coolr.
"""
8 9 10 11 12 13 14
from __future__ import print_function
import coolr
import coolr.clr_rapl
import coolr.clr_hwmon
import coolr.clr_nodeinfo
import coolr.clr_cpufreq
import coolr.clr_misc
15 16 17 18 19 20


class SensorManager:
    """Performs sensor reading and basic data aggregation."""

    def __init__(self):
21 22 23 24 25 26 27 28 29 30
        self.nodeconfig = coolr.clr_nodeinfo.nodeconfig()
        self.cputopology = coolr.clr_nodeinfo.cputopology()
        self.coretemp = coolr.clr_hwmon.coretemp_reader()
        self.rapl = coolr.clr_rapl.rapl_reader()

    def start(self):
        self.rapl.start_energy_counter()

    def stop(self):
        self.rapl.stop_energy_counter()
31 32

    def do_update(self):
33 34 35 36
        machine_info = dict()
        machine_info['energy'] = self.rapl.sample(accflag=True)
        machine_info['temperature'] = self.coretemp.sample()
        return machine_info
37 38 39 40 41 42

    def get_powerlimits(self):
        pl = self.rapl.get_powerlimits()
        # only return enabled domains
        return {k: pl[k] for k in pl if pl[k]['enabled']}

43
    def set_powerlimit(self, domain, value):
44
        self.rapl.set_powerlimit(value, domain)