Created
July 18, 2020 02:14
-
-
Save modelmat/370dc2d0dbccf684d57e0a527087819c to your computer and use it in GitHub Desktop.
Get real-time power consumption for AMD CPU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires pysensor module from pypi | |
import sensors | |
def main(): | |
voltages = {} | |
amperages = {} | |
sensors.init() | |
cpu = next(sensors.iter_detected_chips("k10temp-pci-00c3")) | |
for feature in cpu: | |
if (label := feature.label).startswith("V"): | |
voltages[label[1:]] = feature.get_value() | |
elif label.startswith("I"): | |
amperages[label[1:]] = feature.get_value() | |
for name in voltages: | |
# assuming all in both | |
volts = voltages[name] | |
amps = amperages[name] | |
power = volts * amps | |
print(f"{name}: {volts:.3f}V @ {amps:.3f}A => {power:.3f}W") | |
if __name__ == "__main__": | |
try: | |
main() | |
except: | |
sensors.cleanup() | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment