前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android内存分析命令

Android内存分析命令

作者头像
233333
发布2024-06-28 09:10:40
1300
发布2024-06-28 09:10:40
举报

一、内存指标

Item

全称

含义

等价

USS

Unique Set Size

物理内存

进程独占的内存

PSS

Proportional Set Size

物理内存

PSS= USS+ 按比例包含共享库

RSS

Resident Set Size

物理内存

RSS= USS+ 包含共享库

VSS

Virtual Set Size

虚拟内存

VSS= RSS+ 未分配实际物理内存

内存的大小关系:VSS>=RSS>=PSS>=USS

二、常用内存分析命令

1. procrank

获取所有进程的内存使用的排行榜,排行是以Pss的大小而排序,能输出详细的VSS/RSS/PSS/USS内存指标。

代码语言:javascript
复制
# procrank

  PID       Vss      Rss      Pss      Uss  cmdline
  469  4715244K  199568K   93953K   76772K  system_server
  628  4774604K  184272K   79868K   63260K  com.android.systemui
  378  1581340K  116848K   63536K   35956K  zygote
 1054  5048780K  130504K   33086K   20376K  com.android.launcher3
  377  4239348K  130300K   28338K    8012K  zygote64
  687  1333924K   54604K   25609K    5504K  /system/bin/webview_zygote32
  749  4338336K  108900K   25539K   16612K  com.android.phone
  263    75200K   27620K   18690K   16088K  /vendor/bin/hw/android.hardware.neuralnetworks@1.0-service-armnn
  606  4330764K   91380K   15649K    9656K  com.android.inputmethod.latin
  269   312884K   27868K   13869K   10336K  /system/bin/surfaceflinger
 1170  4321764K   92900K   13701K    6336K  android.process.media
 1302  4323936K   84736K   13004K    8064K  com.android.email
  255    53284K   21308K   10199K    6972K  /vendor/bin/hw/android.hardware.camera.provider@2.4-service
 1140  4317440K   82832K    9876K    3808K  android.rockchip.update.service
 1850  4318536K   75692K    8379K    4096K  com.android.calendar
 1284  4315752K   77148K    8185K    3796K  com.android.providers.calendar
  387    73924K   18420K    7686K    5064K  /system/bin/mediaserver
 1190  4315400K   71948K    7137K    2800K  com.android.quicksearchbox
 1876  4315996K   74824K    6986K    2668K  com.android.mtp
  391    31860K   12104K    6845K    5644K  media.codec
 1021  4315960K   70452K    6835K    3020K  com.android.printspooler
 1011  4314012K   69076K    6658K    2864K  com.cghs.stresstest
  379    43520K   12616K    6621K    4920K  /system/bin/audioserver
  385  2164032K   18588K    6493K    4324K  media.extractor
 1407  4315816K   70584K    6403K    2296K  android.ext.services
 1114  4314788K   69144K    5972K    2240K  com.android.keychain
 1069  4313648K   67308K    5792K    2156K  com.android.smspush
  253    16256K    7892K    4116K    2808K  /vendor/bin/hw/android.hardware.audio@2.0-service
  380    24908K   11124K    3948K    2544K  /system/bin/cameraserver
  386  2128240K   11312K    3220K    2156K  media.metrics
  261    33120K    7556K    3022K    2432K  /vendor/bin/hw/android.hardware.graphics.composer@2.1-service
  232    19996K    5304K    2915K    2820K  /system/bin/logd
  381    18964K    9884K    2836K    1652K  /system/bin/drmserver
  266    14404K    6140K    2798K    2604K  /vendor/bin/hw/android.hardware.wifi@1.0-service
  258    12756K    6560K    2463K    1904K  /vendor/bin/hw/android.hardware.drm@1.0-service
  245    55064K    7468K    2421K    2024K  /system/bin/vold
  388    31004K    6548K    2225K    1980K  /system/bin/netd
  259    11140K    5328K    1985K    1588K  /vendor/bin/hw/android.hardware.drm@1.0-service.widevine
  383    19280K    6492K    1811K    1348K  /system/bin/keystore
  382    19676K    5636K    1809K    1616K  /system/bin/installd
    1    11968K    2436K    1714K    1092K  /init
  234    14408K    5576K    1653K    1352K  /system/bin/hwservicemanager
 1841    12932K    1700K    1511K    1504K  /system/bin/adbd
  390    15096K    5632K    1507K    1312K  /system/bin/wificond
  265    16888K    5044K    1439K    1164K  /vendor/bin/hw/android.hardware.sensors@1.0-service
  244    14848K    5904K    1422K     928K  /vendor/bin/hw/android.hardware.keymaster@3.0-service
  384    10688K    5308K    1297K     804K  /system/bin/mediadrmserver
  260    17480K    5224K    1261K     960K  /vendor/bin/hw/android.hardware.graphics.allocator@2.0-service
  393    15560K    5612K    1245K    1000K  /system/bin/gatekeeperd
  403     9468K    3296K    1244K    1188K  /system/bin/ip6tables-restore
  402     9452K    3200K    1165K    1116K  /system/bin/iptables-restore
  207     6080K    1768K    1158K     568K  /sbin/ueventd
 2038    16940K    3304K    1145K    1088K  procrank
  270    13924K    5000K    1142K     944K  /system/bin/thermalserviced
  389    15988K    4292K    1090K     960K  /system/bin/storaged
  254    12244K    4212K    1042K     868K  /vendor/bin/hw/android.hardware.bluetooth@1.0-service
  256     9048K    4108K    1018K     596K  /vendor/bin/hw/android.hardware.cas@1.0-service
  257    15372K    4372K    1017K     828K  /vendor/bin/hw/android.hardware.configstore@1.0-service
  267    13464K    4504K     993K     860K  /system/bin/healthd
  262    12136K    4168K     896K     676K  /vendor/bin/hw/android.hardware.light@2.0-service
  264    12140K    4168K     870K     668K  /vendor/bin/hw/android.hardware.power@1.0-service
  233    10444K    3428K     848K     760K  /system/bin/servicemanager
  235    10244K    3256K     805K     696K  /vendor/bin/vndservicemanager
  252    12088K    4088K     767K     636K  /system/bin/hw/android.hidl.allocator@1.0-service
 1983     8932K    3008K     736K     548K  /system/bin/sh
  274     8932K    2944K     727K     540K  /system/bin/sh
  268     9180K    3072K     681K     624K  /system/bin/lmkd
  395     9028K    3004K     662K     600K  /system/bin/tombstoned
                           ------   ------  ------
                          601566K  385996K  TOTAL

 RAM: 3938668K total, 27
65940K free, 54772K buffers, 683920K cached, 117060K shmem, 119748K slab

获取所有进程的内存使用的排行榜,排行是以Pss的大小而排序,能输出详细的VSS/RSS/PSS/USS内存指标。

2. free

查看可用内存,缺省单位KB。该命令比较简单、轻量,专注于查看剩余内存情况。数据来源于/proc/meminfo。

代码语言:javascript
复制
# free
                total        used        free      shared     buffers
Mem:       4033196032  1199968256  2833227776   119869440    56078336
-/+ buffers/cache:     1143889920  2889306112
Swap:      2016256000           0  2016256000

# free -m
                total        used        free      shared     buffers
Mem:             3846        1144        2701         114          53
-/+ buffers/cache:           1091        2755
Swap:            1922           0        1922

对于Mem行,存在的公式关系:total= used+free;对于-/+ buffers行: buffers/cache used=mem_used - mem_buffers

buffers/cache free = mem free + mem buffers

3 cat /proc/meminfo

展示的是系统整体内存情况,内存项按类型进行分类:

代码语言:javascript
复制
# cat /proc/meminfo

MemTotal:        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

日常使用经验总结:1)MemTotal:是除去系统底层预留内存之外,能被系统使用的总内存大小,正常情况下会比实际内存小一点,但是如果小太多的话属于预留不合理,需要看看原因,这属于先天不足,天花板过低。

