Comment on
Fairphone 6 + PostmarketOS review
Reply in thread
I used this script:
#!/bin/sh
LABEL="${1:-test}"; DUR="${2:-60}"; INT=2
B=/sys/class/power_supply/qcom-battmgr-bat
G=/sys/class/devfreq/3d00000.gpu
GMAX=$(cat "$G/max_freq")
TMP=$(mktemp)
cpu_snap() { awk '/^cpu /{idle=$5+$6;t=0;for(i=2;i<=NF;i++)t+=$i;print idle, t}' /proc/stat; }
cap0=$(cat "$B/capacity"); cpu0=$(cpu_snap)
t_end=$(( $(date +%s) + DUR ))
while [ "$(date +%s)" -lt "$t_end" ]; do
echo "$(cat $B/current_now) $(cat $B/voltage_now) $(cat $G/cur_freq)" >> "$TMP"
sleep "$INT"
done
cap1=$(cat "$B/capacity"); cpu1=$(cpu_snap)
awk -v label="$LABEL" -v dur="$DUR" -v gmax="$GMAX" -v cap0="$cap0" -v cap1="$cap1" \
-v cpu0="$cpu0" -v cpu1="$cpu1" -v mah=4415 '
{ i=$1; if(i<0)i=-i; sI+=i; sV+=$2; sG+=$3; n++ }
END{
if(n==0){print "no samples"; exit}
aI=sI/n/1000; aV=sV/n/1e6; aW=aI/1000*aV; aG=sG/n/1e6;
pph=aI/mah*100; rt=(pph>0)?100/pph:0;
split(cpu0,a," "); split(cpu1,b," "); di=b[1]-a[1]; dt=b[2]-a[2];
cpu=(dt>0)?100*(1-di/dt):0;
printf "TEST: %s (%ds, %d samples)\n", label, dur, n;
printf " Power draw : %.2f W (%.0f mA @ %.2f V)\n", aW, aI, aV;
printf " Drain rate : %.1f %%/hr (~%.1f h from full)\n", pph, rt;
printf " CPU usage : %.1f %%\n", cpu;
printf " GPU : %.0f MHz (%.0f%% of %.0f MHz max)\n", aG, aG/(gmax/1e6)*100, gmax/1e6;
printf " Capacity : %d%% -> %d%% (delta %d%%)\n", cap0, cap1, cap0-cap1;
}' "$TMP" | tee /tmp/battest_last.txt
rm -f "$TMP"