一、安装Battery Historian
1、安装Docker(Windows)
1)安装环境
-
环境要求
1、Windows启用WSL2功能2、CPU支持二级地址转换(SLAT)
3、4G以上内存
4、BIOS设置中启用硬件虚拟化支持
-
本地环境
1、系统:Windows 11 专业版 64位2、CPU:Intel® Core™ i7-1065G7 CPU @ 1.30GHz 1.50 GHz
3、内存:32G
4、BIOS中已启用硬件虚拟化支持,任务管理器 - 性能 - CPU - 虚拟化状态为“已开启”
2)安装Docker
1、版本:Docker Desktop 4.26.1
2、下载地址:https://docs.docker.com/desktop
3、点击安装,等待安装完成,并启动docker
3)检测Docker安装
1、打开Windows PowerShell
2、执行以下命令从官方仓库中拉去hello-world的镜像到本地,并且自动将其实例化成容器
docker run hello-world
输出如下:
PS C:\Users\xxx> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:ac69084025c660510933cca701f615283cdbb3aa0963188770b54c31c8962493
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
2、安装Battery Historian镜像
1、先启动 Docker Desktop 应用(即 Docker 的 GUI 前端),然后再运行 Battery Historian 映像。运行此映像会初始化 Docker 工具。此操作至少要执行一次,Battery Historian 才会运行。
2、首次运行 Battery Historian 时,请从命令行运行此工具。您无法通过 Docker Desktop 应用指定用于运行 Web 服务器的端口,只能从命令行执行此操作。不过,当您从命令行成功运行容器后,系统会在 Docker Desktop 中创建一个条目,然后您可以使用 Docker Desktop 中的同一监听器端口启动该条目。
3、使用以下命令运行 Battery Historian 映像:
docker run -p port_number:9999 gcr.io/android-battery-historian/stable:3.1 --port 9999
Battery Historian 会使用您选择的端口,如使用 port_number 指定的端口。例如:
docker run -p 9999:9999 gcr.io/android-battery-historian/stable:3.1 --port 9999
4、在浏览器中打开Battery Historian
http://192.168.50.235:9999
其中192.168.50.235为本机IP
二、使用 Batterystats 收集数据
1、将移动设备连接到计算机。
2、在终端窗口中,运行以下命令来关闭正在运行的 adb 服务器:
adb kill-server
3、重启 adb 并运行以下命令来检查已连接的设备:
adb devices
4、开启获取电量数据
adb shell dumpsys batterystats --enable full-wake-history
5、运行以下命令,重置电池数据的收集操作:
adb shell dumpsys batterystats --reset
设备始终会在后台收集 Batterystats 和其他调试信息。重置操作会清除之前收集的电池数据。如果您不重置,输出内容会非常大。
6、断开设备与计算机的连接,以便仅通过设备电池供电
7、使用您的应用,然后执行您要收集数据的操作。
8、重新连接手机。
9、确保系统能识别您的手机,然后运行以下命令:
adb devices
10、使用原始数据生成报告。
对于搭载 Android 7.0 及更高版本的设备
adb bugreport [path/]bugreport.zip
对于搭载 Android 6.0 及更低版本的设备:
adb bugreport [path/]bugreport.txt
11、导出数据
C:\Users\xxx>adb bugreport bugreport.zip
/data/user_de/0/com.android.shell/files/bugreports/bugreport-ALN-AL00-HUAWEIALN-AL00-2024-01-02-15-25-21.zip: 1 file pulled, 0 skipped. 34.5 MB/s (5875956 bytes in 0.162s)
Bug report copied to bugreport.zip
adb pull /data/user_de/0/com.android.shell/files/bugreports/bugreport-ALN-AL00-HUAWEIALN-AL00-2024-01-02-15-25-21.zip D:\temp
12、运行docker,运行Battery Historian
浏览器中打开,例如:http://192.168.50.235:9999/
点击Browse,选择zip包,执行Submit,等待解析完成。
其他
1、获取包名
adb shell
dumpsys activity|grep mFocusedWindow
2、Battery Historian使用3.1版本,3.0版本解析报告报错。
参考
https://developer.android.com/topic/performance/power/setup-battery-historian?hl=zh-cn