What is the unit of the value returned by Cpu.getCurrentPower?
metacosm opened this issue · 4 comments
Is it mW, W, J, something else?
Hi, the power value is in Watts in Windows and on Raspberry.
On Linux with RAPL, it's the energy value in Joules from RAPL readings (which by itself is meaningless as that's energy since pc start, and we use to calculate energy difference every second e2 - e1, so we can get enegy/second, thus power).
It doesn't appear to be the case, though, as both initial and current power are measured during the same loop iteration meaning that the measurements occur in quick succession. Also, this means that every other Cpu implementations must return 0 for getInitialPower
, when the Linux RAPL implementation is actually the only one that's supposed to make use of this value.
This also means that the logic / reporting is inconsistent because the agent reports total joules being consumed while in all instances apart from RAPL/Linux, the total is actually Watts, at least, if I understand correctly.
The logic algorithm is:
- on Linux with RAPL, we get an before/after value of energy, and calculate the difference to get the energy consumption
- On RPi and Windows, we only get the power consumption (from formula or Intel API) once, and use it as energy consumption (because our loop is 1 sec, energy = power in this case). Yes
getInitialPower
will return 0 in this case, andgetCurrentPower
will return power consumption in watts (which for 1 second, is = energy).
The before/after energy collection is done every second, while we collect methods statistics in a smaller sampling loop with the method sample()
Which will loop for the entire second.
Hope this clarifies our approach.