我們知道可以用adb shell procrank打印手機中各個應用程序使用的內存。
PID Vss Rss Pss Uss cmdline
316 98528K 96608K 57850K 54484K system_server
529 75548K 75376K 39037K 36932K com.android.phone
28918 71572K 71468K 35549K 33364K com.android.email
1137 66128K 62780K 27800K 25676K com.miui.mihome2
623 61820K 61708K 25864K 23912K android.process.acore
437 65836K 61516K 25370K 23120K com.android.systemui
12528 56736K 54932K 20266K 18560K com.xiaomi.channel
552 50400K 50344K 14476K 12500K com.xiaomi.xmsf
509 47420K 47272K 14345K 12856K com.baidu.input
1243 44676K 44600K 12085K 10820K com.ijinshan.mguard
16285 48608K 43748K 11014K 9336K com.miui.mihome.lockscreen
3862 40784K 40664K 9192K 8020K com.google.process.gapps
16504 40376K 40296K 8598K 7180K com.tencent.WBlog
9045 40460K 40340K 8332K 7028K com.ijinshan.kbatterydoctor
16531 39244K 39156K 8233K 7212K cn.com.tc.assistant
606 38792K 38676K 6736K 5584K com.lbe.security.miui:service
16699 38320K 38192K 6697K 5464K com.sina.weibo.servant
16092 37444K 37324K 6408K 5324K com.android.exchange
PSS就是在手機正在運行中看到的佔用內存。
我們可以製作以下腳本,每秒鐘打印一次應用的內存使用情況,便於觀察應用對內存的使用情況。
com.miui.mihome2爲應用的包名,此處爲小米桌面。
文件名
trackmem.sh
文件內容:
while true; do
adb shell procrank | grep "com.miui.mihome2"sleep 1
done