4 ms·
Since kernel 3.3 or so, RAPL is also exposed through `/sys/devices/virtual/powercap/intel-rapl/*/energy_uj` in micro-joules (if not, `modprobe intel_rapl`). So
by sirn 2y ago
Since kernel 3.3 or so, RAPL is also exposed through `/sys/devices/virtual/powercap/intel-rapl/*/energy_uj` in micro-joules (if not, `modprobe intel_rapl`). So if you want to do a quick power measurement, it can be done using just POSIX sh (root required):
# 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.
[1]: https://github.com/intel/pcm https://github.com/intel/pcm
- jeffbee 2y agoAnother easy tool that may already be on your system is "turbostat".
- ngneer 2y agoHighly recommended, very useful tool.
- lathiat 2y agoAMD have an equivalent in uProf: https://www.amd.com/en/developer/uprof.html https://www.amd.com/en/developer/uprof.html 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.
- 3abiton 2y agoHow to do so with pn Ryzen? RAPL?
- 149765 2y agoThere is also perf: 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/