摘自https://www.cnblogs.com/zl1991/p/6644998.html,感谢原创作者!!!
1、adb shell procrank
PID Vss Rss Pss Uss cmdline从以上打印可以看出,一般来说内存占用大小有如下规律:VSS>= RSS >= PSS >= USS
2、使用dumpsys meminfo查看内存信息(主要看PSS实际使用的物理内存)
1)adb shell dumpsys meminfo
Applications Memory Usage (in Kilobytes):
Uptime: 131906712 Realtime: 353812965
Total PSS by process:
276,504K: com.ss.android.article.news (pid 32657 / activities)
210,447K: com.tencent.mobileqq (pid 25910 / activities)
155,494K: com.gionee.amisystem (pid 2732 / activities)
146,896K: com.android.systemui (pid 1718 / activities)
143,721K: com.job.android (pid 25331 / activities)
133,167K: system (pid 1362)
100,832K: com.hupu.games (pid 31886 / activities)
93,864K: com.tencent.mobileqq:tool (pid 3538)
87,357K: com.android.settings (pid 25507 / activities)
84,131K: com.baidu.input_gionee (pid 27694)
79,149K: com.tencent.mm (pid 31414)
************************************************
Total PSS by OOM adjustment:
233,722K: Native
41,724K: surfaceflinger (pid 385)
36,643K: cameraserver (pid 542)
15,773K: audioserver (pid 540)
9,159K: vtservice (pid 519)
7,495K: mediaserver (pid 550)
5,683K: zygote (pid 539)
5,648K: teei_daemon (pid 341)
5,616K: zygote64 (pid 538)
5,445K: logd (pid 344)
5,247K: media.codec (pid 520)
4,926K: mtk_agpsd (pid 533)
4,812K: mtkmal (pid 383)
4,565K: media.extractor (pid 549)
3,624K: rilproxy (pid 1125)
3,585K: mnld (pid 531)
3,359K: mtkrild (pid 948)
************************************
133,167K: System
133,167K: system (pid 1362)
371,643K: Persistent
146,896K: com.android.systemui (pid 1718 / activities)
44,705K: com.android.camera (pid 2647)
42,521K: com.antiy.securityprovider (pid 2495)
****************************
210,447K: Foreground
210,447K: com.tencent.mobileqq (pid 25910 / activities)
91,537K: Visible
31,634K: com.tencent.mobileqq:MSF (pid 1509)
24,939K: com.tencent.mobileqq:TMAssistantDownloadSDKService (pid 27540)
20,909K: com.tencent.android.location (pid 2820)
7,237K: android.ext.services (pid 24105)
6,818K: com.gionee.gnwakeup (pid 2280)
115,448K: Perceptible
84,131K: com.baidu.input_gionee (pid 27694)
31,317K: com.gionee.secureime (pid 6059)
201,759K: Home
155,494K: com.gionee.amisystem (pid 2732 / activities)
34,807K: com.gionee.amisystem.yourpage (pid 3287)
11,458K: com.amigo.ai.engine (pid 3407)
117,498K: A Services
35,875K: com.job.android:pushcore (pid 1079)
30,969K: com.gionee.softmanager:remote (pid 2476)
27,539K: com.ss.android.article.news:push (pid 1292)
23,115K: com.ss.android.article.news:pushservice (pid 1334)
13,758K: Previous
13,758K: com.gionee.providers.weather (pid 23136)
801,842K: B Services
276,504K: com.ss.android.article.news (pid 32657 / activities)
143,721K: com.job.android (pid 25331 / activities)
59,550K: com.gionee.softmanager (pid 18770 / activities)
44,166K: com.gionee.systemmanager (pid 27845)
35,700K: com.hupu.games:monitorService (pid 32250)
34,504K: com.hupu.games:pushservice (pid 31976)
33,736K: com.job.android:pushservice (pid 25416)
32,966K: com.tencent.mm:push (pid 32346)
********************************************
663,301K: Cached
100,832K: com.hupu.games (pid 31886 / activities)
93,864K: com.tencent.mobileqq:tool (pid 3538)
87,357K: com.android.settings (pid 25507 / activities)
79,149K: com.tencent.mm (pid 31414)
64,416K: com.android.mms (pid 1453 / activities)
44,393K: android.process.acore (pid 2471)
39,333K: com.gionee.amisystem.yourpage:com.cn.xy (pid 31725)
25,239K: com.tencent.mobileqq:peak (pid 2682)
23,745K: com.android.calendar (pid 31804)
*************************
Total PSS by category:
688,642K: Native
569,096K: Dalvik
414,971K: .dex mmap
257,564K: .art mmap
223,664K: GL mtrack
215,430K: .so mmap
211,283K: Unknown
137,938K: Dalvik Other
72,846K: .apk mmap
*************************
Total RAM: 5,707,832K (status normal)
Free RAM: 2,591,901K ( 663,301K cached pss + 1,348,580K cached kernel + 240,536K free + 46,512K ion cached + 292,972K gpu cached)
Used RAM: 3,456,977K (2,290,821K used pss + 1,098,256K kernel + 32,768K trace buffer + 35,132K ion disp + 0K cma usage)
Lost RAM: -341,046K
Tuning: 256 (large 512), oom 322,560K, restore limit 107,520K (high-end-gfx)
2)查看某个app的内存信息
adb shell dumpsys meminfo com.tencent.mobileqq
Android程序内存被分为2部分:native和dalvik,dalvik就是我们平常说的java堆,我们创建的对象是在这里面分配的,而bitmap是直接在native上分配的,对于内存的限制是 native+dalvik 不能超过最大限制。Android程序内存一般限制在16M,当然也有24M的。
size: 总内存(物理内存、虚拟内存)大小(kb);
Allocated:已分配的内存代销(kb)
Free:表示剩余内存大小(kb)
PrivateDirty:非共享的,又不能放入disk的内存能大小。