Android 分析system_server CPU高的方法
- 查看长时间运行的线程
busybox ps wlT| grep system_server
R 1000 4201 801 4848m 276m 0:0 14:59 02:41:35 {Thread-147} system_server
R 1000 4202 801 4848m 276m 0:0 14:59 02:41:41 {Thread-148} system_server
- 查看线程循环打印的内容
strace -p 4201
结果
read(283, 0x727e57ad60, 32) = -1 EIO (I/O error)
pselect6(284, [283], NULL, NULL, NULL, NULL) = 1 (in [283])
read(283, 0x727e57ad60, 32) = -1 EIO (I/O error)
pselect6(284, [283], NULL, NULL, NULL, NULL) = 1 (in [283])
read(283, 0x727e57ad60, 32) = -1 EIO (I/O error)
- 查看具体线程调用的方法
debuggerd -b 1028
1028是system_server的pid
结果
"Thread-147" sysTid=4201
#00 pc 000000000006fe78 /system/lib64/libc.so (__pselect6+8)
#01 pc 000000000002b948 /system/lib64/libc.so (select+144)
#02 pc 0000000000001894 /system/lib64/libjni_hid_raw.so (native_readReport(_JNIEnv*, _jobject*, int, _jstring*, _jbyteArray*, int)+108)
#03 pc 00000000006691f4 /data/dalvik-cache/arm64/system@framework@boot.oat (offset 0x625000)
"Thread-148" sysTid=4202
#00 pc 0000000000070864 /system/lib64/libc.so (read+4)
#01 pc 00000000000018ec /system/lib64/libjni_hid_raw.so (native_readReport(_JNIEnv*, _jobject*, int, _jstring*, _jbyteArray*, int)+196)
#02 pc 00000000006691f4 /data/dalvik-cache/arm64/system@framework@boot.oat (offset 0x625000)
可以看出来是libjni_hid_raw.so里面的native_readReport出问题了
查找JniUSbHidRaw.cpp–HidRawDeviceManager.java–HidRawDevice.java–start()方法里面有while(true)死循环
- 命令查找句柄是否被删除
cd /proc/4201/fd
lrwx------ 1 system system 64 2021-07-21 18:00 282 -> /dev/hidraw0 (deleted)
lr-x------ 1 system system 64 2021-07-21 18:00 283 -> /dev/hidraw0 (deleted)