在Android系统开发过程中,经常会要去分析进程的内存的使用情况,简单介绍下Android内存分析的相关工具。

文章参考:

1.dumpsys

2.memory-analysis-command

1.内存的指标

Item 全称 描述 类型
USS Unique Set Size 进程独占的内存(不包含共享库占用的内存) 物理内存
PSS Proportional Set Size 进程独占 + 比例分配共享库占用的内存 物理内存
RSS Resident Set Size 进程独占 + 共享库占用的内存 物理内存
VSS Virtual Set Size RSS + 未分配的物理内存 虚拟内存

2.内存分析工具

2.1 proc/meminfo

查看详细的内存信息

# cat /proc/meminfoMemTotal:        3938668 kB
MemFree:         2766932 kB
MemAvailable:    3366724 kB
Buffers:           54764 kB
Cached:           683932 kB
SwapCached:            0 kB
Active:           468604 kB
Inactive:         493776 kB
Active(anon):     226044 kB
Inactive(anon):   114680 kB
Active(file):     242560 kB
Inactive(file):   379096 kB
Unevictable:         256 kB
Mlocked:             256 kB
SwapTotal:       1969000 kB
SwapFree:        1969000 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        223980 kB
Mapped:           376328 kB
Shmem:            117060 kB
Slab:             119740 kB
SReclaimable:      80184 kB
SUnreclaim:        39556 kB
KernelStack:       11872 kB
PageTables:        15752 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     3938332 kB
Committed_AS:   40624220 kB
VmallocTotal:   258867136 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
CmaTotal:          16384 kB
CmaFree:           13892 kB
  • MemTotal:表示系统内存总数

    系统从上电启动到引导完成,内核中需要保留部分内存,剩下的内存总数即为 MemTotal,这个值在系统运行期间保持不变。

  • MemFree:空闲内存总数

    表示系统中尚未使用的内存, MemTotal - MemFree 表示已经用掉的内存。

  • MemAvailable:可用内存

    应用程序可用内存数,系统中存在一些已经被使用但是可以回收的内存,比如Buffers、Cached和slab的部分,所以 MemFree 不能代表全部可用的内存,加上可以回收的内存才是系统可用内存的总和。

    比如 MemAvailable ≈ MemFree + Buffers + Cached,这里是内核计算出来的估值。MemFree表示系统层面,MemAvailable泛指应用层面。

  • Buffers:缓冲区内存

  • Cached:缓存区内存

2.2 free

# freetotal        used        free      shared     buffers
Mem:       4033196032  1199968256  2833227776   119869440    56078336
-/+ buffers/cache:     1143889920  2889306112
Swap:      2016256000           0  2016256000# free -mtotal        used        free      shared     buffers
Mem:             3846        1144        2701         114          53
-/+ buffers/cache:           1091        2755
Swap:            1922           0        1922

轻量级的内存查看工具,内容来源于proc/meminfo.

Mem.total = Mem.used + Mem.free,即 3846 = 1144 + 2701;

Mem.used - Mem.buffers = buffers.used,即 1144 - 53 = 1091;

Mem.free + Mem.buffers = buffers.free, 即 2701 + 53 = 2755;

2.3 dumpsys meminfo

输出的结果大致按照4个部分排序,分别Total PSS by process、Total PSS by OOM adjustment、Total PSS by category 和 Total RAM.

Total PSS by process:以进程的PSS从大到小排序

Total PSS by OOM adjustment:分别显示每个类型进程的情况,Native/System/Persistent/Foreground/Visible/Perceptible/A Services/Home/B Services/Cached.

Total PSS by category:以Dalvik/Native/.art mmap/.dex map等划分的各类进程的总PSS情况

Total:显示总内存、可用内存、已使用内存、其他内存.

# dumpsys meminfoApplications Memory Usage (in Kilobytes):
Uptime: 18012360 Realtime: 92063532Total PSS by process:93,509K: system (pid 469)79,586K: com.android.systemui (pid 628)63,474K: zygote (pid 378)32,858K: com.android.launcher3 (pid 1054 / activities)28,094K: zygote64 (pid 377)25,557K: webview_zygote32 (pid 687)25,377K: com.android.phone (pid 749)18,679K: android.hardware.neuralnetworks@1.0-service-armnn (pid 263)15,488K: com.android.inputmethod.latin (pid 606)13,830K: surfaceflinger (pid 269)13,543K: android.process.media (pid 1170)12,843K: com.android.email (pid 1302)10,147K: android.hardware.camera.provider@2.4-service (pid 255)9,675K: android.rockchip.update.service (pid 1140)8,219K: com.android.calendar (pid 1850)8,027K: com.android.providers.calendar (pid 1284)7,646K: mediaserver (pid 387)6,977K: com.android.quicksearchbox (pid 1190)6,827K: com.android.mtp (pid 1876)6,820K: media.codec (pid 391)6,675K: com.android.printspooler (pid 1021)6,587K: audioserver (pid 379)6,504K: com.cghs.stresstest (pid 1011)6,449K: media.extractor (pid 385)6,246K: android.ext.services (pid 1407)5,812K: com.android.keychain (pid 1114)5,633K: com.android.smspush (pid 1069)4,095K: android.hardware.audio@2.0-service (pid 253)3,916K: cameraserver (pid 380)3,191K: media.metrics (pid 386)2,998K: android.hardware.graphics.composer@2.1-service (pid 261)2,910K: logd (pid 232)2,803K: drmserver (pid 381)2,789K: android.hardware.wifi@1.0-service (pid 266)2,442K: android.hardware.drm@1.0-service (pid 258)2,405K: vold (pid 245)2,214K: netd (pid 388)1,970K: android.hardware.drm@1.0-service.widevine (pid 259)1,799K: keystore (pid 383)1,798K: installd (pid 382)1,707K: /init (pid 1)1,642K: hwservicemanager (pid 234)1,509K: adbd (pid 1841)1,497K: wificond (pid 390)1,430K: android.hardware.sensors@1.0-service (pid 265)1,410K: android.hardware.keymaster@3.0-service (pid 244)1,276K: mediadrmserver (pid 384)1,243K: android.hardware.graphics.allocator@2.0-service (pid 260)1,241K: ip6tables-restore (pid 403)1,234K: gatekeeperd (pid 393)1,163K: iptables-restore (pid 402)1,158K: ueventd (pid 207)1,133K: thermalserviced (pid 270)1,082K: storaged (pid 389)1,034K: android.hardware.bluetooth@1.0-service (pid 254)1,009K: android.hardware.configstore@1.0-service (pid 257)1,005K: android.hardware.cas@1.0-service (pid 256)985K: healthd (pid 267)888K: android.hardware.light@2.0-service (pid 262)861K: android.hardware.power@1.0-service (pid 264)839K: servicemanager (pid 233)801K: vndservicemanager (pid 235)770K: dumpsys (pid 2032)759K: android.hidl.allocator@1.0-service (pid 252)733K: sh (pid 1983)724K: sh (pid 274)676K: lmkd (pid 268)658K: tombstoned (pid 395)Total PSS by OOM adjustment:253,080K: Native63,474K: zygote (pid 378)28,094K: zygote64 (pid 377)25,557K: webview_zygote32 (pid 687)18,679K: android.hardware.neuralnetworks@1.0-service-armnn (pid 263)13,830K: surfaceflinger (pid 269)10,147K: android.hardware.camera.provider@2.4-service (pid 255)7,646K: mediaserver (pid 387)6,820K: media.codec (pid 391)6,587K: audioserver (pid 379)6,449K: media.extractor (pid 385)4,095K: android.hardware.audio@2.0-service (pid 253)3,916K: cameraserver (pid 380)3,191K: media.metrics (pid 386)2,998K: android.hardware.graphics.composer@2.1-service (pid 261)2,910K: logd (pid 232)2,803K: drmserver (pid 381)2,789K: android.hardware.wifi@1.0-service (pid 266)2,442K: android.hardware.drm@1.0-service (pid 258)2,405K: vold (pid 245)2,214K: netd (pid 388)1,970K: android.hardware.drm@1.0-service.widevine (pid 259)1,799K: keystore (pid 383)1,798K: installd (pid 382)1,707K: /init (pid 1)1,642K: hwservicemanager (pid 234)1,509K: adbd (pid 1841)1,497K: wificond (pid 390)1,430K: android.hardware.sensors@1.0-service (pid 265)1,410K: android.hardware.keymaster@3.0-service (pid 244)1,276K: mediadrmserver (pid 384)1,243K: android.hardware.graphics.allocator@2.0-service (pid 260)1,241K: ip6tables-restore (pid 403)1,234K: gatekeeperd (pid 393)1,163K: iptables-restore (pid 402)1,158K: ueventd (pid 207)1,133K: thermalserviced (pid 270)1,082K: storaged (pid 389)1,034K: android.hardware.bluetooth@1.0-service (pid 254)1,009K: android.hardware.configstore@1.0-service (pid 257)1,005K: android.hardware.cas@1.0-service (pid 256)985K: healthd (pid 267)888K: android.hardware.light@2.0-service (pid 262)861K: android.hardware.power@1.0-service (pid 264)839K: servicemanager (pid 233)801K: vndservicemanager (pid 235)770K: dumpsys (pid 2032)759K: android.hidl.allocator@1.0-service (pid 252)733K: sh (pid 1983)724K: sh (pid 274)676K: lmkd (pid 268)658K: tombstoned (pid 395)93,509K: System93,509K: system (pid 469)111,467K: Persistent79,586K: com.android.systemui (pid 628)25,377K: com.android.phone (pid 749)6,504K: com.cghs.stresstest (pid 1011)32,858K: Foreground32,858K: com.android.launcher3 (pid 1054 / activities)5,633K: Visible5,633K: com.android.smspush (pid 1069)15,488K: Perceptible15,488K: com.android.inputmethod.latin (pid 606)9,675K: B Services9,675K: android.rockchip.update.service (pid 1140)75,169K: Cached13,543K: android.process.media (pid 1170)12,843K: com.android.email (pid 1302)8,219K: com.android.calendar (pid 1850)8,027K: com.android.providers.calendar (pid 1284)6,977K: com.android.quicksearchbox (pid 1190)6,827K: com.android.mtp (pid 1876)6,675K: com.android.printspooler (pid 1021)6,246K: android.ext.services (pid 1407)5,812K: com.android.keychain (pid 1114)Total PSS by category:157,906K: .so mmap109,632K: Native106,914K: .dex mmap56,243K: .oat mmap44,939K: .apk mmap32,029K: .art mmap24,460K: Unknown23,246K: Dalvik18,957K: Other mmap11,423K: .ttf mmap7,471K: Dalvik Other2,288K: Stack879K: Other dev320K: Ashmem172K: .jar mmap0K: Cursor0K: Gfx dev0K: EGL mtrack0K: GL mtrack0K: Other mtrackTotal RAM: 3,938,668K (status normal)Free RAM: 3,283,817K (   75,169K cached pss +   442,724K cached kernel + 2,765,924K free)Used RAM:   750,258K (  521,710K used pss +   228,548K kernel)Lost RAM:   -95,419KZRAM:        12K physical used for         0K in swap (1,969,000K total swap)Tuning: 192 (large 512), oom   322,560K, restore limit   107,520K (high-end-gfx)

2.4 procrank

获取所有进程的内存使用的排行榜,排行是以Pss的大小而排序.

# procrankPID       Vss      Rss      Pss      Uss  cmdline469  4715244K  199568K   93953K   76772K  system_server628  4774604K  184272K   79868K   63260K  com.android.systemui378  1581340K  116848K   63536K   35956K  zygote1054  5048780K  130504K   33086K   20376K  com.android.launcher3377  4239348K  130300K   28338K    8012K  zygote64687  1333924K   54604K   25609K    5504K  /system/bin/webview_zygote32749  4338336K  108900K   25539K   16612K  com.android.phone263    75200K   27620K   18690K   16088K  /vendor/bin/hw/android.hardware.neuralnetworks@1.0-service-armnn606  4330764K   91380K   15649K    9656K  com.android.inputmethod.latin269   312884K   27868K   13869K   10336K  /system/bin/surfaceflinger1170  4321764K   92900K   13701K    6336K  android.process.media1302  4323936K   84736K   13004K    8064K  com.android.email255    53284K   21308K   10199K    6972K  /vendor/bin/hw/android.hardware.camera.provider@2.4-service1140  4317440K   82832K    9876K    3808K  android.rockchip.update.service1850  4318536K   75692K    8379K    4096K  com.android.calendar1284  4315752K   77148K    8185K    3796K  com.android.providers.calendar387    73924K   18420K    7686K    5064K  /system/bin/mediaserver1190  4315400K   71948K    7137K    2800K  com.android.quicksearchbox1876  4315996K   74824K    6986K    2668K  com.android.mtp391    31860K   12104K    6845K    5644K  media.codec1021  4315960K   70452K    6835K    3020K  com.android.printspooler1011  4314012K   69076K    6658K    2864K  com.cghs.stresstest379    43520K   12616K    6621K    4920K  /system/bin/audioserver385  2164032K   18588K    6493K    4324K  media.extractor1407  4315816K   70584K    6403K    2296K  android.ext.services1114  4314788K   69144K    5972K    2240K  com.android.keychain1069  4313648K   67308K    5792K    2156K  com.android.smspush253    16256K    7892K    4116K    2808K  /vendor/bin/hw/android.hardware.audio@2.0-service380    24908K   11124K    3948K    2544K  /system/bin/cameraserver386  2128240K   11312K    3220K    2156K  media.metrics261    33120K    7556K    3022K    2432K  /vendor/bin/hw/android.hardware.graphics.composer@2.1-service232    19996K    5304K    2915K    2820K  /system/bin/logd381    18964K    9884K    2836K    1652K  /system/bin/drmserver266    14404K    6140K    2798K    2604K  /vendor/bin/hw/android.hardware.wifi@1.0-service258    12756K    6560K    2463K    1904K  /vendor/bin/hw/android.hardware.drm@1.0-service245    55064K    7468K    2421K    2024K  /system/bin/vold388    31004K    6548K    2225K    1980K  /system/bin/netd259    11140K    5328K    1985K    1588K  /vendor/bin/hw/android.hardware.drm@1.0-service.widevine383    19280K    6492K    1811K    1348K  /system/bin/keystore382    19676K    5636K    1809K    1616K  /system/bin/installd1    11968K    2436K    1714K    1092K  /init234    14408K    5576K    1653K    1352K  /system/bin/hwservicemanager1841    12932K    1700K    1511K    1504K  /system/bin/adbd390    15096K    5632K    1507K    1312K  /system/bin/wificond265    16888K    5044K    1439K    1164K  /vendor/bin/hw/android.hardware.sensors@1.0-service244    14848K    5904K    1422K     928K  /vendor/bin/hw/android.hardware.keymaster@3.0-service384    10688K    5308K    1297K     804K  /system/bin/mediadrmserver260    17480K    5224K    1261K     960K  /vendor/bin/hw/android.hardware.graphics.allocator@2.0-service393    15560K    5612K    1245K    1000K  /system/bin/gatekeeperd403     9468K    3296K    1244K    1188K  /system/bin/ip6tables-restore402     9452K    3200K    1165K    1116K  /system/bin/iptables-restore207     6080K    1768K    1158K     568K  /sbin/ueventd2038    16940K    3304K    1145K    1088K  procrank270    13924K    5000K    1142K     944K  /system/bin/thermalserviced389    15988K    4292K    1090K     960K  /system/bin/storaged254    12244K    4212K    1042K     868K  /vendor/bin/hw/android.hardware.bluetooth@1.0-service256     9048K    4108K    1018K     596K  /vendor/bin/hw/android.hardware.cas@1.0-service257    15372K    4372K    1017K     828K  /vendor/bin/hw/android.hardware.configstore@1.0-service267    13464K    4504K     993K     860K  /system/bin/healthd262    12136K    4168K     896K     676K  /vendor/bin/hw/android.hardware.light@2.0-service264    12140K    4168K     870K     668K  /vendor/bin/hw/android.hardware.power@1.0-service233    10444K    3428K     848K     760K  /system/bin/servicemanager235    10244K    3256K     805K     696K  /vendor/bin/vndservicemanager252    12088K    4088K     767K     636K  /system/bin/hw/android.hidl.allocator@1.0-service1983     8932K    3008K     736K     548K  /system/bin/sh274     8932K    2944K     727K     540K  /system/bin/sh268     9180K    3072K     681K     624K  /system/bin/lmkd395     9028K    3004K     662K     600K  /system/bin/tombstoned------   ------  ------601566K  385996K  TOTALRAM: 3938668K total, 2765940K free, 54772K buffers, 683920K cached, 117060K shmem, 119748K slab

