将安卓设备通过shell脚本,输入指定进程,将cpu/内存信息提取到文件里,方便通过python或其他工具制作成曲线图。
前提设备有执行top procrank busybox等指令的权限,最好就是root化的
脚本输入设计参数1:指定多个进程名,用逗号分开
参数2:记录输出文件,设备中的可写路径
参数3:数据采集间隔时间,这个时间不是精确的时间,毕竟执行procrank 等命令也会消耗时间的。
#!/system/bin/sh if [ $# -eq 0 ];then echo "invalid param" echo "========usage========" echo "param: target outputfile intervel" echo "param: 目标 输出文件 数据采集间隔时间(秒)" echo "e.g." echo $0 target0,target1,target2... outputfile 3 echo $0 all /data/local/cpu_info_all.txt 4 echo $0 com.android.settings /data/local/cpu_info_all.txt 4 echo $0 com.android.settings,all,system_server /data/local/cpu_info_all.txt 5 exit 0 fi脚本输出
脚本输出一行一条记录,除了输出到控制台,同时输出到指定的内部文本,方便adb pull出来。
C:Userswalla>adb shell "/system/bin/get_cpu_info.sh all,system_server /data/local/tmp/cpuinfo 4" get cpu info, targets:all,system_server, output:/data/local/tmp/cpuinfo, intervel:4 2022-05-12 11:36:41 all 6 2022-05-12 11:36:41 system_server 0 2022-05-12 11:36:45 all 9 2022-05-12 11:36:45 system_server 1 2022-05-12 11:36:49 all 10 2022-05-12 11:36:50 system_server 1 2022-05-12 11:36:54 all 8 2022-05-12 11:36:54 system_server 0 2022-05-12 11:36:57 all 7 2022-05-12 11:36:57 system_server 0
C:Userswalla>adb shell "/system/bin/get_mem_info.sh all,system_server /data/local/tmp/meminfo 4" get mem info, targets:all,system_server, output:/data/local/tmp/meminfo, intervel:4 2022-05-12 11:35:39 all 263520K 2022-05-12 11:35:40 system_server 20335K 2022-05-12 11:35:45 all 263296K 2022-05-12 11:35:45 system_server 20335K 2022-05-12 11:35:51 all 263297K 2022-05-12 11:35:51 system_server 20335K 2022-05-12 11:35:57 all 263274K 2022-05-12 11:35:57 system_server 20335K 2022-05-12 11:36:03 all 263301K 2022-05-12 11:36:03 system_server 20335K 2022-05-12 11:36:09 all 263301K 2022-05-12 11:36:09 system_server 20335K
https://download.csdn.net/download/wallage_yeye/85354612
Android内存信息采集-Android文档类资源-CSDN下载



