Skip to content

Instantly share code, notes, and snippets.

@modelmat
Created July 18, 2020 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save modelmat/370dc2d0dbccf684d57e0a527087819c to your computer and use it in GitHub Desktop.
Save modelmat/370dc2d0dbccf684d57e0a527087819c to your computer and use it in GitHub Desktop.
Get real-time power consumption for AMD CPU
# 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