Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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



There 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/


AMD have an equivalent in uProf: 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.


How to do so with pn Ryzen? RAPL?


Another easy tool that may already be on your system is "turbostat".


Highly recommended, very useful tool.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: