Skip to content

Instantly share code, notes, and snippets.

@DanielGibson
Created March 10, 2023 18:36
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 DanielGibson/6cb8cde302fb1d2658e6599b73fb84fa to your computer and use it in GitHub Desktop.
Save DanielGibson/6cb8cde302fb1d2658e6599b73fb84fa to your computer and use it in GitHub Desktop.
print current energy consumption of (AMD?) CPU every second, on Linux
#!/bin/bash
export LC_ALL=C
VAL=`cat /sys/class/powercap/intel-rapl:0/energy_uj`
while true ; do
# yes, this is probably not super-precise due to just using sleep and not measuring the time..
sleep 1
NEWVAL=`cat /sys/class/powercap/intel-rapl:0/energy_uj`
DIFF=$(($NEWVAL-$VAL))
WATTS=`echo $DIFF/1000000 | bc -l`
printf "%.3f W\n" "$WATTS"
VAL=$NEWVAL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment