内存分析的命令

Android procrank  (/system/xbin/procrank) 工具,能够列出进程所占用的内存使用情况。顺序为从高到低。

每个进程占用内存大小以 VSS,  RSS , PSS, USS 的形式列出。

为了简化描述,内存占用以页为单位表述,而不是字节。 通常每页为 4096 字节。

 

VSS ( 等同于 ps 命令列出的 VSZ) 是单个进程全部可访问的地址空间。

其大小包括可能还尚未在内存中驻留的部分。比如地址空间已经被 malloc 分配,但是还没有实际写入。

对于确定单个进程实际内存使用大小, VSS 用处不大。

 

RSS  是单个进程实际占用的内存大小。

RSS 易被误导的原因在于, 它包括了该进程所使用的所有共享库的全部内存大小。对于单个共享库, 尽管无论多少个进程使用,

实际该共享库只会被装入内存一次。

对于单个进程的内存使用大小, RSS  不是一个精确的描述。

 

PSS 不同于RSS,它只是按比例包含其所使用的共享库大小。

例如, 三个进程使用同一个占用 30 内存页的共享库。 对于三个进程中的任何一个,PSS 将只包括 10 个内存页。

PSS 是一个非常有用的数字,因为系统中全部进程以整体的方式被统计, 对于系统中的整体内存使用是一个很好的描述。

如果一个进程被终止, 其PSS 中所使用的共享库大小将会重新按比例分配给剩下的仍在运行并且仍在使用该共享库的进程。

此种计算方式有轻微的误差,因为当某个进程中止的时候, PSS 没有精确的表示被返还给整个系统的内存大小。

 

USS 是单个进程的全部私有内存大小。亦即全部被该进程独占的内存大小。

USS 是一个非常非常有用的数字, 因为它揭示了运行一个特定进程的真实的内存增量大小。

如果进程被终止, USS 就是实际被返还给系统的内存大小。

USS 是针对某个进程开始有可疑内存泄露的情况,进行检测的最佳数字。

 

  1. Usage: procrank [ -W ] [ -v | -r | -p | -u | -h ]  
  2.     -v  Sort by VSS.  
  3.     -r  Sort by RSS.  
  4.     -p  Sort by PSS.  
  5.     -u  Sort by USS.  
  6.         (Default sort order is PSS.)  
  7.     -R  Reverse sort order (default is descending).  
  8.     -w  Display statistics for working set only.  
  9.     -W  Reset working set of all processes.  
  10.     -h  Display this help screen.  
Usage: procrank [ -W ] [ -v | -r | -p | -u | -h ]
    -v  Sort by VSS.
    -r  Sort by RSS.
    -p  Sort by PSS.
    -u  Sort by USS.
        (Default sort order is PSS.)
    -R  Reverse sort order (default is descending).
    -w  Display statistics for working set only.
    -W  Reset working set of all processes.
    -h  Display this help screen.


 

  1. 1|root@android:/ # procrank  
  2. procrank  
  3.   PID      Vss      Rss      Pss      Uss  cmdline  
  4.  1780   48188K   36892K   21177K   18196K  system_server  
  5.  1953   44944K   36056K   17201K   14904K  com.android.systemui  
  6.  2109   51300K   34888K   15291K   12840K  com.android.launcher  
  7.  2248   32996K   32948K   14184K   12516K  com.tencent.qqpimsecure  
  8.  2913   29880K   29796K   11980K    9612K  android.process.acore  
  9.  1396   36280K   36168K   11762K    7552K  zygote  
  10.  2058   27200K   27132K   10204K    9120K  com.android.phone  
  11.  2352   26028K   25960K    9680K    8740K  com.wandoujia.phoenix2  
  12.  2670   25388K   25312K    8064K    6332K  com.sina.weibo  
  13.  2029   22276K   22204K    6700K    6040K  android.process.media  
  14.  2866   23504K   23428K    6161K    4424K  com.sina.weibo.servant  
  15.  2632   21700K   21624K    6071K    5384K  com.infinit.wostore.ui  
  16.  1398    8904K    8904K    5948K    5012K  /system/bin/mediaserver  
  17.  2484   21580K   21508K    5679K    4892K  com.android.email  
  18.  2704   20512K   20436K    5601K    4936K  com.tmall.wireless:core  
  19.  2399   20384K   20300K    4990K    4248K  com.android.contacts  
  20.  2746   20720K   20660K    4973K    4188K  com.android.browser  
  21.  2090   20376K   20320K    4805K    4084K  com.android.nfc  
  22.  2043   20516K   20448K    4753K    4012K  com.android.inputmethod.pinyin  
  23.  2200   20272K   20196K    4679K    3868K  com.android.settings  
  24.  2563   20028K   19952K    4492K    3640K  com.android.mms  
  25.  2788   19304K   19232K    4123K    3396K  com.android.calendar  
  26.  2436   19812K   19744K    4119K    3520K  com.android.providers.calendar  
  27.  2505   18724K   18648K    3973K    3460K  com.android.exchange  
  28.  2655   19588K   19516K    3972K    3320K  com.android.dazhihui  
  29.  2465   19816K   19736K    3894K    3160K  com.android.deskclock  
  30.  2233   18756K   18684K    3467K    2824K  com.android.music  
  31.  2605   17540K   17460K    2824K    2264K  com.android.SystemLog  
  32.  2157   17376K   17296K    2683K    2088K  com.android.location.fused  
  33.  2193   17156K   17076K    2663K    2124K  com.android.smspush  
  34.  2590   17364K   17280K    2662K    2092K  com.broadcom.phone.register  
  35.  2943   17112K   17036K    2653K    2056K  com.android.musicfx  
  36.  2619   17132K   17056K    2620K    2040K  com.android.voicedialer  
  37.  2073   17020K   16940K    2603K    1980K  com.broadcom.bt.app.fm  
  38.  2421   17132K   17056K    2530K    1976K  com.broadcom.app.autoupdate  
  39.  1395   33216K    3888K    1859K    1520K  /system/bin/surfaceflinger  
  40.  1394    6544K    3472K    1737K    1468K  /system/bin/rild  
  41.  1403    3216K    3212K    1673K    1524K  /system/bin/glgps  
  42.  2962    1660K    1660K    1413K    1408K  procrank  
  43.  1397    3200K    3200K    1133K     788K  /system/bin/drmserver  
  44.  2148    1604K    1604K     812K     792K  /system/bin/wpa_supplicant  
  45.  1392    1312K    1312K     514K     448K  /system/bin/netd  
  46.  1390    1176K    1176K     418K     360K  /system/bin/vold  
  47.  1400     892K     892K     295K     280K  /system/bin/keystore  
  48.  1450     532K     532K     258K     252K  /system/bin/sdcard  
  49.  1449     228K     228K     208K     208K  /sbin/adbd  
  50.  1408    3572K     500K     199K     172K  /system/bin/bkmgrd  
  51.     1     264K     264K     190K     144K  /init  
  52.  1401     536K     536K     176K     164K  /system/bin/akmdfs  
  53.  1405     444K     444K     169K     160K  /system/bin/usb_portd  
  54.  2905     480K     480K     160K     120K  /system/bin/sh  
  55.  1399     440K     440K     154K     148K  /system/bin/installd  
  56.  2387     392K     392K     149K     144K  uuids_sys  
  57.  1437     464K     464K     148K     108K  /system/bin/sh  
  58.  1393     424K     424K     143K     136K  /system/bin/debuggerd  
  59.  1023     184K     184K     130K      84K  /sbin/ueventd  
  60.  2287     440K     440K     124K      88K  sh  
  61.  2290     440K     440K     124K      88K  sh  
  62.  1389     336K     336K     109K     104K  /system/bin/servicemanager  
  63.  1406     360K     360K     106K     100K  /system/bin/atxd_proxy  
  64.  2289     340K     340K     105K     100K  /data/data/com.tencent.qqpimsecure/files/athena_v2.dat  
  65.                           ------   ------  ------  
  66.                          241715K  201748K  TOTAL  
  67.   
  68. RAM: 475520K total, 10412K free, 8104K buffers, 190720K cached, 244K shmem, 27252K slab  
  69. root@android:/ #  
1|root@android:/ # procrank
procrank
  PID      Vss      Rss      Pss      Uss  cmdline
 1780   48188K   36892K   21177K   18196K  system_server
 1953   44944K   36056K   17201K   14904K  com.android.systemui
 2109   51300K   34888K   15291K   12840K  com.android.launcher
 2248   32996K   32948K   14184K   12516K  com.tencent.qqpimsecure
 2913   29880K   29796K   11980K    9612K  android.process.acore
 1396   36280K   36168K   11762K    7552K  zygote
 2058   27200K   27132K   10204K    9120K  com.android.phone
 2352   26028K   25960K    9680K    8740K  com.wandoujia.phoenix2
 2670   25388K   25312K    8064K    6332K  com.sina.weibo
 2029   22276K   22204K    6700K    6040K  android.process.media
 2866   23504K   23428K    6161K    4424K  com.sina.weibo.servant
 2632   21700K   21624K    6071K    5384K  com.infinit.wostore.ui
 1398    8904K    8904K    5948K    5012K  /system/bin/mediaserver
 2484   21580K   21508K    5679K    4892K  com.android.email
 2704   20512K   20436K    5601K    4936K  com.tmall.wireless:core
 2399   20384K   20300K    4990K    4248K  com.android.contacts
 2746   20720K   20660K    4973K    4188K  com.android.browser
 2090   20376K   20320K    4805K    4084K  com.android.nfc
 2043   20516K   20448K    4753K    4012K  com.android.inputmethod.pinyin
 2200   20272K   20196K    4679K    3868K  com.android.settings
 2563   20028K   19952K    4492K    3640K  com.android.mms
 2788   19304K   19232K    4123K    3396K  com.android.calendar
 2436   19812K   19744K    4119K    3520K  com.android.providers.calendar
 2505   18724K   18648K    3973K    3460K  com.android.exchange
 2655   19588K   19516K    3972K    3320K  com.android.dazhihui
 2465   19816K   19736K    3894K    3160K  com.android.deskclock
 2233   18756K   18684K    3467K    2824K  com.android.music
 2605   17540K   17460K    2824K    2264K  com.android.SystemLog
 2157   17376K   17296K    2683K    2088K  com.android.location.fused
 2193   17156K   17076K    2663K    2124K  com.android.smspush
 2590   17364K   17280K    2662K    2092K  com.broadcom.phone.register
 2943   17112K   17036K    2653K    2056K  com.android.musicfx
 2619   17132K   17056K    2620K    2040K  com.android.voicedialer
 2073   17020K   16940K    2603K    1980K  com.broadcom.bt.app.fm
 2421   17132K   17056K    2530K    1976K  com.broadcom.app.autoupdate
 1395   33216K    3888K    1859K    1520K  /system/bin/surfaceflinger
 1394    6544K    3472K    1737K    1468K  /system/bin/rild
 1403    3216K    3212K    1673K    1524K  /system/bin/glgps
 2962    1660K    1660K    1413K    1408K  procrank
 1397    3200K    3200K    1133K     788K  /system/bin/drmserver
 2148    1604K    1604K     812K     792K  /system/bin/wpa_supplicant
 1392    1312K    1312K     514K     448K  /system/bin/netd
 1390    1176K    1176K     418K     360K  /system/bin/vold
 1400     892K     892K     295K     280K  /system/bin/keystore
 1450     532K     532K     258K     252K  /system/bin/sdcard
 1449     228K     228K     208K     208K  /sbin/adbd
 1408    3572K     500K     199K     172K  /system/bin/bkmgrd
    1     264K     264K     190K     144K  /init
 1401     536K     536K     176K     164K  /system/bin/akmdfs
 1405     444K     444K     169K     160K  /system/bin/usb_portd
 2905     480K     480K     160K     120K  /system/bin/sh
 1399     440K     440K     154K     148K  /system/bin/installd
 2387     392K     392K     149K     144K  uuids_sys
 1437     464K     464K     148K     108K  /system/bin/sh
 1393     424K     424K     143K     136K  /system/bin/debuggerd
 1023     184K     184K     130K      84K  /sbin/ueventd
 2287     440K     440K     124K      88K  sh
 2290     440K     440K     124K      88K  sh
 1389     336K     336K     109K     104K  /system/bin/servicemanager
 1406     360K     360K     106K     100K  /system/bin/atxd_proxy
 2289     340K     340K     105K     100K  /data/data/com.tencent.qqpimsecure/files/athena_v2.dat
                          ------   ------  ------
                         241715K  201748K  TOTAL

RAM: 475520K total, 10412K free, 8104K buffers, 190720K cached, 244K shmem, 27252K slab
root@android:/ #
 
 

meminfo

命令:cat /proc/meminfo

实例:

MemTotal:         234312 kB

MemFree:            3448 kB

Buffers:              92 kB

Cached:            18052 kB

SwapCached:        25556 kB

Active:            50564 kB

Inactive:          50236 kB

Active(anon):      41924 kB

Inactive(anon):    41968 kB

Active(file):       8640 kB

Inactive(file):     8268 kB

Unevictable:        1164 kB

Mlocked:           17028 kB

HighTotal:             0 kB

HighFree:              0 kB

LowTotal:         234312 kB

LowFree:            3448 kB

SwapTotal:        196604 kB

SwapFree:         114384 kB

Dirty:                 0 kB

Writeback:             0 kB

AnonPages:         83900 kB

Mapped:            53944 kB

Shmem:                44 kB

Slab:              17540 kB

SReclaimable:       5828 kB

SUnreclaim:        11712 kB

KernelStack:        4184 kB

PageTables:         5304 kB

NFS_Unstable:          0 kB

Bounce:                0 kB

WritebackTmp:          0 kB

CommitLimit:      313760 kB

Committed_AS:    2792956 kB

VmallocTotal:     778240 kB

VmallocUsed:      115160 kB

VmallocChunk:     405852 kB

 

解释:

MemTotal: 所有可用RAM大小 (即物理内存减去一些预留位和内核的二进制代码大小)     MemFree: LowFree与HighFree的总和     Buffers: 用来给块设备做的缓冲大小(只记录文件系统的metadata以及 tracking in-flight pages,就是说 buffers是用来存储,目录里面有什么内容,权限等等。)     Cached: 用来给文件做缓冲大小(直接用来记忆我们打开的文件). 它不包括SwapCached     SwapCached: 已经被交换出来的内存,但仍然被存放在swapfile中。用来在需要的时候很快的被替换而不需要再次打开I/O端口。     Active: 最近经常被使用的内存,除非非常必要否则不会被移作他用.     Inactive: 最近不经常被使用的内存,非常用可能被用于其他途径.     HighTotal:     HighFree: 高位内存是指所有在860MB以上的内存空间,该区域主要用于用户空间的程序或者是缓存页面。内核必须使用不同的手法使用该段内存,因此它比低位内存要慢一些。     LowTotal:     LowFree: 低位可以达到高位内存一样的作用,而且它还能够被内核用来记录一些自己的数据结构。                    Among many other things, it is where everything from the Slab is                    allocated.  Bad things happen when you're out of lowmem.     SwapTotal: 交换空间的总和     SwapFree: 从RAM中被替换出暂时存在磁盘上的空间大小     Dirty: 等待被写回到磁盘的内存大小。     Writeback: 正在被写回到磁盘的内存大小。     Mapped: 影射文件的大小。     Slab: 内核数据结构缓存     VmallocTotal: vmalloc内存大小     VmallocUsed: 已经被使用的虚拟内存大小。     VmallocChunk: largest contigious block of vmalloc area which is free     CommitLimit: Based on the overcommit ratio('vm.overcommit_ratio'),               this is the total amount of  memory currently available to               be allocated on the system. This limit is only adhered to               if strict overcommit accounting is enabled (mode 2 in               'vm.overcommit_memory').               The CommitLimit is calculated with the following formula:               CommitLimit = ('vm.overcommit_ratio' * Physical RAM) + Swap               For example, on a system with 1G of physical RAM and 7G               of swap with a `vm.overcommit_ratio` of 30 it would               yield a CommitLimit of 7.3G.               For more details, see the memory overcommit documentation               in vm/overcommit-accounting.              Committed_AS: The amount of memory presently allocated on the system. The committed memory is a sum of all of the memory which               has been allocated by processes, even if it has not been               "used" by them as of yet. A process which malloc()'s 1G               of memory, but only touches 300M of it will only show up               as using 300M of memory even if it has the address space               allocated for the entire 1G. This 1G is memory which has               been "committed" to by the VM and can be used at any time               by the allocating application. With strict overcommit               enabled on the system (mode 2 in 'vm.overcommit_memory'),               allocations which would exceed the CommitLimit (detailed               above) will not be permitted. This is useful if one needs               to guarantee that processes will not fail due to lack of               memory once that memory has been successfully allocated.     VmallocTotal: 可以vmalloc虚拟内存大小     VmallocUsed: 已经被使用的虚拟内存大小。     VmallocChunk: largest contigious block of vmalloc area which is free

提示:

使用adb shell cat /proc/meminfo 命令,查看剩余的空间还有多少,通常的系统剩余空间是: MemFree + cached

      如下看到的系统剩余空间是:5616K + 158632K
        cat proc/meminfo           MemTotal:         483724 kB           MemFree:            5616 kB           Buffers:            2732 kB           Cached:           158632 kB           SwapCached:            0 kB           Active:           277336 kB           Inactive:          83232 kB          Active(anon):     197452 kB
        需要注意的是,在setting->apps->running app里面看到的剩余空间是上述MemFree + cached + background running app memory - SECOND_SERVER_MEM,具体的计算方法参考:RunningProcessView.java(/alps/package/apps/settings/src/com/android/setting/applications)里面的void refreshUi(boolean dataChanged)函数
 
 
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值