4

I want to measure the energy consumed while performing a repetitive task on a Raspberry Pi. One example of my usecase is measuring the energy consumed when I am sending 10,000 data packets/min to a server. And then compare the energy consumed when sending 1,000 packets/min. Are there any software tools which can help to achieve the objective?

2
  • 1
    Why...........?
    – Milliways
    Nov 6, 2015 at 11:33
  • Software won't be able to measure the power directly, but you could see if anyone has yet bothered to implement any demand-scaling of the clock, and if so, figure out a way to log it. If not there may not be all that much variation under load to begin with, unless you are using something like wifi or 3g where communication might may have a noticeable power cost. Nov 12, 2015 at 1:00

1 Answer 1

1

doesn't work since RPi lacks the power gauge hardware. Still, may be useful for people running different SBC brands

I would start by logging /sys/class/power_supply/*/current_now every ten seconds or so. You may want to replace the star by whatever the power supply device is called on RPi. A simple script would do:

for i in {1..360}; do
    cat /sys/class/power_supply/*/current_now >> log.txt
    sleep 10
done

This script would run for an hour (3600 seconds), so keep sending your data packets during that time. Then you can simply take the log file, compute the average current (it'll be in micro-Amperes, so divide by 1000000), multiply by 5 Volts and voila - you have the energy consumption in W*h.

4
  • How does this work internally ? So far i know the Pi has no current-measuring capability inside the SoC or even as onboard chip ?
    – flakeshake
    Dec 9, 2015 at 14:08
  • @flakeshake It doesn't? I didn't really verify, I just assumed that since /sys/class/power_supply/ is present on all machines I encountered in the last 10 years (be it x86, x64 or ARM), RPi should have it as well. Dec 9, 2015 at 14:17
  • 2
    This won't work. The folder /sys/class/power_supply/ is empty
    – GER_Moki
    Dec 9, 2015 at 20:04
  • OK, I've added a disclamer to my answer. Sorry it didn't help. I guess the only way for RPi is to use a USB power meter then. Dec 9, 2015 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.