2)MemFree、MemAvailable:前者是当前系统未被使用的内存,后者是当前系统可以被使用的内存(包括可以被回收的部分内存),意思就那个什么,挤挤还是有的。从经验上来说,如果当前MemAvailable底于总内存的1/10,那么系统可能会出现因为内存造成的卡顿,其中原因可能包括频繁回收内存造成的阻塞、耗时以及寻址难度加大变相地增加了内存分配的时间等等。

3)Buffers、Cached:前者用于缓存磁盘blocks以优化block I/O,后者用于缓存文件内容以优化文件1/O。部分内存是可被回收的,被算到MemAvailable中。MemAvailable ≈ MemFree+Buffers+Cached

4)Mlocked:被系统锁定的页面。比如系统中google 7.0加的PinnerService 就会有这个效果,把常用的内容锁定在内存中,避免频繁的内存回收与分配,优化但不限于提升io效率。典型的用空间换时间,如果是Android 2G及其以下内存的手机,建议关闭PinnerService,要啥自行车。PinnerService官方描述

5) SwapTotal, SwapFree:这就zram,如果为0就是没打开。SwapTotal是zram总空间大小, SwapFree是没交换的空间大小。

6)Slab:内核基于Buddy做了page的粗分,Slab基于Buddy做了内存二次划分,这部分就是基于SIab内存分配的内存大小。使用的函数是kmalloc/kfree。SReclaimable和SUnreclaim分别是Slab的可回收和不可回收部分(slab=SReclaimable+SUnreclaim),如果Slab比较大,可能是kernel debug开关被打开了(也不一定,具体看调试内容),而且 SUnreclaim也非常大的话,可能存在kernel泄漏。

7) Kernel内存可使用内存 Slab + KernelStack+PageTables。

4. dumpsys meminfo

4.1 dumpsys实现逻辑简单介绍

