def update(self): if not self.is_available: return current_measurement_value = rapl_read() current_measurement_time = time.time() for m_idx, _ in enumerate(self.last_probe): joule_used = ((current_measurement_value[m_idx].current - self.last_probe[m_idx].current) / float(self.MICRO_JOULE_IN_JOULE)) self.last_probe[m_idx] = joule_used seconds_passed = (current_measurement_time - self.last_probe_time) logging.debug("seconds passed %s", seconds_passed) watts_used = float(joule_used) / float(seconds_passed) logging.debug("watts used %s", watts_used) logging.info("Joule_Used %d, seconds passed, %d", joule_used, seconds_passed) if watts_used > 0: # The information on joules used elapses every once in a while, # this might lead to negative readings. # To prevent this, we keep the last value until the next update self.last_measurement[m_idx] = watts_used logging.info("Power reading elapsed") self.last_probe = current_measurement_value self.last_probe_time = current_measurement_time
def __init__(self): Source.__init__(self) self.name = 'Power' self.measurement_unit = 'W' self.pallet = ('power light', 'power dark', 'power light smooth', 'power dark smooth') self.last_probe_time = time.time() self.last_probe = rapl_read() if not self.last_probe: self.is_available = False logging.debug("Power reading is not available") return self.max_power = 1 self.last_measurement = [0] * len(self.last_probe) multi_sensors = [] for item in self.last_probe: name = item.label sensor_count = multi_sensors.count(name) multi_sensors.append(name) if 'package' not in name: name += ",Pkg" + str(sensor_count) self.available_sensors.append(name)