1.可以使用adb shell showmap pid查看一个进程的showmap,这对于我们来说非常有用,可以确定进程中哪些库占用内存比较多
1,确定app进程号,通过jarvis过滤,ps-A显示全部进程
ps命令使用
cmd通过adb shell进入与移动设备的命令交互界面。 然后使用ps指令, 最常用的是ps -aux和ps -ef与grep混合用, 筛选要查找的进程信息ps -ef|grep "筛选的进程字符" adb shell ps|more 显示全部进程信息(加|more为了分页显示)
筛选需要的进程信息 adb shell ps -ef |findstr "筛选进程信息" ps: adb shell ps -ef |findstr "baidu"
g6sa:/ # ps -A | grep jarvis
ps -A | grep jarvis
u0_a37 21979 2223 3858620 193980 SyS_epoll_wait 0 S cn.alios.jarvisd
u0_a47 22750 2223 3829168 172756 SyS_epoll_wait 0 S com.ebanma.jarvis
2,showmap
可以通过adb shell showmap 22750 > log7.txt 将info保存到日志里
adb shell showmap 22750virtual shared shared private privatesize RSS PSS clean dirty clean dirty swap swapPSS # object
-------- -------- -------- -------- -------- -------- -------- -------- -------- ---- ------------------------------336 336 103 336 0 0 0 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/base.apk44 44 44 0 0 36 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libBroadcastSignal.so44 44 44 0 0 36 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libCarVapiSignal.so268 268 268 0 0 252 16 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libCosmoSignal.so96 88 88 0 0 80 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libDistributeActuator.so592 356 356 0 0 340 16 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libLbsFenceActuator.so164 164 164 0 0 152 12 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libLbsSignal.so44 44 44 0 0 36 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libMapSignal.so48 48 48 0 0 40 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libStatusActuator.so52 52 52 0 0 44 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libStatusSignal.so56 56 56 0 0 48 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libalios_log.so20 20 20 0 0 12 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libatrace.so348 244 244 0 0 228 16 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libbase.so892 656 656 0 0 620 36 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libc++_shared.so1904 1012 1012 0 0 848 164 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libcrypto.so40 40 40 0 0 32 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libfreexl.so1684 732 732 0 0 668 64 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libgeos.so464 68 68 0 0 64 4 0 0 2 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libicudata.so1416 724 724 0 0 680 44 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libidot.so21960 15624 15624 0 0 15136 488 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjarvis_engine.so936 916 916 0 0 880 36 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjarvis_items.so360 352 352 0 0 336 16 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjarvisbase.so140 68 68 0 0 64 4 0 0 2 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjarvisdlzma.so1472 248 248 0 0 204 44 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjarvisdxml2.so88 72 72 0 0 64 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjarvisdz.so84 84 84 0 0 76 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjarvisjniloader.so168 160 160 0 0 152 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libjsoncpp.so304 76 76 0 0 64 12 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libproj.so32 32 32 0 0 24 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libproperties.so1220 1136 1136 0 0 1108 28 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libsgmainso-5.4.193.so5204 128 128 0 0 112 16 0 0 2 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libspatialite.so1324 1160 1160 0 0 1140 20 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libsqlite3.so164 164 164 0 0 156 8 0 0 3 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/lib/arm64/libuv.so4 4 4 0 0 4 0 0 0 1 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/oat/arm64/base.art72 72 72 0 0 68 4 0 0 4 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/oat/arm64/base.odex3540 3028 3028 0 0 3028 0 0 0 1 /data/app/com.ebanma.jarvis-49tUzEJIztwJUQdjlSRzhg==/oat/arm64/base.vdex17152 17108 1784 14300 1412 0 1396 0 0 3 /data/dalvik-cache/arm64/system@framework@boot.art
2.dumpsys meminfo分析
Applications Memory Usage (in Kilobytes):
Uptime: 11439815 Realtime: 11439815** MEMINFO in pid 22750 [com.ebanma.jarvis] **Pss Private Private SwapPss Heap Heap HeapTotal Dirty Clean Dirty Size Alloc Free------ ------ ------ ------ ------ ------ ------Native Heap 14246 14188 0 0 20480 14419 6060Dalvik Heap 2342 2004 0 0 3901 1951 1950Dalvik Other 893 892 0 0 Stack 44 44 0 0 Ashmem 2 0 0 0 Other dev 13 0 12 0 .so mmap 26613 1404 23732 0 .apk mmap 383 0 12 0 .ttf mmap 23 0 0 0 .dex mmap 3926 8 3336 0 .oat mmap 910 0 0 0 .art mmap 1722 1392 4 0 Other mmap 190 4 36 0 GL mtrack 7005 7005 0 0 Unknown 1666 1628 0 0 TOTAL 59978 28569 27132 0 24381 16370 8010App SummaryPss(KB)------Java Heap: 3400Native Heap: 14188Code: 28492Stack: 44Graphics: 7005Private Other: 2572System: 4277TOTAL: 59978 TOTAL SWAP PSS: 0ObjectsViews: 19 ViewRootImpl: 1AppContexts: 5 Activities: 1Assets: 3 AssetManagers: 0Local Binders: 22 Proxy Binders: 31Parcel memory: 9 Parcel count: 38Death Recipients: 6 OpenSSL Sockets: 5WebViews: 0SQLMEMORY_USED: 0PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 117
3,cpu占用率分析
top -d 5 | grep 17618 设置top频率5s一次
top -d 5 | grep 17618
18101 shell 20 0 8.8M 6.2M 1.8M S 0.0 0.1 0:00.01 grep 17618
17618 u0_a56 10 -10 3.6G 169M 134M S 0.0 3.2 0:03.64 com.ebanma.jarv+
17618 u0_a56 10 -10 3.6G 169M 134M S 0.6 3.2 0:03.64 com.ebanma.jarv+
[H[JTasks: 356 total, 1 running, 286 sleeping, 0 stopped, 1 zombie
17618 u0_a56 10 -10 3.6G 171M 134M S 0.6 3.2 0:03.70 com.ebanma.jarv+
17618 u0_a56 10 -10 3.6G 175M 134M S 0.8 3.3 0:03.77 com.ebanma.jarv+
[H[JTasks: 358 total, 2 running, 287 sleeping, 0 stopped, 1 zombie
17618 u0_a56 10 -10 3.6G 170M 134M S 0.4 3.2 0:03.83 com.ebanma.jarv+
17618 u0_a56 10 -10 3.6G 170M 134M S 0.4 3.2 0:03.86 com.ebanma.jarv+
18217 shell 20 0 8.8M 6.2M 1.9M S 0.4 0.1 0:00.01 grep 17618
[H[JTasks: 357 total, 2 running, 287 sleeping, 0 stopped, 1 zombie
18101 shell 20 0 8.8M 6.2M 1.8M S 0.2 0.1 0:00.01 grep 17618
也可查看占用cpu最高的前10个程序(-t 显示进程名称,-s 按指定行排序,-n 在退出前刷新几次,-d 刷新间隔,-m 显示最大数量):
top -m 10 -s 9 (数字9代表按照cpu占用率排序,-s后面只能跟数字)
做cpu占用率测试时需要执行一些命令辅助我们测试,比如每隔500ms发一次广播,可以借助脚本:
while true
doadb shell am broadcast -a android.intent.action.openTinyAppp -e data datavaluesleep 0.5secho '+++++++++++++++++++'
done