by sirn · 2y ago · 0 comments
# in milli-watt (1000 = 1W) because shell arithmetic doesn't do floating point
while true; do
LAST_MJ=$MJ
MJ=$(cat /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/energy_uj)
echo $(((MJ - LAST_MJ) / 1000))
sleep 1
done
Despite the powercap name being intel-rapl, the powercap interface is also available on AMD machines.For a more detailed reading on several more metrics about the CPU, I think pcm[1] may be a better tool (it's a successor to the Intel Power Gadget the project was forked from). Though, it only works on Intel CPU.
perf stat -e 'power/energy-pkg/' -I 1000 --interval-count 3
# time counts unit events
1.001064377 11.00 Joules power/energy-pkg/
2.002605466 10.98 Joules power/energy-pkg/
3.003726824 11.01 Joules power/energy-pkg/Power profiling is listed as supported on all CPUs though a bunch of features (including memory bandwidth, one that I had wanted) are limited to EPYC CPUs and don't exist in Ryzen or Threadripper.