2.5 showmap

该命令的输出每一行代表一个虚拟地址区域(vm_area),内容基本和proc/pid/maps基本一致.

# showmap -a 1302start      end  virtual                     shared   shared  private  privateaddr     addr     size      RSS      PSS    clean    dirty    clean    dirty     swap  swapPSSobject-------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- ------------------------------
0b65b000 0b65c000        4        0        0        0        0        0        0        0        0 [anon:thread stack guard page]

start addr: 虚拟地址的起始地址
end addr: 虚拟地址的结束地址
virutal size: 占用虚拟内存大小
RSS:进程独占内存 + 共享库占用内存的物理内存
PSS:进程独占内存 + 比例分配共享库占用的物理内存
shared:共享数据
private:私有数据

2.6 vmstat

不仅可以查看内存情况,还可以查看进程运行队列、系统切换、CPU时间占比等情况.

转载于:https://www.cnblogs.com/tinylaker/p/10574899.html

Android内存分析工具相关推荐

  1. Android内存分析工具:Memory Profiler

    一.前言  我们知道,Android系统检测到app有不再使用对象时,就会进行内存回收相关的工作. 尽管Android检测无用对象.回收内存的方法在不断改进,  但在目前所有的Android版本中,进 ...

  2. Android内存分析工具集【8】-TraceView

    常用的性能检测工具是traceview,集成于 Android Device Monitor 中.从Android Studio3.0开始, Android Device Monitor 被废弃,取而 ...

  3. android 内存分析工具_Android Camera内存问题剖析

    本文通过一类 Android 机型上相机拍摄过程中的 native 内存 OOM 的问题展开,借助内存快照裁剪回捞和 Native 内存监控工具的赋能,来深入剖析此类问题. 背景 Raphael 是西 ...

  4. 图解Android 内存分析工具之Mat使用教程

    2019独角兽企业重金招聘Python工程师标准>>>                 感觉程序员都不太喜欢文字多的阅读,所以用图表达更简单易懂. 1.  安装 http://dow ...

  5. android dumpsys 分析,Android内存分析工具-dumpsys meminfo

    首先来看怎么使用 执行如下shell adb shell dumpsys meminfo [包名] 假如我们要跟踪的应用包名为com.laomou.memtest 在打开应用操作一段时间后,返回到桌面 ...

  6. 高效地分析Android内存--MAT工具解析

    欢迎Follow我的GitHub, 关注我的CSDN. 本文的合集已经编著成书,高级Android开发强化实战,欢迎各位读友的建议和指导.在京东即可购买:https://item.jd.com/123 ...

  7. Android内存分析和调优(上)

    Android内存分析和调优(上) Android内存分析和调优(上) Android内存分析工具(四):adb命令 posted on 2017-09-25 19:29 时空观察者9号 阅读(... ...

  8. MemoryAnalyzer(MAT)内存分析工具和Android Profiler的使用

    Android Profiler运行程序 下载堆内存 导出下载的内存 转换格式 cmd到SDK路径下:sdk/platform-tools/hprof-conv.exe ,使用hprof-conv 转 ...

  9. Android内存分析和调优

    最近我们的android app占用了大量内存,于是领导安排做减少内存占用的工作. 要优化内存,首先要做的就是分析内存占用情况.android提供了多个工具和命令进行内存分析. 第一层 Procran ...

  10. 内存分析工具MAT的使用

    原文链接:http://www.jianshu.com/p/d8e247b1e7b2 MAT简介 MAT(Memory Analyzer Tool),一个基于Eclipse的内存分析工具,是一个快速. ...

最新文章

  1. 命令行下安装的tensorflow怎么打开_CourseMaker微课制作教程18:录ppt一直“正在打开……”及WPS下ppt满屏放映怎么办?...
  2. 【报告分享】90后人群消费趋势研究报告.pdf
  3. MapReduce框架下的FP Growth算法详解
  4. python验证码图片生成
  5. Java Web 上应用良田高拍仪二次开发
  6. html5获取经纬度页面,html5获取经纬度
  7. 10只狗怎么鉴别1000瓶水哪瓶有毒
  8. Linux下通过虚拟网卡实现局域网 转发tcp/udp流量
  9. 批量查询快递物流,自动过滤重复的单号
  10. 如何处理Git中没有小绿勾的问题
  11. 仿热血江湖游戏Players装备加解锁功能未开放,请联系客服人员
  12. flannel 介绍(UTP、VXLAN、Host Gateway模式详解)
  13. Uboot SPL的Boot模式选择(从MMC切换到SPI启动)
  14. Android实现身份证识别
  15. 电脑端手机模拟器软件
  16. 前美团COO干嘉伟:好的管理,打得、骂得,又哄得
  17. PoE交换机的供电电压可否调整
  18. Hadoop的基本特点
  19. SAST——Checkmarx静态检测工具收集(2)
  20. 2022年1月17号~19号

热门文章

  1. BAT大牛亲授从零起步基于ElasticSearch的搜房网(前后端集成)实战(第二章需求分析和数据库设计)
  2. es文件浏览器访问ftp服务器,es文件浏览器如何ftp服务器
  3. 卡方检验python程序_卡方检验及其python实现
  4. 在线上传图片二维码识别解析
  5. 什么是代理服务器,代理ip池芝麻
  6. 路由器ipv4和ipv6转发原理
  7. S3C2410,ARM920T,试题总结
  8. CS5460基本读写程序(无bug版本)
  9. 神经网络学习的几种方法
  10. ASP.NET MVC后台判断是否是手机登录以及是否是微信公众号登陆