dumpsys的源码结构其实很简单,只有一个dumpsys.cpp源码路径是: /frameworks/native/cmds/dumpsys/dumpsys.cpp在其main方法中,先通过defaultServiceManager(函数获得ServiceManager对象,然后根据dumpsys传进来的参数通过函数checkService来找到具体的service,并执行该service的dump方法,达到dump service的目的。

4.2 dumpsys meminfo 数据组成

dumpsys meminfo对应的服务是:ActivityManagerService, 它从memBinder类的dump函数开始执行的。

代码语言:javascript
复制
static class MemBinder extends Binder {
        ActivityManagerService mActivityManagerService;
        private final PriorityDump.PriorityDumper mPriorityDumper =
                new PriorityDump.PriorityDumper() {
            @Override
            public void dumpHigh(FileDescriptor fd, PrintWriter pw, String[] args,
                    boolean asProto) {
                dump(fd, pw, new String[] {"-a"}, asProto);
            }

            @Override
            public void dump(FileDescriptor fd, PrintWriter pw, String[] args, boolean asProto) {
                mActivityManagerService.dumpApplicationMemoryUsage(
                        fd, pw, "  ", args, false, null, asProto);
            }
        };

主要收集内存信息并打印是在dumpApplicationMemoryUsage方法中做的,但是该方法比较大,就不列出来了,举个例子:

Debug.getMemoryInfo(pid,mi);/通过debug.java中的getMemoryInfo函数来获取当前进程的整体memory信息,获取的是 对应的/proc/$/smaps文件统计出来的信息。getMemoryInfo是个native方法,对应到android_os_Debug.cpp的 android_os_Debug_getDirtyPagesPid.

从代码看:这部分内容是从/proc/$/smaps获取的。

那么总结下dumpsys meminfo的出处:



很明显,dumpsys meminfo 获取的数据是从系统各个渠道汇集来的。

4.3 dumpsys meminfo 展示的是系统整体内存情况,内存项按进程进行分类
代码语言:javascript
复制
# dumpsys meminfo

Applications Memory Usage (in Kilobytes):
Uptime: 18012360 Realtime: 92063532

Total PSS by process: //Java层存活的进程及其占用内存情况
     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:  //Native存活的进程及其占用内存情况
    253,080K: Native
         63,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: System
         93,509K: system (pid 469)
    111,467K: Persistent
         79,586K: com.android.systemui (pid 628)
         25,377K: com.android.phone (pid 749)
          6,504K: com.cghs.stresstest (pid 1011)
     32,858K: Foreground
         32,858K: com.android.launcher3 (pid 1054 / activities)
      5,633K: Visible
          5,633K: com.android.smspush (pid 1069)
     15,488K: Perceptible
         15,488K: com.android.inputmethod.latin (pid 606)
      9,675K: B Services
          9,675K: android.rockchip.update.service (pid 1140)
     75,169K: Cached
         13,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 mmap
    109,632K: Native
    106,914K: .dex mmap
     56,243K: .oat mmap
     44,939K: .apk mmap
     32,029K: .art mmap
     24,460K: Unknown
     23,246K: Dalvik
     18,957K: Other mmap
     11,423K: .ttf mmap
      7,471K: Dalvik Other
      2,288K: Stack
        879K: Other dev
        320K: Ashmem
        172K: .jar mmap
          0K: Cursor
          0K: Gfx dev
          0K: EGL mtrack
          0K: GL mtrack
          0K: Other mtrack

Total 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,419K
     ZRAM:        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)

先总结下最下面的统计:Total RAM:内存总数,与proc/meminfo中的MemTotal一致。Free RAM: cached pss + cached kernel + cached ion + free手机剩余内存一般是看它

  • cached pss: dumpsys meminfo中 cached 进程的PSS总和
  • cached kernel:代表内核缓存的内存,这部分内存主要用于以下几方面:
    • 内核对象缓存:用于缓存内核对象和数据结构,提升系统性能。
    • 页缓存:用于缓存从存储设备读取的数据,以减少磁盘 I/O 操作,提高文件访问速度。
    • Slab 分配器缓存:用于高效地管理内核内存分配。
  • free: proc/meminfo MemFree
  • ion cached以及gpu cached: display相关ion的内存占用

Used RAM: used pss+kernel+trace buffer+ion display+cma usage

  • used pss: native process PSS+dumpsys meminfo APP除cached部分的PSS总和
  • kernel: meminfo的Shmem+Slab+PageTables+kernelStack+vmallocinfo里面的ioremap项+map_lowmem项所占内存的 和
  • ion disp: display相关的ion模块内存占用 cma usage: cma模块占用

Lost RAM:与cache ion有关

ZRAM:zram swap转换情况

Tuning:这一行主要是system的一些设置,没看过

5 dumpsys meminfo [pid packageName]

查看单个进程内存详情

代码语言:javascript
复制
** MEMINFO in pid 9953 [com.google.android.gm] **
                 Pss     Pss  Shared Private  Shared Private    Heap    Heap    Heap
               Total   Clean   Dirty   Dirty   Clean   Clean    Size   Alloc    Free
              ------  ------  ------  ------  ------  ------  ------  ------  ------
  Native Heap      0       0       0       0       0       0    7800    7637(6)  126
  Dalvik Heap   5110(3)    0    4136    4988(3)    0       0    9168    8958(6)  210
 Dalvik Other   2850       0    2684    2772       0       0
        Stack     36       0       8      36       0       0
       Cursor    136       0       0     136       0       0
       Ashmem     12       0      28       0       0       0
    Other dev    380       0      24     376       0       4
     .so mmap   5443(5) 1996    2584    2664(5) 5788    1996(5)
    .apk mmap    235      32       0       0    1252      32
    .ttf mmap     36      12       0       0      88      12
    .dex mmap   3019(5) 2148       0       0    8936    2148(5)
   Other mmap    107       0       8       8     324      68
      Unknown   6994(4)    0     252    6992(4)    0       0
        TOTAL  24358(1) 4188    9724   17972(2)16388    4260(2)16968   16595     336

 Objects
               Views:    426         ViewRootImpl:        3(8)
         AppContexts:      6(7)        Activities:        2(7)
              Assets:      2        AssetManagers:        2
       Local Binders:     64        Proxy Binders:       34
    Death Recipients:      0
     OpenSSL Sockets:      1

 SQL
         MEMORY_USED:   1739
  PAGECACHE_OVERFLOW:   1164          MALLOC_SIZE:       62

数据来源:



纵轴:

属性名

说明

Native Heap

在Native Code 中使用 malloc 分配出的内存

Dalvik Heap

Dalvik 虚拟机分配的空间,不包括它自身的开销。Dalvik 堆中和 Zygote 进程共享的部分算是 sharedDirty

Dalvik Other

类数据结构和索引占据的内存

Stack

栈内存

Cursor

CursorWindow 占用的空间,与 SQL 有关

Ashmem

匿名共享内存,此类内存与cache shrinker 关联,可以控制cache shrinker在适当时机回收这些共享内存

Gfx dev

/dev/kgsl-3d0 占用的内存

Other dev

内部driver占用的内存

.so mmap

映射的 .so(native)代码占用的内存

.jar mmap

Java 文件代码占用内存

.apk mmap

apk 代码占用内存

.ttf mmap

ttf 文件代码占用内存

.dex mmap

映射的 .dex(Dalvik 或 ART)代码占用的内存

.oat mmap

代码映像占用的 RAM 量。此映像在所有应用之间共享,不受特定应用影响

.art mmap

堆映像占用的 RAM 量。此映像在所有应用之间共享,不受特定应用影响。尽管 ART 映像包含 Object 实例,它仍然不会计入您的堆大小

Other mmap

其它文件占用的内存

横轴:

属性名

说明

Pss Total

实际使用的内存,这里考虑了与Zygote 的共享。任何独占的内存页直接计算它的PSS值,而和其它进程共享的页则按照共享的比例计算PSS值

Private Dirty

进程私有的,相对磁盘数据有改动的内存

Private Clean

进程私有的,相对磁盘数据没有修改的内存

SwapPss Dirty

Android 4.4的一个优化,swap to zRAM。牺牲CPU,减少内存。这两个值的区别在于内核是否是统计按比例分出的swap数据,是的输出为SwapPss Dirty。

Swap Dirty

Whether the kernel reports proportional swap usage

Heap相关:

Heap Size

Heap Alloc

Heap Free

Native Heap

从mallinfo usmblks获得,代表最 大总共分配空间

从mallinfo uorblks获得,总共已分配 空间

从mallinfo fordblks获得,代表总 共剩余空间

Dalvik Heap

从Runtime totalMemory()获得, Dalvik Heap总共的内存大小

Runtime totalMemory()-freeMemory() , Dalvik Heap分配的内存大小

从Runtime freeMemory()获得, Dalvik Heap剩余的内存大小

App Summary:



属性名

内存组成

Java Heap

Dalvik Heap 的 Private Dirty.art mmap 的 Private Dirty

Native Heap

Native Heap 的 Private Dirty

Code

.so mmap.jar mmap.apk mmap.ttf mmap.dex mmap.oat mmap的 Private Dirty + Private Clean

Stack

Stack 的 Private Dirty

Graphics

Gfx devEGL mtrackGL mtrack的 Private Dirty + Private Clean

Private Other

Native HeapDalvik Heap- HEAP_UNKNOWN的Private Dirty + Private Clean

System

Native HeapDalvik HeapHEAP_UNKNOWN的 Pss + SwapPss Dirty - Private Dirty - Private Clean

TOTAL

Native HeapDalvik HeapHEAP_UNKNOWN的 Pss + SwapPss Dirty

TOTAL SWAP PSS

Native HeapDalvik HeapHEAP_UNKNOWN的 SwapPss Dirty

TOTAL SWAP (KB)

Native HEAPDalvik HeapHEAP_UNKNOWN的 Swap Dirty

Object:



这里通常会通过看Activities、AppContexts来判断是否有内存泄漏,比如刚退出应用,查看Object中Activities是否为0,如果 不为0,则有Activity没有销毁,很有可能存在泄漏。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-06-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、内存指标
  • 二、常用内存分析命令
    • 1. procrank
      • 2. free
        • 3 cat /proc/meminfo
          • 4. dumpsys meminfo
            • 4.1 dumpsys实现逻辑简单介绍
            • 4.2 dumpsys meminfo 数据组成
            • 4.3 dumpsys meminfo 展示的是系统整体内存情况,内存项按进程进行分类
          • 5 dumpsys meminfo [pid packageName]
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档