Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android系統檢測程序內存占用各種方法

Android系統檢測程序內存占用各種方法

編輯:關於Android編程

1.檢查系統總內存
復制代碼 代碼如下:
liuhx@uc ~ $ adb shell cat /proc/meminfo
MemTotal:         840868 kB
MemFree:          457344 kB
Buffers:            1744 kB
Cached:           203064 kB
SwapCached:            0 kB
Active:           234932 kB
Inactive:         129644 kB
Active(anon):     170292 kB
Inactive(anon):        0 kB
Active(file):      64640 kB
Inactive(file):   129644 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        159820 kB
Mapped:            97916 kB
Slab:               7808 kB
SReclaimable:       2920 kB
SUnreclaim:         4888 kB
PageTables:         3516 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      420432 kB
Committed_AS:    1295272 kB
VmallocTotal:     122880 kB
VmallocUsed:       16508 kB
VmallocChunk:      76804 kB

第一行MemTotal就是總內存。一般並不會等於手機標榜的數值。說是2G內存的手機,會在1.8G左右

2.檢查某個程序的各類型內存占用

可用dumpsys meminfo 包名。不知道包名的話,可以用ps命令得到所有運行的程序,也包括得到pid。以自帶的浏覽器為例:
復制代碼 代碼如下:
liuhx@uc ~ $ adb shell dumpsys meminfo com.android.browser
Applications Memory Usage (kB):
Uptime: 23140065 Realtime: 23140065

** MEMINFO in pid 939 [com.android.browser] **
                         Shared  Private     Heap     Heap     Heap
                   Pss    Dirty    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------
       Native     7111      748     7048     8964     8634      329
       Dalvik     7338     5096     6892     7568     7041      527
       Cursor        0        0        0                          
       Ashmem      276        0      276                          
    Other dev        4        0        0                          
     .so mmap     5050     1728      252                          
    .jar mmap        0        0        0                          
    .apk mmap      418        0        0                          
    .ttf mmap      439        0        0                          
    .dex mmap        0        0        0                          
   Other mmap     2320       16       24                          
      Unknown     5173       12     5172                          
        TOTAL    28129     7600    19664    16532    15675      856
 
 Objects
               Views:      104         ViewRootImpl:        1
         AppContexts:        4           Activities:        1
              Assets:        2        AssetManagers:        2
       Local Binders:       15        Proxy Binders:       19
    Death Recipients:        0
     OpenSSL Sockets:        0
 
 SQL
         MEMORY_USED:     1468
  PAGECACHE_OVERFLOW:      899          MALLOC_SIZE:      168
 
 DATABASES
      pgsz     dbsz   Lookaside(b)          cache  Dbname
         4     1180             68        54/55/9  /data/data/com.android.browser/databases/browser2.db
         4     1180             25         1/60/2  /data/data/com.android.browser/databases/browser2.db (2)
         4     1180             65        90/23/7  /data/data/com.android.browser/databases/browser2.db (1)
         4       40             18         0/15/1  /data/data/com.android.browser/databases/webview.db
 
 Asset Allocations
    zip:/system/app/Browser.apk:/resources.arsc: 881K

dumpsys的輸出結果在不同版本的android系統可能不同。

其中Pss Total是程序占用的PSS。

3.檢查程序狀態
復制代碼 代碼如下:
liuhx@uc ~ $ adb shell cat /proc/939/status
Name: android.browser
State: S (sleeping)
Tgid: 939
Pid: 939
PPid: 38
TracerPid: 0
Uid: 10013 10013 10013 10013
Gid: 10013 10013 10013 10013
FDSize: 256
Groups: 1015 1028 3003 50013
VmPeak:   215504 kB
VmSize:   206780 kB
VmLck:        0 kB
VmHWM:    52108 kB
VmRSS:    47748 kB
VmData:    53616 kB
VmStk:       84 kB
VmExe:        8 kB
VmLib:    29300 kB
VmPTE:      156 kB
Threads: 29
SigQ: 0/6656
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000001204
SigIgn: 0000000000000000
SigCgt: 00000002000094e8
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: fffffffffffffeff
voluntary_ctxt_switches: 451
nonvoluntary_ctxt_switches: 3563

VmRss是程序占用的RSS

4.檢查程序各部分的內存占用。
復制代碼 代碼如下:
cat /proc/939/smaps

這個命令的輸出結果很長,下面是一部分結果:
復制代碼 代碼如下:
4b399000-4b39b000 r--p 0001d000 1f:00 560        /system/lib/libGLESv1_enc.so
Size:                  8 kB
Rss:                   8 kB
Pss:                   8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         8 kB
Referenced:            8 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
4b39b000-4b39c000 rw-p 0001f000 1f:00 560        /system/lib/libGLESv1_enc.so
Size:                  4 kB
Rss:                   4 kB
Pss:                   4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         4 kB
Referenced:            4 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved