Logging and Graphing Power Consumption of Embedded Linux Systems -- Busybox and GnuPlot analyzing the Kindle 3

Actually this should've been really easy. A small script loop on the kindle to log the battery consumption and then plug that data into gnuplot. But it turned out gnuplot afaik doesn't support to output the difference between values. Thanks to apo_ from #gnuplot I've got it running with the help of awk now. The great thing is that this script runs in busybox and can hence easily be adapted for pretty much any kind of portable devices including Android phones, Kindles, Tablets, Notebooks, Netbooks, etc. And that's how it looks.
Kindle 3 Battery Consumption
Measurement points are marked with an x.

First the very simple kindle log script:

while true;
cat /sys/devices/system/luigi_battery/luigi_battery0/battery_mAH >> $LOG
sleep 180
Then a little awk script to calculate the difference between the values for gnuplot:
zero="$(awk -F ';' '{ print $1 }' batterylog.txt | head -n1)"
awk -F ';' '{print $1-'$zero',a-$2; a=$2;}' batterylog.txt | sed '1d' > /tmp/batterylog
awk -F ';' '{print $1-'$zero', $2 / 100;}' batterylog.txt | sed '1d' > /tmp/batterylog2
awk -F ';' '{print $1-'$zero', $3 / 200;}' batterylog.txt | sed '1d' > /tmp/batterylog3
And now gnuplot that!

set xlabel "Time [s]"
set ylabel "Battery [mAh/mV/mW]"
set style fill solid 1.0 border
plot "/tmp/batterylog2" using 1:2 title "", \
"/tmp/batterylog" using 1:2 smooth unique title "Battery Usage [delta mW]", \
"/tmp/batterylog2" using 1:2 smooth unique title "Battery Absolute [mAh/100]", \
"/tmp/batterylog3" using 1:2 smooth unique title "Battery Absolute [mV/200]"
pause 100;

All very easy stuff of course! ;-)


  1. Wow, neat... I will have to try to think of a way to adapt this.

  2. it is extremely easy on you have to do is adapt 1 script


I appreciate comments. Feel free to write anything you wish. Selected comments and questions will be published.