View Single Post
Posts: 486 | Thanked: 251 times | Joined on Oct 2009
#55
I've written a short perl script to monitor battery drain. It will also monitor charging, but not many battery items get updated during charging. The script logs the battery parameters once per minute on the minute. Ten minutes might be better. The stepsize available from the system is
pretty coarse, so it is only good for extended perioids of stable average power draw. (e.g. wifi on for an hour, all radios off for an hour, etc.)

If you name the script batt_mon.pl and want to log to 20091207bat.log, then type in a terminal window:
Code:
perl -w batt_mon.pl > 20091207bat.log
The columns are
time in seconds since 1970 Jan 01 00:00:00 UTC
battery level, seems to go frem 0 to 9
battery % full, state is still 'ok' at 10%
remaining battery power in seconds (little reality)
milliampere-hours remaining
present battery millivolts
battery state, 'full', 'ok', others I don't know yet
charging/discharging

Everything between {} below is supposed to be indented. If not, it is really part of the line above. when I paste from the preview of this post into the vi editor, the lines are as they should be.

Code:
#!/usr/bin/perl -w
print "#   time\tlevel\t%chrg\tsec\tmah\tmVolts\tstate\tchg/dis\n";
while(1) {
  $now = time;
  @lines = `lshal | grep batt`;
  @level = split ' ', $lines[1];
  @pct = split ' ', $lines[4];
  @remtime =  split ' ', $lines[10];
  @mah =  split ' ', $lines[12];
  @mv = split ' ', $lines[17];
  @st = split ' ', $lines[0];
  @chrg = split ' ', $lines[8];
  @disc = split ' ', $lines[9];
  $cd = substr($chrg[2],0,1) . "/" . substr($disc[2],0,1);
  print "$now\t$level[2]\t$pct[2]\t$remtime[2]\t$mah[2]\t$mv[2]\t$st[2]\t$cd\n";
  sleep 60 - time%60;
}
 

The Following 3 Users Say Thank You to j.s For This Useful Post: