我尝试使用来自GitHub的Battery Historian Python script来分析电池使用情况,但每次使用脚本时生成的html显示&#34;无法找到结束时间&#34;。< / p>
我按照here的步骤进行操作。
以下是生成的示例batterystats.txt
文件:
Battery History:
-2m43s770ms 100 44020302 status=not-charging health=good plug=none temp=270 volt=4339 +wifi +wifi_running +wake_lock brightness=medium phone_state=off
-2m43s151ms 100 44020302
-2m38s500ms 100 04020302 -wake_lock
-2m20s496ms 100 44020302 +wake_lock
-2m17s471ms 100 04020302 -wake_lock
-2m13s741ms 100 04020302 temp=280
-1m59s447ms 100 44020302 +wake_lock
-1m56s423ms 100 04020302 -wake_lock
-43s740ms 100 04020302 volt=4317
-21s432ms 100 040a0302 status=full plug=usb volt=4312 +plugged
Per-PID Stats:
PID 140 wake time: +1s55ms
PID 601 wake time: +1s236ms
PID 140 wake time: +13s381ms
PID 601 wake time: +29ms
PID 812 wake time: +555ms
PID 939 wake time: +18ms
PID 1241 wake time: +51ms
PID 601 wake time: +1ms
PID 1294 wake time: +3ms
PID 601 wake time: +32ms
PID 601 wake time: +7ms
PID 1689 wake time: +103ms
Statistics since last charge:
System starts: 0, currently on battery: false
Time on battery: 2m 22s 369ms (0.0%) realtime, 2m 22s 369ms (0.0%) uptime
Total run time: 21d 4h 47m 25s 154ms realtime, 3d 2h 25m 30s 738ms uptime,
Screen on: 0ms (0.0%), Input events: 0, Active phone call: 0ms (0.0%)
Screen brightnesses: No activity
Mobile total received: 0B, Total sent: 0B
Wi-Fi total received: 249.09KB, Total sent: 18.02KB
Total full wakelock time: 2m 22s 191ms , Total partial wakelock time: 9s 697ms
Signal levels: No activity
Signal scanning time: 0ms
Radio types: none 2m 22s 369ms (100.0%) 0x
Radio data uptime when unplugged: 0 ms
Wifi on: 2m 22s 369ms (100.0%), Wifi running: 2m 22s 369ms (100.0%), Bluetooth on: 0ms (0.0%)
Device battery use since last full charge
Amount discharged (lower bound): 0
Amount discharged (upper bound): 0
Amount discharged while screen on: 0
Amount discharged while screen off: 0
All partial wake locks:
Wake lock 1013 AudioMix: 9s 52ms (4 times) realtime
Wake lock u0a8 UlrDispSvcFastWL: 166ms (2 times) realtime
Wake lock 1000 AlarmManager: 87ms (2 times) realtime
Wake lock u0a8 GCoreFlp: 80ms (3 times) realtime
Wake lock 1000 NetworkStats: 78ms (1 times) realtime
Wake lock 1000 ActivityManager-Launch: 78ms (1 times) realtime
Wake lock u0a8 Event Log Service: 75ms (1 times) realtime
Wake lock u0a24 AlarmManager: 32ms (1 times) realtime
Wake lock u0a8 AlarmManager: 23ms (2 times) realtime
Wake lock u0a43 AlarmManager: 7ms (1 times) realtime
Wake lock u0a8 Event Log Handoff: 7ms (1 times) realtime
Wake lock u0a8 GCM_CONN: 5ms (1 times) realtime
Wake lock u0a8 GCM_HB_ALARM: 4ms (1 times) realtime
Wake lock u0a23 PUSH_SERVICE_WAKE_LOCK: 3ms (1 times) realtime
Wake lock u0a23 AlarmManager: 1ms (1 times) realtime
Wake lock u0a8 Wakeful StateMachine: GeofencerStateMachine: 1ms (1 times) realtime
0:
Wi-Fi network: 632B received, 1.59KB sent
Proc /init:
CPU: 20ms usr + 80ms krn ; 0ms fg
Proc ksoftirqd/0:
CPU: 10ms usr + 0ms krn ; 0ms fg
Proc mtk charger_hv_:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc vold:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc jbd2/mmcblk0p7-:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc pmic_thread_kth:
CPU: 0ms usr + 450ms krn ; 0ms fg
Proc kthreadd:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc btif_rxd:
CPU: 10ms usr + 0ms krn ; 0ms fg
Proc netd:
CPU: 10ms usr + 10ms krn ; 0ms fg
Proc mmcqd/0:
CPU: 0ms usr + 50ms krn ; 0ms fg
Proc kworker/u:0:
CPU: 0ms usr + 270ms krn ; 0ms fg
Proc kworker/u:2:
CPU: 0ms usr + 120ms krn ; 0ms fg
Proc kworker/0:2:
CPU: 0ms usr + 500ms krn ; 0ms fg
Proc zygote:
CPU: 20ms usr + 30ms krn ; 0ms fg
Proc flush-179:0:
CPU: 10ms usr + 0ms krn ; 0ms fg
Proc tx_thread:
CPU: 0ms usr + 100ms krn ; 0ms fg
Proc disp_clean_up_k:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc healthd:
CPU: 0ms usr + 100ms krn ; 0ms fg
Proc ueventd:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc bat_thread_kthr:
CPU: 0ms usr + 520ms krn ; 0ms fg
Proc disp_config_upd:
CPU: 0ms usr + 440ms krn ; 0ms fg
Proc ion_mm_heap:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc disp_ovl_kthrea:
CPU: 0ms usr + 110ms krn ; 0ms fg
1000:
User activity: 6 other, 1 button, 1 touch
Wake lock NetworkStats: 78ms partial (1 times) realtime
Wake lock ActivityManager-Launch: 78ms partial (1 times) realtime
Wake lock AlarmManager: 87ms partial (2 times) realtime
TOTAL wake: 243ms partial realtime
Sensor 0: 2m 22s 369ms realtime (0 times)
Vibrator: 100ms realtime (1 times)
Foreground activities: 129ms realtime (1 times)
Proc com.mediatek.schpwronoff:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc surfaceflinger:
CPU: 950ms usr + 1s 30ms krn ; 0ms fg
Proc com.android.settings:
CPU: 0ms usr + 0ms krn ; 730ms fg
Proc system_server:
CPU: 2s 680ms usr + 2s 230ms krn ; 0ms fg
Proc aal:
CPU: 60ms usr + 180ms krn ; 0ms fg
Proc servicemanager:
CPU: 0ms usr + 10ms krn ; 0ms fg
1001:
Proc com.android.phone:
CPU: 50ms usr + 20ms krn ; 0ms fg
1010:
Proc wpa_supplicant:
CPU: 10ms usr + 30ms krn ; 0ms fg
1013:
Wake lock AudioMix: 9s 52ms partial (4 times) realtime
Proc mediaserver:
CPU: 20ms usr + 30ms krn ; 0ms fg
1023:
Proc sdcard:
CPU: 0ms usr + 20ms krn ; 0ms fg
2000:
Proc adbd:
CPU: 110ms usr + 380ms krn ; 0ms fg
9997:
Proc em_svr:
CPU: 0ms usr + 40ms krn ; 0ms fg
u0a5:
Proc android.process.media:
CPU: 60ms usr + 0ms krn ; 0ms fg
Apk com.android.providers.media:
Service com.android.providers.media.MtpService:
Created for: 0ms uptime
Starts: 1, launches: 1
u0a8:
Wi-Fi network: 5.35KB received, 1.92KB sent
Wake lock Wakeful StateMachine: GeofencerStateMachine: 1ms partial (1 times) realtime
Wake lock GCoreFlp: 80ms partial (3 times) realtime
Wake lock UlrDispSvcFastWL: 166ms partial (2 times) realtime
Wake lock GCM_HB_ALARM: 4ms partial (1 times) realtime
Wake lock Event Log Service: 75ms partial (1 times) realtime
Wake lock GCM_CONN: 5ms partial (1 times) realtime
Wake lock Event Log Handoff: 7ms partial (1 times) realtime
Wake lock AlarmManager: 23ms partial (2 times) realtime
TOTAL wake: 361ms partial realtime
Proc com.google.android.gms:
CPU: 100ms usr + 40ms krn ; 0ms fg
Proc com.google.process.gapps:
CPU: 180ms usr + 70ms krn ; 0ms fg
Proc com.google.android.gms.persistent:
CPU: 1s 130ms usr + 300ms krn ; 0ms fg
Apk com.google.android.gms:
2 wakeup alarms
Service com.google.android.gms.config.ConfigService:
Created for: 0ms uptime
Starts: 0, launches: 1
Service com.google.android.gms.checkin.EventLogService:
Created for: 85ms uptime
Starts: 1, launches: 1
Service com.google.android.gms.gcm.http.GoogleHttpService:
Created for: 0ms uptime
Starts: 0, launches: 1
Service com.google.android.location.reporting.service.DispatchingService:
Created for: 268ms uptime
Starts: 1, launches: 1
Service com.google.android.gms.usagereporting.service.UsageReportingService:
Created for: 0ms uptime
Starts: 0, launches: 1
u0a13:
Proc com.android.systemui:
CPU: 810ms usr + 300ms krn ; 0ms fg
u0a18:
Proc com.lenovo.safecenter.hd:
CPU: 360ms usr + 120ms krn ; 0ms fg
u0a19:
Proc com.lenovo.lps.cloud.sync.row:
CPU: 0ms usr + 0ms krn ; 0ms fg
1 proc starts
u0a20:
Proc com.lenovo.lewea:
CPU: 40ms usr + 10ms krn ; 0ms fg
Apk com.lenovo.lewea:
Service com.lenovo.weather.service.UpdateAppWidgetService:
Created for: 84ms uptime
Starts: 2, launches: 2
u0a23:
Wake lock AlarmManager: 1ms partial (1 times) realtime
Wake lock PUSH_SERVICE_WAKE_LOCK: 3ms partial (1 times) realtime
TOTAL wake: 4ms partial realtime
Proc com.lenovo.lsf.device:
CPU: 30ms usr + 0ms krn ; 0ms fg
u0a24:
Wake lock AlarmManager: 32ms partial (1 times) realtime
Proc com.lenovo.ue.service:
CPU: 40ms usr + 10ms krn ; 0ms fg
u0a42:
(nothing executed)
u0a43:
Wake lock AlarmManager: 7ms partial (1 times) realtime
u0a58:
Proc com.google.android.inputmethod.latin:
CPU: 20ms usr + 0ms krn ; 0ms fg
u0a65:
(nothing executed)
u0a74:
Proc com.google.android.apps.plus:
CPU: 50ms usr + 30ms krn ; 0ms fg
Apk com.google.android.apps.plus:
(nothing executed)
u0a114:
Wi-Fi network: 243.13KB received, 14.51KB sent
Wake lock WindowManager: 2m 22s 191ms full (1 times) realtime
Foreground activities: 2m 22s 208ms realtime (1 times)
Proc com.devstring.imageframe:
CPU: 6s 300ms usr + 810ms krn ; 0ms fg
Statistics since last unplugged:
Time on battery: 2m 22s 369ms (86.9%) realtime, 2m 22s 369ms (86.9%) uptime
Total run time: 2m 43s 811ms realtime, 2m 43s 811ms uptime,
Screen on: 0ms (0.0%), Input events: 0, Active phone call: 0ms (0.0%)
Screen brightnesses: No activity
Mobile total received: 0B, Total sent: 0B
Wi-Fi total received: 249.09KB, Total sent: 18.02KB
Total full wakelock time: 2m 22s 191ms , Total partial wakelock time: 9s 697ms
Signal levels: No activity
Signal scanning time: 0ms
Radio types: none 2m 22s 369ms (100.0%) 0x
Radio data uptime when unplugged: 0 ms
Wifi on: 2m 22s 369ms (100.0%), Wifi running: 2m 22s 369ms (100.0%), Bluetooth on: 0ms (0.0%)
Device is currently plugged into power
Last discharge cycle start level: 100
Last discharge cycle end level: 100
Amount discharged while screen on: 0
Amount discharged while screen off: 0
All partial wake locks:
Wake lock 1013 AudioMix: 9s 52ms (4 times) realtime
Wake lock u0a8 UlrDispSvcFastWL: 166ms (2 times) realtime
Wake lock 1000 AlarmManager: 87ms (2 times) realtime
Wake lock u0a8 GCoreFlp: 80ms (3 times) realtime
Wake lock 1000 NetworkStats: 78ms (1 times) realtime
Wake lock 1000 ActivityManager-Launch: 78ms (1 times) realtime
Wake lock u0a8 Event Log Service: 75ms (1 times) realtime
Wake lock u0a24 AlarmManager: 32ms (1 times) realtime
Wake lock u0a8 AlarmManager: 23ms (2 times) realtime
Wake lock u0a43 AlarmManager: 7ms (1 times) realtime
Wake lock u0a8 Event Log Handoff: 7ms (1 times) realtime
Wake lock u0a8 GCM_CONN: 5ms (1 times) realtime
Wake lock u0a8 GCM_HB_ALARM: 4ms (1 times) realtime
Wake lock u0a23 PUSH_SERVICE_WAKE_LOCK: 3ms (1 times) realtime
Wake lock u0a23 AlarmManager: 1ms (1 times) realtime
Wake lock u0a8 Wakeful StateMachine: GeofencerStateMachine: 1ms (1 times) realtime
0:
Wi-Fi network: 632B received, 1.59KB sent
Proc /init:
CPU: 20ms usr + 80ms krn ; 0ms fg
Proc ksoftirqd/0:
CPU: 10ms usr + 0ms krn ; 0ms fg
Proc mtk charger_hv_:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc vold:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc jbd2/mmcblk0p7-:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc pmic_thread_kth:
CPU: 0ms usr + 450ms krn ; 0ms fg
Proc kthreadd:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc btif_rxd:
CPU: 10ms usr + 0ms krn ; 0ms fg
Proc netd:
CPU: 10ms usr + 10ms krn ; 0ms fg
Proc mmcqd/0:
CPU: 0ms usr + 50ms krn ; 0ms fg
Proc kworker/u:0:
CPU: 0ms usr + 270ms krn ; 0ms fg
Proc kworker/u:2:
CPU: 0ms usr + 120ms krn ; 0ms fg
Proc kworker/0:2:
CPU: 0ms usr + 500ms krn ; 0ms fg
Proc zygote:
CPU: 20ms usr + 30ms krn ; 0ms fg
Proc flush-179:0:
CPU: 10ms usr + 0ms krn ; 0ms fg
Proc tx_thread:
CPU: 0ms usr + 100ms krn ; 0ms fg
Proc disp_clean_up_k:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc healthd:
CPU: 0ms usr + 100ms krn ; 0ms fg
Proc ueventd:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc bat_thread_kthr:
CPU: 0ms usr + 520ms krn ; 0ms fg
Proc disp_config_upd:
CPU: 0ms usr + 440ms krn ; 0ms fg
Proc ion_mm_heap:
CPU: 0ms usr + 20ms krn ; 0ms fg
Proc disp_ovl_kthrea:
CPU: 0ms usr + 110ms krn ; 0ms fg
1000:
User activity: 6 other, 1 button, 1 touch
Wake lock NetworkStats: 78ms partial (1 times) realtime
Wake lock ActivityManager-Launch: 78ms partial (1 times) realtime
Wake lock AlarmManager: 87ms partial (2 times) realtime
TOTAL wake: 243ms partial realtime
Sensor 0: 2m 22s 369ms realtime (0 times)
Vibrator: 100ms realtime (1 times)
Foreground activities: 129ms realtime (1 times)
Proc com.mediatek.schpwronoff:
CPU: 0ms usr + 10ms krn ; 0ms fg
Proc surfaceflinger:
CPU: 950ms usr + 1s 30ms krn ; 0ms fg
Proc com.android.settings:
CPU: 0ms usr + 0ms krn ; 730ms fg
Proc system_server:
CPU: 2s 680ms usr + 2s 230ms krn ; 0ms fg
Proc aal:
CPU: 60ms usr + 180ms krn ; 0ms fg
Proc servicemanager:
CPU: 0ms usr + 10ms krn ; 0ms fg
1001:
Proc com.android.phone:
CPU: 50ms usr + 20ms krn ; 0ms fg
1010:
Proc wpa_supplicant:
CPU: 10ms usr + 30ms krn ; 0ms fg
1013:
Wake lock AudioMix: 9s 52ms partial (4 times) realtime
Proc mediaserver:
CPU: 20ms usr + 30ms krn ; 0ms fg
1023:
Proc sdcard:
CPU: 0ms usr + 20ms krn ; 0ms fg
2000:
Proc adbd:
CPU: 110ms usr + 380ms krn ; 0ms fg
9997:
Proc em_svr:
CPU: 0ms usr + 40ms krn ; 0ms fg
u0a5:
Proc android.process.media:
CPU: 60ms usr + 0ms krn ; 0ms fg
Apk com.android.providers.media:
Service com.android.providers.media.MtpService:
Created for: 0ms uptime
Starts: 1, launches: 1
u0a8:
Wi-Fi network: 5.35KB received, 1.92KB sent
Wake lock Wakeful StateMachine: GeofencerStateMachine: 1ms partial (1 times) realtime
Wake lock GCoreFlp: 80ms partial (3 times) realtime
Wake lock UlrDispSvcFastWL: 166ms partial (2 times) realtime
Wake lock GCM_HB_ALARM: 4ms partial (1 times) realtime
Wake lock Event Log Service: 75ms partial (1 times) realtime
Wake lock GCM_CONN: 5ms partial (1 times) realtime
Wake lock Event Log Handoff: 7ms partial (1 times) realtime
Wake lock AlarmManager: 23ms partial (2 times) realtime
TOTAL wake: 361ms partial realtime
Proc com.google.android.gms:
CPU: 100ms usr + 40ms krn ; 0ms fg
Proc com.google.process.gapps:
CPU: 180ms usr + 70ms krn ; 0ms fg
Proc com.google.android.gms.persistent:
CPU: 1s 130ms usr + 300ms krn ; 0ms fg
Apk com.google.android.gms:
2 wakeup alarms
Service com.google.android.gms.config.ConfigService:
Created for: 0ms uptime
Starts: 0, launches: 1
Service com.google.android.gms.checkin.EventLogService:
Created for: 85ms uptime
Starts: 1, launches: 1
Service com.google.android.gms.gcm.http.GoogleHttpService:
Created for: 0ms uptime
Starts: 0, launches: 1
Service com.google.android.location.reporting.service.DispatchingService:
Created for: 268ms uptime
Starts: 1, launches: 1
Service com.google.android.gms.usagereporting.service.UsageReportingService:
Created for: 0ms uptime
Starts: 0, launches: 1
u0a13:
Proc com.android.systemui:
CPU: 810ms usr + 300ms krn ; 0ms fg
u0a18:
Proc com.lenovo.safecenter.hd:
CPU: 360ms usr + 120ms krn ; 0ms fg
u0a19:
Proc com.lenovo.lps.cloud.sync.row:
CPU: 0ms usr + 0ms krn ; 0ms fg
1 proc starts
u0a20:
Proc com.lenovo.lewea:
CPU: 40ms usr + 10ms krn ; 0ms fg
Apk com.lenovo.lewea:
Service com.lenovo.weather.service.UpdateAppWidgetService:
Created for: 84ms uptime
Starts: 2, launches: 2
u0a23:
Wake lock AlarmManager: 1ms partial (1 times) realtime
Wake lock PUSH_SERVICE_WAKE_LOCK: 3ms partial (1 times) realtime
TOTAL wake: 4ms partial realtime
Proc com.lenovo.lsf.device:
CPU: 30ms usr + 0ms krn ; 0ms fg
u0a24:
Wake lock AlarmManager: 32ms partial (1 times) realtime
Proc com.lenovo.ue.service:
CPU: 40ms usr + 10ms krn ; 0ms fg
u0a42:
(nothing executed)
u0a43:
Wake lock AlarmManager: 7ms partial (1 times) realtime
u0a58:
Proc com.google.android.inputmethod.latin:
CPU: 20ms usr + 0ms krn ; 0ms fg
u0a65:
(nothing executed)
u0a74:
Proc com.google.android.apps.plus:
CPU: 50ms usr + 30ms krn ; 0ms fg
Apk com.google.android.apps.plus:
(nothing executed)
u0a114:
Wi-Fi network: 243.13KB received, 14.51KB sent
Wake lock WindowManager: 2m 22s 191ms full (1 times) realtime
Foreground activities: 2m 22s 208ms realtime (1 times)
Proc com.devstring.imageframe:
CPU: 6s 300ms usr + 810ms krn ; 0ms fg
命令:
adb shell dumpsys batterystats > batterystats.txt
python historian.py batterystats.txt > batterystats.html
batterystats.html显示无法找到结束时间
我已提到Displaying "Cannot find endtime" on Using hisorian.py
EDIT1
当我使用其他设备进行测试时。没有产生这样的错误。但每次此设备电池统计数据都没有给出结束时间错误
编辑2 不同版本的android有不同的dumpsys格式,电池历史记录似乎与新版本兼容。为了生成图表,我在第646至649行中表示,即
#if not self._end_time:
#print "cannot find end time"
#sys.exit(1)
虽然它是一个黑客,我的设备是Android 4.4,它的电池dumpsys不提供应用程序明智的电池使用,但Android 5.2设备这样做。
答案 0 :(得分:1)
看起来parse_end_time
函数try和except语句中的某些内容导致_end_time
未定义,我正在查看here。第646行是产生实际错误的地方。如果我不得不猜测,我会说这是line = line.split("dumpstate: ", 1)[1]
这一行。看起来line
来自您的输入文件for line in fileinput.input(input_file):
,您的batterystats.txt是否有此dumpstate行?您可以尝试注释掉停止脚本的646-648行,看看是否真的需要“结束时间”。
编辑:哎呀,你的batterystats.txt被包含在内 - 并且没有“dumpstate”行...这意味着if "dumpstate:" in line:
(第640行)永远不是真的,并且_end_time
从未被定义过。希望这能以某种方式帮助你。让我知道。
答案 1 :(得分:0)
虽然已经晚了但是,对于当前版本的battery-historian.py
解决方案是使用Android 5.0+ API,不同版本支持不同格式的电池统计日志。当前historian.py
适用于5.0以下版本,它会崩溃或不会显示图表(这是在6.0上测试的)。
如果您了解python,以及如何阅读电池统计文件,您可以编辑Android的风格代码,但这是一项耗时的任务。您也可以用另一种语言编写自己的解析器,但这就像重新发明轮子一样。
我没有尝试的一件事是克隆旧版battery-historian
repo,也许如果有可用的话,它可能适用于旧版本的android,具体取决于repo的年龄。 (未经测试)
<强>更新强>
在查看电池历史记录的commit history时,我可以看到有2014年6月的提交,而Android L(5.0)开发者预览版于2014年8月发布,所以有一个公平的机会早于Android 5.0的提交将适用于<5.0的设备。
答案 2 :(得分:-2)
这不是上述问题的确切解决方案,但它有助于监控您尝试使用dumpsys batterystats解决的相同内容。 请仔细阅读此链接,其中Colt提到反过来获取统计数据。Colt's Unofficial guide to getting started with Battery Historian
他在评论中提到了
Historian仅适用于bugreport内容
使用Battery Historian电池历史记录工具将处理a 电池统计信息转储,并为您创建可视化报告。
记录数据adb shell dumpsys
batterystats --reset
重置 电池数据“你的工作在这里”专业提示:拔掉你的设备进行这项工作,这样你就会看到真正的电池抽奖号码。 (记得插上 它回到下一步之前!)
抓取数据
adb bugreport >bugreport.txt
转换为电池历史记录
python historian.py bugreport.txt >out.html
我会感激任何反馈或批评,我可以从中学习或用来帮助我改进我的答案。谢谢