healthd log
android kernel log中会打印出如下healthd log,这些log是什么意思?来自哪里?这篇文章为你解读。
<12>[ 191.726280] .(4)[418:[email protected]]healthd: battery l=4 v=3575 t=30.0 h=2 st=3 c=-248 fc=2946000 cc=1 chg=
<12>[ 191.753749] .(5)[418:[email protected]]healthd: battery l=4 v=3567 t=30.0 h=2 st=3 c=-258 fc=2946000 cc=1 chg=
<12>[ 195.114317] .(5)[418:[email protected]]healthd: battery l=4 v=3667 t=30.0 h=2 st=2 c=446 fc=2946000 cc=1 chg=a
<12>[ 195.122295] .(7)[418:[email protected]]healthd: battery l=4 v=3667 t=30.0 h=2 st=2 c=406 fc=2946000 cc=1 chg=a
<12>[ 195.149265] .(4)[418:[email protected]]healthd: battery l=4 v=3667 t=30.0 h=2 st=2 c=407 fc=2946000 cc=1 chg=a
<12>[ 195.151107] .(4)[418:[email protected]]healthd: battery l=4 v=3652 t=30.0 h=2 st=2 c=304 fc=2946000 cc=1 chg=a
<12>[ 195.162849] .(4)[418:[email protected]]healthd: battery l=4 v=3647 t=30.0 h=2 st=2 c=299 fc=2946000 cc=1 chg=a
<12>[ 200.414571] .(7)[418:[email protected]]healthd: battery l=4 v=3572 t=30.0 h=2 st=3 c=-258 fc=2946000 cc=1 chg=
<12>[ 200.417265] .(7)[418:[email protected]]healthd: battery l=4 v=3572 t=30.0 h=2 st=3 c=-253 fc=2946000 cc=1 chg=
<12>[ 200.420810] .(7)[418:[email protected]]healthd: battery l=4 v=3572 t=30.0 h=2 st=3 c=-274 fc=2946000 cc=1 chg=
<12>[ 203.755133] .(6)[418:[email protected]]healthd: battery l=4 v=3806 t=30.0 h=2 st=3 c=1365 fc=2946000 cc=1 chg=
<12>[ 203.994594] .(6)[418:[email protected]]healthd: battery l=4 v=3606 t=30.0 h=2 st=2 c=-29 fc=2946000 cc=1 chg=a
<12>[ 203.997249] .(5)[418:[email protected]]healthd: battery l=4 v=3606 t=30.0 h=2 st=2 c=-32 fc=2946000 cc=1 chg=a
<12>[ 203.999349] .(5)[418:[email protected]]healthd: battery l=4 v=3606 t=30.0 h=2 st=2 c=-28 fc=2946000 cc=1 chg=a
[ 6883.388565] (1)[486:[email protected]]healthd: battery l=25 v=3830 t=30.5 h=2 st=2 c=453400 fc=2946000 cc=0 chg=u
[ 6899.524245] (2)[486:[email protected]]healthd: battery l=25 v=3830 t=30.6 h=2 st=2 c=473600 fc=2946000 cc=0 chg=u
[ 6937.475240] (5)[486:[email protected]]healthd: battery l=25 v=3826 t=30.7 h=2 st=2 c=407700 fc=2946000 cc=0 chg=u
[ 6959.521355] (1)[486:[email protected]]healthd: battery l=25 v=3826 t=30.7 h=2 st=2 c=406400 fc=2946000 cc=0 chg=u
[ 7002.385107] (0)[486:[email protected]]healthd: battery l=26 v=3827 t=30.8 h=2 st=2 c=370400 fc=2946000 cc=0 chg=u
[ 7019.522528] (1)[486:[email protected]]healthd: battery l=26 v=3827 t=30.9 h=2 st=2 c=469300 fc=2946000 cc=0 chg=u
通过代码跟踪可以大概知道log含义:
- l: 电量百分比
- v: 电池电压
- t: 电池温度
- h: 电池健康状态(如下)
/frameworks/native/services/batteryservice/include/batteryservice/BatteryServiceConstants.h
18 enum {
19 BATTERY_HEALTH_UNKNOWN = 1,
20 BATTERY_HEALTH_GOOD = 2,
21 BATTERY_HEALTH_OVERHEAT = 3,
22 BATTERY_HEALTH_DEAD = 4,
23 BATTERY_HEALTH_OVER_VOLTAGE = 5,
24 BATTERY_HEALTH_UNSPECIFIED_FAILURE = 6,
25 BATTERY_HEALTH_COLD = 7,
26 };
- c=%d", props.batteryCurrent);
- fc=%d", props.batteryFullCharge);
- cc=%d", props.batteryCycleCount);
- chg: 当前使用充电器:
- props.chargerAcOnline ? “a” : “”,
- props.chargerUsbOnline ? “u” : “”,
- props.chargerWirelessOnline ? “w” : “”
log打印来源
kernel log中的healthd log是从android 代码 /system/core/healthd/BatteryMonitor.cpp
打印出来的:
201 bool BatteryMonitor::update(void) {
...
214 props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000;
215
216 if (!mHealthdConfig->batteryCurrentNowPath.isEmpty())
217 props.batteryCurrent = getIntField(mHealthdConfig->batteryCurrentNowPath) / 1000;
218
219 if (!mHealthdConfig->batteryFullChargePath.isEmpty())
220 props.batteryFullCharge = getIntField(mHealthdConfig->batteryFullChargePath);
221
222 if (!mHealthdConfig->batteryCycleCountPath.isEmpty())
223 props.batteryCycleCount = getIntField(mHealthdConfig->batteryCycleCountPath);
224
225 if