Android 系统内存分析


能够列出进程所占用的内存使用情况。顺序为从高到低。
每个进程占用内存大小以 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 是针对某个进程开始有可疑内存泄露的情况,进行检测的最佳数字。

procrank的基本功能

如下图:

        


procrank的使用

shell@xxxxxxxxxx:/ # procrank                                               
  PID       Vss      Rss      Pss      Uss  cmdline
 1645   462296K  101904K   75617K   73092K  com.oslauncher
 1944   437272K   76368K   36017K   25136K  com.dangbeimarket
10745   362920K   48664K   23951K   21948K  com.audiocn.kalaok.tv
 1426   414912K   50272K   22969K   19336K  system_server
 1010   419416K   18056K   17332K   17100K  /applications/bin/tvos
  987    73360K   18992K   13801K   12400K  /system/bin/mediaserver
10475   391460K   40152K   13667K   11724K  com.android.launcher
  985   308084K   43976K   13366K    8300K  zygote
10437   345864K   35064K   12858K   11500K  com.android.mediacenter
 4185   326280K   33972K   12737K   11332K  com.android.systemui:screenshot
10943   344080K   32092K    9533K    7996K  com.android.ctvmenu
 1525   348232K   31180K    7838K    6064K  com.android.tv.tvplayer.ui
 1738   359820K   29932K    7342K    5584K  com.android.systemui
 1616   331056K   28048K    6835K    5604K  com.android.inputmethod.pinyin
 1504   342164K   27664K    6604K    5264K  com.android.tv.service
11064   328920K   26140K    5882K    4884K  com.android.wididemo
 1777   332604K   24988K    5775K    4568K  com.android.phone
 1603   323256K   25200K    5451K    4208K  android.process.media
 1815   323020K   23572K    5061K    4104K  android.process.acore
10845   340276K   27132K    5001K    3720K  com.android.documentsui
 1552   334240K   22200K    4293K    3448K  com.android.android.providers.tv
 1960   323592K   22356K    3614K    2208K  com.dangbeimarket:BackInstallService
10814   335636K   23920K    3564K    2548K  com.egame.tvmodel
 1901   326248K   23860K    3132K    2172K  com.android.mcastdemo
  984    77540K    6576K    2572K    1820K  /system/bin/surfaceflinger
 1632   318084K   19276K    2246K    1496K  com.broadcom.bluetoothmonitor
 5552   319036K   17868K    1940K    1264K  com.android.defcontainer
 1659   318256K   18184K    1934K    1208K  com.android.printspooler
15579     2696K    2140K    1921K    1916K  procrank
 1997   320424K   18564K    1914K    1100K  com.dangbeimarket:MonitorService
 1690   316972K   18084K    1895K    1188K  com.android.externalstorage
  995    28200K    5188K    1855K    1224K  /system/bin/livecap
 2402   317096K   17128K    1531K     860K  com.mstar.tvsetting.hotkey
  986    14872K    4320K    1449K     988K  /system/bin/drmserver
 1797   316916K   17220K    1427K     748K  com.android.smspush
  998    14116K    3720K    1331K    1012K  /system/bin/mtkbt
  979     5948K    1572K     680K     572K  /system/bin/vold
  994    27868K    2188K     665K     296K  /system/bin/virtualkeypad
  982     9780K    1232K     562K     484K  /system/bin/netd
  992     3368K    1196K     471K     384K  /system/bin/keystore
 1929     1304K     724K     453K     444K  /system/bin/mdnsd
    1      588K     428K     334K     268K  /init
  981     4580K     908K     330K     296K  /system/bin/resourcemanager
  996     4360K     684K     221K     204K  /system/bin/browserserver
  980     3540K     488K     214K     208K  /system/bin/sdcard
  983     1072K     532K     193K     180K  /system/bin/debuggerd
  988     1028K     472K     185K     176K  /system/bin/installd
11660      932K     488K     181K     128K  sh
 3582     1020K     468K     179K     172K  /system/bin/dhcpcd
 3078      928K     480K     173K     120K  sh
 1002     1504K     184K     172K     172K  /sbin/adbd
 1001      924K     460K     167K     116K  /system/bin/sh
  665      520K     224K     156K      92K  /sbin/ueventd
11179      932K     424K     152K     144K  logcat
  977     1424K     140K     136K     136K  /sbin/healthd
  978     1028K     344K     117K     112K  /system/bin/servicemanager
  993      880K     344K     109K     104K  /system/bin/logwrapper
                           ------   ------  ------
                          350132K  293872K  TOTAL

RAM: 840500K total, 55164K free, 46500K buffers, 203836K cached, 8708K shmem, 24768K slab

procmem 使用

procmem 查看单个进程的内存使用状况
        

dumpsys  meminfo的使用

查看系统所有进程内存使用状况
shell@cv6a628h_base:/ # dumpsys meminfo                                        
Applications Memory Usage (kB):
Uptime: 4143500 Realtime: 4143500

Total PSS by process:
    67094 kB: com.oslauncher (pid 1824 / activities)
    31293 kB: com.dangbeimarket (pid 2140 / activities)
    23305 kB: com.starcor.hunan (pid 4716)
    22324 kB: system (pid 1445)
    17890 kB: mb.gamenet (pid 2348 / activities)
    17853 kB: com.cultraview.mediacenter (pid 2783 / activities)
    17539 kB: tvos (pid 1006)
    14164 kB: com.android.launcher (pid 2304 / activities)
    13053 kB: zygote (pid 986)
    12767 kB: com.audiocn.kalaok.tv (pid 4588 / activities)
    10275 kB: com.cultraview.ctvmenu (pid 3039 / activities)
     7454 kB: com.mstar.tv.tvplayer.ui (pid 1792 / activities)
     7071 kB: com.android.systemui (pid 1897)
     7022 kB: mediaserver (pid 988)
     6338 kB: com.mstar.tv.service (pid 1647)
     6311 kB: android.process.media (pid 1627)
     5978 kB: com.android.phone (pid 1945)
     5799 kB: com.android.documentsui (pid 2603)
     4961 kB: android.process.acore (pid 1983)
     4766 kB: com.android.wididemo (pid 2729)
     3893 kB: com.android.inputmethod.pinyin (pid 1713)
     3662 kB: com.egame.tvmodel (pid 2543 / activities)
     3639 kB: com.mstar.android.providers.tv (pid 1726)
     3464 kB: com.dangbeimarket:BackInstallService (pid 2157)
     2726 kB: com.android.mcastdemo (pid 2069)
     2613 kB: surfaceflinger (pid 985)
     2009 kB: com.broadcom.bluetoothmonitor (pid 1739)
     1830 kB: com.android.printspooler (pid 1777)
     1811 kB: com.dangbeimarket:MonitorService (pid 2193)
     1808 kB: livecap (pid 996)
     1771 kB: com.android.externalstorage (pid 1850)
     1660 kB: com.android.provision (pid 1754)
     1415 kB: drmserver (pid 987)
     1346 kB: com.android.smspush (pid 1965)
     1306 kB: mtkbt (pid 999)
     1160 kB: logcat (pid 4754)
      678 kB: vold (pid 980)
      663 kB: virtualkeypad (pid 995)
      578 kB: netd (pid 983)
      468 kB: keystore (pid 993)
      451 kB: mdnsd (pid 2125)
      338 kB: /init (pid 1)
      331 kB: resourcemanager (pid 982)
      214 kB: browserserver (pid 997)
      208 kB: sdcard (pid 981)
      201 kB: sh (pid 2226)
      193 kB: sh (pid 1002)
      190 kB: debuggerd (pid 984)
      176 kB: adbd (pid 1003)
      176 kB: dumpsys (pid 6590)
      173 kB: installd (pid 989)
      160 kB: ueventd (pid 665)
      140 kB: healthd (pid 978)
      115 kB: servicemanager (pid 979)
      112 kB: logwrapper (pid 994)

Total PSS by OOM adjustment:
    51481 kB: Native
               17539 kB: tvos (pid 1006)
               13053 kB: zygote (pid 986)
                7022 kB: mediaserver (pid 988)
                2613 kB: surfaceflinger (pid 985)
                1808 kB: livecap (pid 996)
                1415 kB: drmserver (pid 987)
                1306 kB: mtkbt (pid 999)
                1160 kB: logcat (pid 4754)
                 678 kB: vold (pid 980)
                 663 kB: virtualkeypad (pid 995)
                 578 kB: netd (pid 983)
                 468 kB: keystore (pid 993)
                 451 kB: mdnsd (pid 2125)
                 338 kB: /init (pid 1)
                 331 kB: resourcemanager (pid 982)
                 214 kB: browserserver (pid 997)
                 208 kB: sdcard (pid 981)
                 201 kB: sh (pid 2226)
                 193 kB: sh (pid 1002)
                 190 kB: debuggerd (pid 984)
                 176 kB: adbd (pid 1003)
                 176 kB: dumpsys (pid 6590)
                 173 kB: installd (pid 989)
                 160 kB: ueventd (pid 665)
                 140 kB: healthd (pid 978)
                 115 kB: servicemanager (pid 979)
                 112 kB: logwrapper (pid 994)
    22324 kB: System
               22324 kB: system (pid 1445)
    14658 kB: Persistent
                6338 kB: com.mstar.tv.service (pid 1647)
                6311 kB: android.process.media (pid 1627)
                2009 kB: com.broadcom.bluetoothmonitor (pid 1739)
    70733 kB: Foreground
               67094 kB: com.oslauncher (pid 1824 / activities)
                3639 kB: com.mstar.android.providers.tv (pid 1726)
     7071 kB: Visible
                7071 kB: com.android.systemui (pid 1897)
     3893 kB: Perceptible
                3893 kB: com.android.inputmethod.pinyin (pid 1713)
     7454 kB: Previous
                7454 kB: com.mstar.tv.tvplayer.ui (pid 1792 / activities)
    33820 kB: B Services
               23305 kB: com.starcor.hunan (pid 4716)
                5978 kB: com.android.phone (pid 1945)
                2726 kB: com.android.mcastdemo (pid 2069)
                1811 kB: com.dangbeimarket:MonitorService (pid 2193)
   133501 kB: Cached
               31293 kB: com.dangbeimarket (pid 2140 / activities)
               17890 kB: mb.gamenet (pid 2348 / activities)
               17853 kB: com.cultraview.mediacenter (pid 2783 / activities)
               14164 kB: com.android.launcher (pid 2304 / activities)
               12767 kB: com.audiocn.kalaok.tv (pid 4588 / activities)
               10275 kB: com.cultraview.ctvmenu (pid 3039 / activities)
                5799 kB: com.android.documentsui (pid 2603)
                4961 kB: android.process.acore (pid 1983)
                4766 kB: com.android.wididemo (pid 2729)
                3662 kB: com.egame.tvmodel (pid 2543 / activities)
                3464 kB: com.dangbeimarket:BackInstallService (pid 2157)
                1830 kB: com.android.printspooler (pid 1777)
                1771 kB: com.android.externalstorage (pid 1850)
                1660 kB: com.android.provision (pid 1754)
                1346 kB: com.android.smspush (pid 1965)

Total PSS by category:
   107941 kB: Dalvik
    52961 kB: Unknown
    49486 kB: .so mmap
    38762 kB: .dex mmap
    37860 kB: Ashmem
    35996 kB: Dalvik Other
     9990 kB: Other mmap
     4515 kB: .apk mmap
     2964 kB: Native
     2196 kB: .ttf mmap
     1304 kB: Other dev
      792 kB: Stack
      164 kB: .jar mmap
        4 kB: Cursor
        0 kB: code mmap
        0 kB: image mmap
        0 kB: Graphics
        0 kB: GL
        0 kB: Memtrack

Total RAM: 840500 kB
 Free RAM: 478961 kB (133501 cached pss + 227268 cached + 118192 free)
 Used RAM: 251974 kB (211434 used pss + 17152 buffers + 548 shmem + 22840 slab)
 Lost RAM: 109565 kB
     ZRAM: 4 kB physical used for 0 kB in swap (102396 kB total swap)
      KSM: 46860 kB saved from shared 11324 kB
           215852 kB unshared; 325484 kB volatile
   Tuning: 64 (large 128), oom 91340 kB, restore limit 30446 kB (low-ram)

dumpsys meminfo  xxx

查看单个进程内存使用状况,如下:
shell@cv6a628h_base:/ # dumpsys meminfo com.android.systemui                   
Applications Memory Usage (kB):
Uptime: 4250893 Realtime: 4250893

** MEMINFO in pid 1897 [com.android.systemui] **
                   Pss  Private  Private  Swapped     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap        0        0        0        0     3268     2127       88
  Dalvik Heap     1738     1628        0        0     5544     4128     1416
 Dalvik Other     1376     1212        0        0                           
        Stack       28       28        0        0                           
    Other dev        8        0        8        0                           
     .so mmap      769      472        0        0                           
    .apk mmap      776        0      652        0                           
    .ttf mmap       98        0       68        0                           
    .dex mmap     1194       12      664        0                           
   Other mmap       12        8        0        0                           
      Unknown     1072     1036        0        0                           
        TOTAL     7071     4396     1392        0     8812     6255     1504
 
 Objects
               Views:       51         ViewRootImpl:        1
         AppContexts:        7           Activities:        0
              Assets:        5        AssetManagers:        5
       Local Binders:       32        Proxy Binders:       29
    Death Recipients:        0
     OpenSSL Sockets:        0
 
 SQL
         MEMORY_USED:        0
  PAGECACHE_OVERFLOW:        0          MALLOC_SIZE:        0



发布了101 篇原创文章 · 获赞 19 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/kehyuanyu/article/details/47147751
今日推荐