Closed HEZI0427 closed 1 year ago
分析: 获取 scrcpy 运行pid
root@VM-46-13-centos:/data# adb -s 10.80.50.103:5555 shell ps -ef| grep 'udt-scrcpy-server'
shell 9659 403 0 10:42:44 ? 00:00:00 sh -c CLASSPATH=/data/local/tmp/udt/udt-scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.24 max_size=1080 bit_rate=1000000 max_fps=25 tunnel_forward=true rotation_autosync=true udt_socket_name=udt-scrcpy-server codec_options=duration=2
shell 9661 9659 1 10:42:44 ? 00:01:09 udt-scrcpy-server
查看当前占用(99M)
WeTestC2:/ # dumpsys meminfo 9661
Applications Memory Usage (in Kilobytes):
Uptime: 139286007 Realtime: 139286007
Pss Private Private Swap Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 8036 8036 0 0 0 0 0
Dalvik Heap 64492 64492 0 0 0 0 0
Dalvik Other 752 752 0 0
Stack 40 40 0 0
Ashmem 106 0 0 0
Other dev 24 0 24 0
.so mmap 7084 4116 448 0
.jar mmap 1106 0 16 0
.dex mmap 229 228 0 0
.oat mmap 497 76 0 0
.art mmap 14713 14708 0 0
Other mmap 364 68 0 0
Unknown 2188 2188 0 0
TOTAL 99631 94704 488 0 0 0 0
App Summary
Pss(KB)
------
Java Heap: 79200
Native Heap: 8036
Code: 4884
Stack: 40
Graphics: 0
Private Other: 3032
System: 4439
TOTAL: 99631 TOTAL SWAP (KB): 0
第一次启动时内存占用(37M)
Applications Memory Usage (in Kilobytes):
Uptime: 140998266 Realtime: 140998266
Pss Private Private Swap Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 5164 5164 0 0 0 0 0
Dalvik Heap 5900 5900 0 0 0 0 0
Dalvik Other 584 584 0 0
Stack 40 40 0 0
Ashmem 202 0 0 0
Other dev 16 0 16 0
.so mmap 7140 4124 496 0
.jar mmap 1272 0 44 0
.dex mmap 232 232 0 0
.oat mmap 459 76 0 0
.art mmap 14737 14708 12 0
Other mmap 385 60 0 0
Unknown 1728 1728 0 0
TOTAL 37859 32616 568 0 0 0 0
存在内存泄露
分析2: 需要实时dump scrcpy程序内存占用 方案一:无需添加代码,但需要Android应用包名,scrcpy程序不支持此方法 https://juejin.cn/post/6844904080691691533
方案二:在scrcpy中添加dump代码
android.os.Debug.dumpHprofData("/sdcard/data.hprof");
此时获取的hprof无法被MAT直接使用,需要转换,
<AndroidSDK>/platform-tools/hprof-conv data.hprof data-android.hprof
通过MAT打开转换后的hprof文件
分析3:
org.libjpegturbo.turbojpeg.TJCompressor
为例,查看泄漏堆栈
初步确定内线程内持有外部类对象没有及时释放
分析5: 测试2小时(10次),测试结束后,内存维持在37M左右
WeTestC2:/sdcard # dumpsys meminfo 29691
Applications Memory Usage (in Kilobytes):
Uptime: 142712995 Realtime: 142712995
Pss Private Private Swap Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 6076 6076 0 0 0 0 0
Dalvik Heap 4328 4328 0 0 0 0 0
Dalvik Other 484 484 0 0
Stack 40 40 0 0
Other dev 17 0 16 0
.so mmap 7721 4124 524 0
.jar mmap 1489 0 36 0
.dex mmap 232 232 0 0
.oat mmap 524 76 0 0
.art mmap 14739 14708 16 0
Other mmap 442 68 0 0
Unknown 1732 1732 0 0
TOTAL 37824 31868 592 0 0 0 0
无设计之外重复大内存对象
现象: