安卓内存信息查看


一、内存相关信息概述

1.1 内存指标概念

Item全称含义等价
USSUnique Set Size物理内存进程独占的内存
PSSProportional Set Size物理内存PSS= USS+ 按比例包含共享库
RSSResident Set Size物理内存RSS= USS+ 包含共享库
VSSVirtual Set Size虚拟内存VSS= RSS+ 未分配实际物理内存

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

1.2 常用的内存调优分析命令

  • dumpsys meminfo
  • MemoryInfo
  • procrank
  • cat /proc/meminfo
  • free
  • showmap
  • vmstat

二、查看内存信息的方式

2.1 proc/meminfo

C:\Users\henry.xue>adb shell
trinket:/ # cat proc/meminfo
MemTotal:        3711580 kB
MemFree:          607128 kB
MemAvailable:    2371444 kB
Buffers:           10980 kB
Cached:          1697644 kB
SwapCached:            0 kB
Active:          1107552 kB
Inactive:        1345780 kB
Active(anon):     745760 kB
Inactive(anon):     4916 kB
Active(file):     361792 kB
Inactive(file):  1340864 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Dirty:              2320 kB
Writeback:             0 kB
AnonPages:        744756 kB
Mapped:           666316 kB
Shmem:              5960 kB
Slab:             231564 kB
SReclaimable:      70964 kB
SUnreclaim:       160600 kB
KernelStack:       35616 kB
PageTables:        52180 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     3952936 kB
Committed_AS:   90872212 kB
VmallocTotal:   263061440 kB
VmallocUsed:       75784 kB
VmallocChunk:          0 kB
CmaTotal:         208896 kB
CmaFree:               0 kB

参数详解:

  • MemTotal:总内存大小,单位为 kB。
  • MemFree:空闲内存大小,单位为 kB。表示当前未被使用的内存大小。
  • MemAvailable:可用内存大小,单位为 kB。表示系统当前可用于分配给进程的内存大小,包括空闲内存和缓存内存。
  • Buffers:缓冲区大小,单位为 kB。用于存放文件系统的缓冲区大小。
  • Cached:缓存大小,单位为 kB。//用于高速缓存
  • SwapCached:交换缓存大小,单位为 kB。表示被交换到磁盘的内存页在内存中的缓存大小。 //用于swap缓存
  • Active:活跃内存大小,单位为 kB。表示当前正在使用的内存大小。
  • Inactive:非活跃内存大小,单位为 kB。表示当前未被使用但仍然在内存中的内存大小。
  • Active(anon):活跃的匿名内存大小,单位为 kB。表示当前正在使用的匿名内存大小。
  • Inactive(anon):非活跃的匿名内存大小,单位为 kB。表示未被使用的匿名内存大小。
  • Active(file):活跃的文件内存大小,单位为 kB。表示当前正在使用的文件内存大小。
  • Inactive(file):非活跃的文件内存大小,单位为 kB。表示未被使用的文件内存大小。
  • 其余参数包括 Dirty、Writeback、AnonPages、Mapped、Shmem、Slab、KernelStack、PageTables 等,分别表示不同类型的内存使用情况和内核数据结构占用的内存大小。
  • SwapTotal:交换空间总大小,单位为 kB。表示系统中交换空间的总大小。
  • SwapFree:可用交换空间大小,单位为 kB。表示系统中可用于交换的空间大小。
  • CommitLimit:提交限制大小,单位为 kB。表示系统能够保证不会耗尽内存和交换空间的总可用空间大小。
  • Committed_AS:已提交内存大小,单位为 kB。表示系统当前已分配但尚未使用的内存大小。
  • VmallocTotal:虚拟内存总大小,单位为 kB。表示系统中虚拟内存的总大小。
  • VmallocUsed:已使用的虚拟内存大小,单位为 kB。表示系统中已被使用的虚拟内存大小。
  • VmallocChunk:虚拟内存块大小,单位为 kB。表示 虚拟空间可用的最大连续内存块
  • CmaTotal:连续内存分配总大小,单位为 kB。表示系统中用于连续内存分配的总大小。
  • CmaFree:可用连续内存分配大小,单位为 kB。表示系统中可用于连续内存分配的大小。

对于cache和buffer也是系统可以使用的内存。所以系统总的可用内存为 MemFree+Buffers+Cached

2.2 MemoryInfo

ActivityManager里的内部类MemoryInfo

    public static class MemoryInfo implements Parcelable {
        /**
         * The available memory on the system.  This number should not
         * be considered absolute: due to the nature of the kernel, a significant
         * portion of this memory is actually in use and needed for the overall
         * system to run well.
         */
        public long availMem;

        /**
         * The total memory accessible by the kernel.  This is basically the
         * RAM size of the device, not including below-kernel fixed allocations
         * like DMA buffers, RAM for the baseband CPU, etc.
         */
        public long totalMem;

        /**
         * The threshold of {@link #availMem} at which we consider memory to be
         * low and start killing background services and other non-extraneous
         * processes.
         */
        public long threshold;

        /**
         * Set to true if the system considers itself to currently be in a low
         * memory situation.
         */
        public boolean lowMemory;
        ......

其中重要的四个参数:

  • availMem: 系统上的可用内存。这个数字不应该被认为是绝对的:由于内核的性质,这个内存的很大一部分实际上正在使用,并且是整个系统正常运行所必需的。
  • totalMem: 内核可访问的总内存。这基本上是设备的 RAM 大小,不包括内核下面的固定分配,如 DMA 缓冲区、基带 CPU 的 RAM 等。
  • threshold: availMem 的阈值,在这个阈值以下,系统会认为内存较低,并开始终止后台服务和其他非必要进程。
  • lowMemory: 如果系统认为当前处于低内存情况,则设置为 true。
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
long totalMemory = memoryInfo.totalMem;
long availableMemory = memoryInfo.availMem;

这段代码将获取设备的总内存和可用内存信息。

2.3 dumpsys meminfo

dumpsys meminfo命令的输出结果分以下4部分:

划分类型排序解释
processPSS以进程的PSS从大到小依次排序显示,每行显示一个进程;
OOM adjPSSNative/System/Persistent/Foreground/Visible/Perceptible/A Services/Home/B Services/Cached,分别显示每类的进程情况
categoryPSS以Dalvik/Native/.art mmap/.dex map等划分的各类进程的总PSS情况 total - 总内存、剩余内存、可用内存、其他内存
total-总内存、剩余内存、可用内存、其他内存
dumpsys meminfo
Applications Memory Usage (in Kilobytes):
Uptime: 442335361 Realtime: 442551316

Total PSS by process://以process来划分
    197,523K: system (pid 1510)
    136,732K: com.android.launcher3 (pid 2401 / activities)
    134,327K: com.android.systemui (pid 2036)
    112,825K: com.example.hxplay (pid 13199 / activities)
     63,737K: surfaceflinger (pid 753)
     50,951K: org.codeaurora.snapcam (pid 11871)
     45,727K: com.henry.basic (pid 13233 / activities)
     38,094K: zygote (pid 598)
     34,182K: com.android.audiotest (pid 28563 / activities)
     31,967K: com.android.webview:webview_service (pid 28725)
     31,353K: android.hardware.camera.provider@2.4-service (pid 690)
     29,564K: com.android.phone (pid 2291)
     27,245K: com.quectel.cardiagnosis (pid 13165)
     23,462K: com.android.server.telecom:ui (pid 28279)
     22,883K: com.android.permissioncontroller (pid 28851)
     21,958K: audioserver (pid 738)
     21,231K: qcrild (pid 1208)
     20,582K: zygote64 (pid 597)
     20,505K: qcrild (pid 1217)
     18,263K: android.hardware.audio@2.0-service (pid 686)
     17,509K: webview_zygote (pid 2212)
     17,227K: com.android.nfc (pid 3070)
     16,459K: android.process.media (pid 3652)
     16,185K: com.android.inputmethod.latin (pid 2560)
     15,913K: com.android.settings (pid 30898)
     15,307K: com.android.dialer (pid 30983)
     15,029K: android.process.acore (pid 28312)
     14,010K: com.qualcomm.qti.workloadclassifier (pid 3241)
     13,345K: com.qualcomm.location.XT (pid 30516)
     12,977K: android.hardware.wifi@1.0-service (pid 707)
     12,721K: com.qualcomm.qti.seccamservice:remote (pid 31144)
     12,622K: com.android.providers.calendar (pid 19949)
     12,489K: com.android.cellbroadcastreceiver (pid 19299)
     12,355K: com.qualcomm.qti.sva (pid 3035)
     12,316K: android.ext.services (pid 2477)
     12,209K: .dataservices (pid 2160)
     11,952K: android.hardware.gnss@2.0-service-qti (pid 695)
     11,870K: com.qualcomm.qti.ustaservice (pid 2262)
     11,663K: media.extractor (pid 973)
     11,631K: media.swcodec (pid 1074)
     11,431K: com.qualcomm.qti.smq (pid 3542)
     11,319K: .qtidataservices (pid 2236)
     11,309K: com.qualcomm.qti.telephonyservice (pid 2250)
     10,985K: com.qualcomm.qti.callenhancement (pid 4427)
     10,781K: com.qti.diagservices (pid 18499)
     10,752K: com.qualcomm.qti.modemtestmode (pid 5435)
     10,723K: com.qualcomm.qcrilmsgtunnel (pid 2612)
     10,691K: com.qualcomm.qti.services.systemhelper:systemhelper_service (pid 3131)
     10,656K: com.android.keychain (pid 12637)
     10,400K: com.qualcomm.telephony (pid 5277)
     10,355K: netmgrd (pid 1070)
     10,023K: android.hardware.graphics.composer@2.3-service (pid 696)
      9,904K: org.chromium.webview_shell (pid 12967)
      9,625K: com.qualcomm.qti.qdma (pid 3321)
      9,517K: cameraserver (pid 944)
      9,468K: com.android.se (pid 3202)
      9,396K: com.android.smspush (pid 3353)
      9,047K: com.qualcomm.qti.services.secureui:sui_service (pid 3268)
      8,606K: media.codec (pid 1057)
      8,126K: mediaserver (pid 986)
      7,384K: vendor.qti.hardware.perf@2.1-service (pid 715)
      6,962K: .pasr (pid 3090)
      6,213K: adbd (pid 1449)
      5,939K: com.android.printspooler (pid 19936)
      5,617K: wpa_supplicant (pid 2232)
      5,518K: media.metrics (pid 985)
      5,139K: cnd (pid 1060)
      4,954K: drmserver (pid 945)
      4,892K: init (pid 1)
      4,755K: logd (pid 479)
      4,306K: netd (pid 596)
      4,271K: ims_rtp_daemon (pid 1891)
      4,180K: imsrcsd (pid 1882)
      3,928K: xtra-daemon (pid 1102)
      3,408K: imsdatadaemon (pid 1202)
      3,389K: android.hardware.neuralnetworks@1.2-service-qti (pid 700)
      3,207K: android.hardware.sensors@2.0-service (pid 702)
      3,136K: wifidisplayhalservice (pid 1061)
      2,885K: keystore (pid 962)
      2,881K: thermal-engine (pid 920)
      2,817K: statsd (pid 1017)
      2,706K: android.hardware.drm@1.2-service.clearkey (pid 694)
      2,662K: cnss_diag (pid 932)
      2,589K: installd (pid 958)
      2,561K: vold (pid 491)
      2,460K: ueventd (pid 465)
      2,445K: update_engine (pid 1106)
      2,344K: init (pid 463)
      2,341K: vendor.qti.hardware.iop@2.0-service (pid 714)
      2,267K: storaged (pid 1019)
      2,195K: lowi-server (pid 1101)
      2,145K: apexd (pid 575)
      2,088K: sensors.qti (pid 775)
      2,067K: android.hardware.configstore@1.1-service (pid 692)
      2,057K: android.hardware.bluetooth@1.0-service-qti (pid 689)
      2,035K: android.hardware.drm@1.0-service (pid 693)
      2,032K: ipacm (pid 873)
      2,009K: vendor.qti.hardware.scve.objecttracker@1.0-service (pid 721)
      1,993K: vendor.qti.hardware.sensorscalibrate@1.0-service (pid 723)
      1,955K: incidentd (pid 956)
      1,921K: vendor.qti.hardware.scve.panorama@1.0-service (pid 722)
      1,911K: vendor.nxp.hardware.nfc@1.2-service (pid 709)
      1,907K: vendor.qti.secure_element@1.0-service (pid 728)
      1,906K: cnss-daemon (pid 1079)
      1,852K: wfdhdcphalservice (pid 1054)
      1,850K: init (pid 464)
      1,846K: android.system.suspend@1.0-service (pid 688)
      1,827K: vendor.display.color@1.0-service (pid 708)
      1,792K: mediadrmserver (pid 964)
      1,763K: hwservicemanager (pid 481)
      1,677K: vendor.qti.hardware.display.allocator-service (pid 712)
      1,622K: qseecomd (pid 485)
      1,619K: tloc_daemon (pid 1126)
      1,595K: ssgtzd (pid 2863)
      1,576K: qdmastatsd (pid 1120)
      1,570K: qti (pid 1230)
      1,558K: perfservice (pid 991)
      1,553K: gpuservice (pid 741)
      1,535K: android.hardware.cas@1.1-service (pid 691)
      1,492K: vendor.qti.hardware.qteeconnector@1.0-service (pid 719)
      1,465K: dpmQmiMgr (pid 1069)
      1,444K: wificond (pid 1035)
      1,438K: adpl (pid 1254)
      1,376K: gatekeeperd (pid 1098)
      1,347K: dpmd (pid 1158)
      1,344K: adsprpcd (pid 923)
      1,320K: time_daemon (pid 590)
      1,304K: android.hardware.keymaster@4.0-service-qti (pid 483)
      1,302K: pm-service (pid 736)
      1,270K: vendor.qti.hardware.servicetracker@1.1-service (pid 724)
      1,262K: vendor.qti.hardware.capabilityconfigstore@1.0-service (pid 711)
      1,248K: vendor.qti.hardware.qseecom@1.0-service (pid 486)
      1,223K: qcom-system-daemon (pid 917)
      1,196K: ATFWD-daemon-Quec (pid 919)
      1,183K: imsqmidaemon (pid 928)
      1,165K: vendor.qti.hardware.soter@1.0-service (pid 725)
      1,146K: ATFWD-daemon (pid 1097)
      1,143K: android.hardware.usb@1.0-service (pid 705)
      1,125K: hvdcp_opti (pid 1268)
      1,103K: android.hardware.gatekeeper@1.0-service-qti (pid 519)
      1,083K: loc_launcher (pid 1086)
      1,067K: android.hardware.boot@1.0-service (pid 518)
      1,062K: vendor.qti.esepowermanager@1.0-service (pid 710)
      1,055K: android.hardware.health@2.0-service (pid 697)
      1,053K: vendor.qti.hardware.qdutils_disp@1.0-service-qti (pid 716)
      1,051K: pd-mapper (pid 735)
      1,036K: vendor.qti.hardware.cryptfshw@1.0-service-qti (pid 520)
      1,035K: android.hardware.thermal@1.0-service (pid 704)
      1,034K: android.hardware.power@1.0-service (pid 701)
      1,028K: wfdvndservice (pid 1073)
      1,027K: pm-proxy (pid 914)
      1,025K: vendor.qti.power.pasrmanager@1.0-service (pid 727)
      1,000K: dpmd (pid 1117)
        999K: vendor.qti.hardware.tui_comm@1.0-service-qti (pid 726)
        991K: android.hardware.vibrator@1.0-service (pid 706)
        987K: android.hardware.light@2.0-service (pid 698)
        963K: android.hardware.memtrack@1.0-service (pid 699)
        941K: dumpsys (pid 9544)
        934K: ipacm-diag (pid 515)
        931K: android.hardware.atrace@1.0-service (pid 517)
        907K: ip6tables-restore (pid 1176)
        899K: iptables-restore (pid 1175)
        889K: vndservicemanager (pid 482)
        881K: tftp_server (pid 758)
        880K: servicemanager (pid 480)
        877K: android.hidl.allocator@1.0-service (pid 687)
        868K: rmt_storage (pid 754)
        862K: mlid (pid 1085)
        841K: adsprpcd (pid 924)
        838K: lmkd (pid 742)
        824K: cdsprpcd (pid 926)
        821K: adsprpcd (pid 922)
        819K: sh (pid 9533)
        813K: process-tracker (pid 27394)
        795K: port-bridge (pid 3210)
        775K: msm_irqbalance (pid 1191)
        773K: process-tracker (pid 27396)
        734K: ashmemd (pid 737)
        707K: sh (pid 912)
        691K: qcomserver (pid 492)
        627K: tombstoned (pid 1103)
        604K: qrtr-ns (pid 730)
        499K: ssgqmigd (pid 1080)

Total PSS by OOM adjustment://以oom来划分,会详细列举所有的类别的进程
    572,215K: Native
         63,737K: surfaceflinger (pid 753)
         38,094K: zygote (pid 598)
         31,353K: android.hardware.camera.provider@2.4-service (pid 690)
         21,958K: audioserver (pid 738)
         21,231K: qcrild (pid 1208)
         20,582K: zygote64 (pid 597)
         20,505K: qcrild (pid 1217)
         18,263K: android.hardware.audio@2.0-service (pid 686)
         17,509K: webview_zygote (pid 2212)
         12,977K: android.hardware.wifi@1.0-service (pid 707)
         11,952K: android.hardware.gnss@2.0-service-qti (pid 695)
         11,663K: media.extractor (pid 973)
         11,631K: media.swcodec (pid 1074)
         10,355K: netmgrd (pid 1070)
         10,023K: android.hardware.graphics.composer@2.3-service (pid 696)
          9,517K: cameraserver (pid 944)
          8,606K: media.codec (pid 1057)
          8,126K: mediaserver (pid 986)
          7,384K: vendor.qti.hardware.perf@2.1-service (pid 715)
          6,213K: adbd (pid 1449)
          5,617K: wpa_supplicant (pid 2232)
          5,518K: media.metrics (pid 985)
          5,139K: cnd (pid 1060)
          4,954K: drmserver (pid 945)
          4,892K: init (pid 1)
          4,755K: logd (pid 479)
          4,306K: netd (pid 596)
          4,271K: ims_rtp_daemon (pid 1891)
          4,180K: imsrcsd (pid 1882)
          3,928K: xtra-daemon (pid 1102)
          3,408K: imsdatadaemon (pid 1202)
          3,389K: android.hardware.neuralnetworks@1.2-service-qti (pid 700)
          3,207K: android.hardware.sensors@2.0-service (pid 702)
          3,136K: wifidisplayhalservice (pid 1061)
          2,885K: keystore (pid 962)
          2,881K: thermal-engine (pid 920)
          2,817K: statsd (pid 1017)
          2,706K: android.hardware.drm@1.2-service.clearkey (pid 694)
          2,662K: cnss_diag (pid 932)
          2,589K: installd (pid 958)
          2,561K: vold (pid 491)
          2,460K: ueventd (pid 465)
          2,445K: update_engine (pid 1106)
          2,344K: init (pid 463)
          2,341K: vendor.qti.hardware.iop@2.0-service (pid 714)
          2,267K: storaged (pid 1019)
          2,195K: lowi-server (pid 1101)
          2,145K: apexd (pid 575)
          2,088K: sensors.qti (pid 775)
          2,067K: android.hardware.configstore@1.1-service (pid 692)
          2,057K: android.hardware.bluetooth@1.0-service-qti (pid 689)
          2,035K: android.hardware.drm@1.0-service (pid 693)
          2,032K: ipacm (pid 873)
          2,009K: vendor.qti.hardware.scve.objecttracker@1.0-service (pid 721)
          1,993K: vendor.qti.hardware.sensorscalibrate@1.0-service (pid 723)
          1,955K: incidentd (pid 956)
          1,921K: vendor.qti.hardware.scve.panorama@1.0-service (pid 722)
          1,911K: vendor.nxp.hardware.nfc@1.2-service (pid 709)
          1,907K: vendor.qti.secure_element@1.0-service (pid 728)
          1,906K: cnss-daemon (pid 1079)
          1,852K: wfdhdcphalservice (pid 1054)
          1,850K: init (pid 464)
          1,846K: android.system.suspend@1.0-service (pid 688)
          1,827K: vendor.display.color@1.0-service (pid 708)
          1,792K: mediadrmserver (pid 964)
          1,763K: hwservicemanager (pid 481)
          1,677K: vendor.qti.hardware.display.allocator-service (pid 712)
          1,622K: qseecomd (pid 485)
          1,619K: tloc_daemon (pid 1126)
          1,595K: ssgtzd (pid 2863)
          1,576K: qdmastatsd (pid 1120)
          1,570K: qti (pid 1230)
          1,558K: perfservice (pid 991)
          1,553K: gpuservice (pid 741)
          1,535K: android.hardware.cas@1.1-service (pid 691)
          1,492K: vendor.qti.hardware.qteeconnector@1.0-service (pid 719)
          1,465K: dpmQmiMgr (pid 1069)
          1,444K: wificond (pid 1035)
          1,438K: adpl (pid 1254)
          1,376K: gatekeeperd (pid 1098)
          1,347K: dpmd (pid 1158)
          1,344K: adsprpcd (pid 923)
          1,320K: time_daemon (pid 590)
          1,304K: android.hardware.keymaster@4.0-service-qti (pid 483)
          1,302K: pm-service (pid 736)
          1,270K: vendor.qti.hardware.servicetracker@1.1-service (pid 724)
          1,262K: vendor.qti.hardware.capabilityconfigstore@1.0-service (pid 711)
          1,248K: vendor.qti.hardware.qseecom@1.0-service (pid 486)
          1,223K: qcom-system-daemon (pid 917)
          1,196K: ATFWD-daemon-Quec (pid 919)
          1,183K: imsqmidaemon (pid 928)
          1,165K: vendor.qti.hardware.soter@1.0-service (pid 725)
          1,146K: ATFWD-daemon (pid 1097)
          1,143K: android.hardware.usb@1.0-service (pid 705)
          1,125K: hvdcp_opti (pid 1268)
          1,103K: android.hardware.gatekeeper@1.0-service-qti (pid 519)
          1,083K: loc_launcher (pid 1086)
          1,067K: android.hardware.boot@1.0-service (pid 518)
          1,062K: vendor.qti.esepowermanager@1.0-service (pid 710)
          1,055K: android.hardware.health@2.0-service (pid 697)
          1,053K: vendor.qti.hardware.qdutils_disp@1.0-service-qti (pid 716)
          1,051K: pd-mapper (pid 735)
          1,036K: vendor.qti.hardware.cryptfshw@1.0-service-qti (pid 520)
          1,035K: android.hardware.thermal@1.0-service (pid 704)
          1,034K: android.hardware.power@1.0-service (pid 701)
          1,028K: wfdvndservice (pid 1073)
          1,027K: pm-proxy (pid 914)
          1,025K: vendor.qti.power.pasrmanager@1.0-service (pid 727)
          1,000K: dpmd (pid 1117)
            999K: vendor.qti.hardware.tui_comm@1.0-service-qti (pid 726)
            991K: android.hardware.vibrator@1.0-service (pid 706)
            987K: android.hardware.light@2.0-service (pid 698)
            963K: android.hardware.memtrack@1.0-service (pid 699)
            941K: dumpsys (pid 9544)
            934K: ipacm-diag (pid 515)
            931K: android.hardware.atrace@1.0-service (pid 517)
            907K: ip6tables-restore (pid 1176)
            899K: iptables-restore (pid 1175)
            889K: vndservicemanager (pid 482)
            881K: tftp_server (pid 758)
            880K: servicemanager (pid 480)
            877K: android.hidl.allocator@1.0-service (pid 687)
            868K: rmt_storage (pid 754)
            862K: mlid (pid 1085)
            841K: adsprpcd (pid 924)
            838K: lmkd (pid 742)
            824K: cdsprpcd (pid 926)
            821K: adsprpcd (pid 922)
            819K: sh (pid 9533)
            813K: process-tracker (pid 27394)
            795K: port-bridge (pid 3210)
            775K: msm_irqbalance (pid 1191)
            773K: process-tracker (pid 27396)
            734K: ashmemd (pid 737)
            707K: sh (pid 912)
            691K: qcomserver (pid 492)
            627K: tombstoned (pid 1103)
            604K: qrtr-ns (pid 730)
            499K: ssgqmigd (pid 1080)
    197,523K: System
        197,523K: system (pid 1510)
    278,003K: Persistent
        134,327K: com.android.systemui (pid 2036)
         29,564K: com.android.phone (pid 2291)
         17,227K: com.android.nfc (pid 3070)
         14,010K: com.qualcomm.qti.workloadclassifier (pid 3241)
         12,209K: .dataservices (pid 2160)
         11,870K: com.qualcomm.qti.ustaservice (pid 2262)
         11,319K: .qtidataservices (pid 2236)
         11,309K: com.qualcomm.qti.telephonyservice (pid 2250)
         10,691K: com.qualcomm.qti.services.systemhelper:systemhelper_service (pid 3131)
          9,468K: com.android.se (pid 3202)
          9,047K: com.qualcomm.qti.services.secureui:sui_service (pid 3268)
          6,962K: .pasr (pid 3090)
    112,825K: Foreground
        112,825K: com.example.hxplay (pid 13199 / activities)
    181,522K: Visible
        136,732K: com.android.launcher3 (pid 2401 / activities)
         12,355K: com.qualcomm.qti.sva (pid 3035)
         12,316K: android.ext.services (pid 2477)
         10,723K: com.qualcomm.qcrilmsgtunnel (pid 2612)
          9,396K: com.android.smspush (pid 3353)
     16,185K: Perceptible
         16,185K: com.android.inputmethod.latin (pid 2560)
     34,182K: Previous
         34,182K: com.android.audiotest (pid 28563 / activities)
     65,888K: B Services
         13,345K: com.qualcomm.location.XT (pid 30516)
         10,985K: com.qualcomm.qti.callenhancement (pid 4427)
         10,781K: com.qti.diagservices (pid 18499)
         10,752K: com.qualcomm.qti.modemtestmode (pid 5435)
         10,400K: com.qualcomm.telephony (pid 5277)
          9,625K: com.qualcomm.qti.qdma (pid 3321)
    340,705K: Cached
         50,951K: org.codeaurora.snapcam (pid 11871)
         45,727K: com.henry.basic (pid 13233 / activities)
         31,967K: com.android.webview:webview_service (pid 28725)
         27,245K: com.quectel.cardiagnosis (pid 13165)
         23,462K: com.android.server.telecom:ui (pid 28279)
         22,883K: com.android.permissioncontroller (pid 28851)
         16,459K: android.process.media (pid 3652)
         15,913K: com.android.settings (pid 30898)
         15,307K: com.android.dialer (pid 30983)
         15,029K: android.process.acore (pid 28312)
         12,721K: com.qualcomm.qti.seccamservice:remote (pid 31144)
         12,622K: com.android.providers.calendar (pid 19949)
         12,489K: com.android.cellbroadcastreceiver (pid 19299)
         11,431K: com.qualcomm.qti.smq (pid 3542)
         10,656K: com.android.keychain (pid 12637)
          9,904K: org.chromium.webview_shell (pid 12967)
          5,939K: com.android.printspooler (pid 19936)

Total PSS by category:// 以category划分
    533,188K: Native
    342,413K: .so mmap
    137,556K: EGL mtrack
    117,691K: Unknown
     98,767K: .art mmap
     97,986K: .apk mmap
     86,172K: Gfx dev
     79,756K: GL mtrack
     62,290K: Dalvik
     55,436K: .jar mmap
     53,788K: .dex mmap
     41,159K: Other mmap
     31,214K: .oat mmap
     19,370K: Dalvik Other
      6,975K: .ttf mmap
      6,755K: Stack
      2,194K: Other dev
        488K: Ashmem
          0K: Cursor
          0K: Other mtrack
          
//整体情况
Total RAM: 3,711,580K (status normal)
 Free RAM: 1,417,725K (  340,705K cached pss +   997,660K cached kernel +    79,360K free)
 Used RAM: 1,800,939K (1,458,343K used pss +   342,596K kernel)
 Lost RAM:   511,990K
     ZRAM:     6,776K physical used for    29,680K in swap (2,097,148K total swap)
   Tuning: 512 (large 512), oom   322,560K, restore limit   107,520K (high-end-gfx)

另外,可只输出某个pid或package的进程信息

dumpsys meminfo <pid> // 输出指定pid的某一进程
dumpsys meminfo --package <packagename> // 输出指定包名的进程,可能包含多个进程

将 < packagename> 替换为您要查看的应用程序包名,这将返回该应用程序的内存使用情况,包括堆内存、Native 内存等。

示例:

trinket:/ # dumpsys meminfo com.android.systemui
Applications Memory Usage (in Kilobytes):
Uptime: 85930415 Realtime: 85930415

** MEMINFO in pid 2027 [com.android.systemui] **
                   Pss  Private  Private     Swap     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap    27358    27308        0        0    33420    29399     4020
  Dalvik Heap     6052     6008        0        0    11031     5516     5515
 Dalvik Other     2273     2268        0        0
        Stack       40       40        0        0
       Ashmem       96       92        0        0
      Gfx dev     4332     4332        0        0
    Other dev       44        0       40        0
     .so mmap     2982       88       76        0
    .jar mmap     2108        0      192        0
    .apk mmap    14337        0    11888        0
    .ttf mmap      196        0       52        0
    .dex mmap      173        4      168        0
    .oat mmap      952        0        0        0
    .art mmap     1583     1280        0        0
   Other mmap     1645      476      108        0
   EGL mtrack     3024     3024        0        0
    GL mtrack     2964     2964        0        0
      Unknown     1548     1544        0        0
        TOTAL    71707    49428    12524        0    44451    34915     9535

 App Summary
                       Pss(KB)
                        ------
           Java Heap:     7288
         Native Heap:    27308
                Code:    12468
               Stack:       40
            Graphics:    10320
       Private Other:     4528
              System:     9755

               TOTAL:    71707      TOTAL SWAP (KB):        0

 Objects
               Views:      840         ViewRootImpl:        6
         AppContexts:       16           Activities:        0
              Assets:       14        AssetManagers:        0
       Local Binders:      171        Proxy Binders:       67
       Parcel memory:       22         Parcel count:       75
    Death Recipients:        4      OpenSSL Sockets:        0
            WebViews:        0

 SQL
         MEMORY_USED:        0
  PAGECACHE_OVERFLOW:        0          MALLOC_SIZE:        0
trinket:/ #
  • Pss:Proportional Set Size,进程使用的物理内存大小,按比例分配共享库的内存。
  • Private Dirty:进程使用的私有脏数据内存大小,表示进程独占的脏数据内存。
  • Private Clean:进程使用的私有干净数据内存大小,表示进程独占的干净数据内存。
  • Swap:被交换到磁盘的内存大小。
  • Heap Size:堆内存总大小。
  • Heap Alloc:已分配的堆内存大小。
  • Heap Free:堆内存空闲大小。

在输出中,各个部分的含义如下:

  • Native Heap:本地堆内存使用情况。
  • Dalvik Heap:Dalvik 虚拟机堆内存使用情况。
  • Dalvik Other:Dalvik 虚拟机其他内存使用情况。
  • Stack:栈内存使用情况。
  • Ashmem:共享内存使用情况。
  • Gfx dev:图形设备内存使用情况。
  • Other dev:其他设备内存使用情况。
  • .so mmap:共享库内存映射使用情况。
  • .jar mmap:Java 存档内存映射使用情况。
  • .apk mmap:Android 应用程序包内存映射使用情况。
  • .ttf mmap:TrueType 字体内存映射使用情况。
  • .dex mmap:Dalvik 可执行文件内存映射使用情况。
  • .oat mmap:ART 可执行文件内存映射使用情况。
  • .art mmap:ART 内存映射使用情况。
  • Other mmap:其他内存映射使用情况。
  • EGL mtrack:EGL 内存使用情况。
  • GL mtrack:图形库内存使用情况。
  • Unknown:未知内存使用情况。

App Summary

  • Java Heap:Java 堆内存的使用情况,占用了 7288KB 的内存。
  • Native Heap:本地堆内存的使用情况,占用了 27308KB 的内存。
  • Code:代码段的内存使用情况,占用了 12468KB 的内存。
  • Stack:堆栈的内存使用情况,占用了 40KB 的内存。
  • Graphics:图形相关的内存使用情况,占用了 10320KB 的内存。
  • Private Other:其他私有内存的使用情况,占用了 4528KB 的内存。
  • System:系统内存的使用情况,占用了 9755KB 的内存。
    在总结部分:
  • TOTAL:所有上述部分的内存使用情况总和为 71707KB。
  • TOTAL SWAP:交换空间(Swap)的使用情况为 0KB,表示当前没有使用交换空间。

Objects

Objects:这部分提供了应用程序中对象的相关统计信息。

  • Views:视图对象的数量。
  • ViewRootImpl:视图根对象的数量。
  • AppContexts:应用程序上下文的数量。
  • Activities:活动(Activity)对象的数量。
  • Assets:资源对象的数量。
  • AssetManagers:资源管理器对象的数量。
  • Local Binders:本地 Binder 对象的数量。
  • Proxy Binders:代理 Binder 对象的数量。
  • Parcel memory:Parcel 内存使用情况。
  • Parcel count:Parcel 对象的数量。
  • Death Recipients:死亡接收者对象的数量。
  • OpenSSL Sockets:OpenSSL 套接字对象的数量。
  • WebViews:Web 视图对象的数量。

SQL

  • SQL:这部分提供了与 SQL 数据库相关的内存使用情况。
  • MEMORY_USED:数据库内存使用情况。
  • PAGECACHE_OVERFLOW:页面缓存溢出情况。
  • MALLOC_SIZE:分配大小。

2.4 free指令

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

free -m

xxxxxxx:/ # free -m
                total        used        free      shared     buffers
Mem:             3624        3319         304           7          17
-/+ buffers/cache:           3302         322
Swap:            2047           0        2047
trinket:/ #

内存(Memory)部分:
total:系统总内存为3624 MB。
used:已使用的内存为3319 MB。
free:空闲内存为304 MB。
shared:共享内存为7 MB。
buffers:缓冲区占用了17 MB。
缓存/缓冲区(Buffers/Cache)部分:
-/+ buffers/cache:这一行显示了实际使用的内存情况,去除了缓冲区占用的内存。
used:实际使用的内存为3302 MB。
free:实际空闲内存为322 MB。
交换空间(Swap)部分:
total:交换空间总大小为2047 MB。
used:已使用的交换空间大小为0 MB。
free:剩余可用的交换空间大小为2047 MB。

free 后面还可以跟其他参数:

-b:以字节为单位显示内存使用情况。
-k:以 KB(千字节)为单位显示内存使用情况。
-m:以 MB(兆字节)为单位显示内存使用情况。
-g:以 GB(千兆字节)为单位显示内存使用情况。
-t:在输出的最后一行显示总内存使用情况的总和。
-h:以人类可读的格式(例如,将字节转换为 KB、MB、GB)显示内存使用情况。

使用watch 命令来定期执行 free 命令并显示系统内存使用情况

watch -n 1 free -m

这个命令将每隔 1 秒执行一次 free -m 命令,并在终端中显示当前的内存使用情况(以 MB 为单位)。可以根据需要更改 -n 参数的值来调整更新频率。


2.5 procrank

功能: 获取所有进程的内存使用的排行榜,排行是以Pss的大小而排序。procrank命令比dumpsys meminfo命令,能输出更详细的VSS/RSS/PSS/USS内存指标。

最后一行输出下面6个指标:

totalfreebufferscachedshmemslab

执行结果:

 procrank
  PID       Vss      Rss      Pss      Uss     Swap    PSwap    USwap    ZSwap  cmdline
 1510  8499472K  301680K  149495K  129368K       0K       0K       0K       0K  system_server
13199  5846184K  213156K  110327K  103144K       0K       0K       0K       0K  com.example.hxplay
 2036  6638764K  231108K   99555K   91620K       0K       0K       0K       0K  com.android.systemui
 2401  6294320K  172424K   55903K   48928K       0K       0K       0K       0K  com.android.launcher3
11871  6139768K  162400K   46255K   39872K       0K       0K       0K       0K  org.codeaurora.snapcam
13233  5835764K  147540K   42963K   35672K       0K       0K       0K       0K  com.henry.basic
  598  1734388K  124156K   38585K   11544K       0K       0K       0K       0K  zygote
28725  1879448K   91864K   32391K   15440K      20K      16K      12K       3K  com.android.webview:webview_service
28563  5748916K  120992K   31542K   27560K    1432K      96K       0K      22K  com.android.audiotest
  690   156132K   35852K   31393K   30344K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.camera.provider@2.4-service
 2291  6574624K  131748K   29912K   24920K       0K       0K       0K       0K  com.android.phone
13165  5678620K  106476K   28226K   25500K       0K       0K       0K       0K  com.quectel.cardiagnosis
  753   310044K   44472K   22448K   17868K     212K      78K       0K      17K  /system/bin/surfaceflinger
  738  2655016K   41028K   22081K   19368K       0K       0K       0K       0K  /system/bin/audioserver
 1208  1389244K   39396K   21274K    9208K       0K       0K       0K       0K  /vendor/bin/hw/qcrild
  597  5421464K  146956K   20897K    5556K       4K       4K       4K       0K  zygote64
28279  5808684K  134744K   20790K   12640K    1008K     142K      60K      32K  com.android.server.telecom:ui
 1217  1249916K   38712K   20540K    8484K       0K       0K       0K       0K  /vendor/bin/hw/qcrild
28851  5802572K  141744K   20214K   14364K      24K       1K       0K       0K  com.android.permissioncontroller
  686    53696K   21556K   18295K   17884K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.audio@2.0-service
 2212  1739824K   56604K   17960K    4660K       0K       0K       0K       0K  webview_zygote
 3070  5779904K  105928K   17482K   14784K       0K       0K       0K       0K  com.android.nfc
 2560  5770632K  112208K   16450K   13404K       0K       0K       0K       0K  com.android.inputmethod.latin
30898  5771736K  102956K   16086K   13608K     900K      70K      24K      16K  com.android.settings
 3652  5803580K  105004K   15882K   13052K    2816K     530K     276K     121K  android.process.media
30983  5771068K  101592K   15459K   12604K     932K     102K      56K      23K  com.android.dialer
28312  5748860K  107632K   15255K   12068K       0K       0K       0K       0K  android.process.acore
 3241  5746096K  101580K   14273K   11308K       0K       0K       0K       0K  com.qualcomm.qti.workloadclassifier
30516  5693200K   99928K   13540K   10196K     888K      58K      12K      13K  com.qualcomm.location.XT
  707  2187236K   16496K   13144K   12944K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.wifi@1.0-service
31144  5707888K   98868K   12793K    9392K    1608K     175K      60K      40K  com.qualcomm.qti.seccamservice:remote
19949  5722976K   97664K   12770K   10452K     900K      58K       0K      13K  com.android.providers.calendar
 3035  5770064K   96460K   12558K    9900K       0K       0K       0K       0K  com.qualcomm.qti.sva
 2477  5758552K   93956K   12492K   10104K       0K       0K       0K       0K  android.ext.services
 2160  5791236K   99112K   12469K   10152K       0K       0K       0K       0K  .dataservices
19299  5679996K   86112K   12335K   10512K    2192K     276K     104K      63K  com.android.cellbroadcastreceiver
 2262  5710548K   94676K   12120K    9748K       0K       0K       0K       0K  com.qualcomm.qti.ustaservice
  695   269540K   17128K   11980K   11204K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.gnss@2.0-service-qti
 1074  270699060K   16120K   11634K   11452K      24K      13K       8K       3K  media.swcodec
 2236  5886004K  102244K   11586K    8912K       0K       0K       0K       0K  .qtidataservices
 2250  5702404K   96972K   11578K    9324K       0K       0K       0K       0K  com.qualcomm.qti.telephonyservice
  973  270696216K   26308K   11070K    9284K     680K     327K     124K      74K  media.extractor
 2612  5707972K   96160K   10986K    8816K       0K       0K       0K       0K  com.qualcomm.qcrilmsgtunnel
 3131  5735684K   93580K   10939K    8900K       0K       0K       0K       0K  com.qualcomm.qti.services.systemhelper:systemhelper_service
18499  5707204K   92132K   10887K    8856K    1656K     137K       8K      31K  com.qti.diagservices
12637  5735972K   93400K   10740K    8488K    1832K     138K       0K      31K  com.android.keychain
 5435  5754152K   90888K   10600K    8492K    2480K     288K      60K      65K  com.qualcomm.qti.modemtestmode
 3542  5690060K   91284K   10289K    8212K    4152K    1037K     304K     236K  com.qualcomm.qti.smq
 5277  5722432K   89580K   10236K    8296K    2504K     310K      72K      70K  com.qualcomm.telephony
 1070  1691400K   14892K   10202K    9764K     192K      60K       0K      13K  /system/vendor/bin/netmgrd
12967  5633764K   91752K   10161K    8036K       0K       0K       0K       0K  org.chromium.webview_shell
  696   232976K   18216K   10076K    8940K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.graphics.composer@2.3-service
 4427  5704704K   87424K    9639K    7760K    4348K    1197K     404K     273K  com.qualcomm.qti.callenhancement
 3202  5715000K   85480K    9637K    7744K       0K       0K       0K       0K  com.android.se
 3353  5651104K   84856K    9565K    7720K       0K       0K       0K       0K  com.android.smspush
 3268  5736936K   94488K    9307K    7132K       0K       0K       0K       0K  com.qualcomm.qti.services.secureui:sui_service
  944    52788K   20668K    8939K    6228K     692K     358K     144K      81K  /system/bin/cameraserver
 3321  5776788K   91080K    8726K    6456K    3628K     880K     376K     201K  com.qualcomm.qti.qdma
 1057    76212K   14112K    8389K    7212K     276K     202K     144K      46K  media.codec
  986    68636K   20012K    7672K    4700K     564K     309K     112K      70K  /system/bin/mediaserver
  715   315144K   13756K    7405K    6576K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.perf@2.1-service
 3090  5717908K   90092K    7218K    5156K       0K       0K       0K       0K  .pasr
 1449   233056K    8968K    6242K    6092K       0K       0K       0K       0K  /system/bin/adbd
19936  5679012K   89004K    6181K    3868K       0K       0K       0K       0K  com.android.printspooler
 2232  2239108K    9624K    5632K    5300K       0K       0K       0K       0K  /vendor/bin/hw/wpa_supplicant
 1060  2399284K   10584K    5050K    4456K     128K      44K       0K      10K  /system/vendor/bin/cnd
  985  2242368K   18772K    4752K    3200K     848K     504K     268K     115K  media.metrics
  596   324364K    8108K    4323K    4188K       0K       0K       0K       0K  /system/bin/netd
 1891   155136K    8732K    4292K    3792K       0K       0K       0K       0K  /system/vendor/bin/ims_rtp_daemon
  945    34660K   14336K    4242K    1824K     808K     340K      76K      77K  /system/bin/drmserver
  479   148608K    6260K    4230K    4204K     532K     238K      40K      54K  /system/bin/logd
 1882   137892K    8492K    4201K    3712K       0K       0K       0K       0K  /system/vendor/bin/imsrcsd
 1102   171556K    9764K    3952K    3012K       0K       0K       0K       0K  xtra-daemon
 1202  2320944K    8336K    3447K    2828K       0K       0K       0K       0K  /system/vendor/bin/imsdatadaemon
  700    67576K    8192K    3408K    2864K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.neuralnetworks@1.2-service-qti
  702   241004K    8688K    3230K    2476K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.sensors@2.0-service
 1061    22216K    6140K    2980K    2576K     180K      68K       0K      15K  /vendor/bin/wifidisplayhalservice
  920   668100K    6264K    2757K    2608K     140K      63K       8K      14K  /system/vendor/bin/thermal-engine
  694    79772K    6352K    2722K    2624K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.drm@1.2-service.clearkey
  932    59764K    6020K    2674K    2608K       0K       0K       0K       0K  /system/vendor/bin/cnss_diag
  958   147568K    5784K    2603K    2532K       0K       0K       0K       0K  /system/bin/installd
  962  2161092K    6696K    2583K    2324K     320K     131K       8K      29K  /system/bin/keystore
 1106    44712K    6848K    2469K    2048K       0K       0K       0K       0K  /system/bin/update_engine
  491   133792K    6408K    2407K    2212K     172K      60K       0K      13K  /system/bin/vold
  714    97644K    6852K    2357K    2004K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.iop@2.0-service
    1    68484K    6312K    2329K    1716K    2604K    1918K    1332K     438K  /system/bin/init
 1017   184244K    6136K    2211K    1896K     620K     273K      16K      62K  /system/bin/statsd
 1101  2245376K    5152K    2208K    2124K       0K       0K       0K       0K  lowi-server
  575    79772K    5548K    2159K    1572K       0K       0K       0K       0K  /system/bin/apexd
  775   133356K    6828K    2102K    1448K       0K       0K       0K       0K  /vendor/bin/sensors.qti
  692    77884K    5588K    2075K    1576K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.configstore@1.1-service
  689    41132K    5268K    2070K    2032K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.bluetooth@1.0-service-qti
10341    36160K    4484K    2068K    2000K       0K       0K       0K       0K  procrank
  693    18252K    5268K    2059K    1616K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.drm@1.0-service
  873   113252K    5804K    2044K    1920K       0K       0K       0K       0K  /system/vendor/bin/ipacm
  721    19544K    5304K    2032K    1552K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.scve.objecttracker@1.0-service
  723    44188K    7276K    2007K    1344K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.sensorscalibrate@1.0-service
  956    82144K    5316K    1966K    1820K       0K       0K       0K       0K  /system/bin/incidentd
  722    19728K    5312K    1944K    1436K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.scve.panorama@1.0-service
  709    56652K    5360K    1921K    1840K       0K       0K       0K       0K  /vendor/bin/hw/vendor.nxp.hardware.nfc@1.2-service
 1019    95548K    5476K    1920K    1788K     348K     136K       4K      31K  /system/bin/storaged
  728    78424K    5100K    1916K    1808K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.secure_element@1.0-service
  688    96632K    5848K    1858K    1452K       0K       0K       0K       0K  /system/bin/hw/android.system.suspend@1.0-service
  708    39992K    5204K    1839K    1740K       0K       0K       0K       0K  /vendor/bin/hw/vendor.display.color@1.0-service
  964  2229448K    6756K    1787K    1488K      32K      20K       8K       4K  /system/bin/mediadrmserver
  712    96196K    5756K    1695K    1548K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.display.allocator-service
 1079   152172K    5616K    1690K    1576K     236K     197K     172K      45K  /system/vendor/bin/cnss-daemon
 1126    97188K    4836K    1635K    1428K       0K       0K       0K       0K  /vendor/bin/tloc_daemon
 2863    47684K    3576K    1607K    1488K       0K       0K       0K       0K  /vendor/bin/ssgtzd
 1120   270900K    4376K    1590K    1548K       0K       0K       0K       0K  /system/vendor/bin/qdmastatsd
 1230    96952K    4416K    1584K    1528K       0K       0K       0K       0K  /system/vendor/bin/qti
  741    60200K    5524K    1577K    1500K       0K       0K       0K       0K  /system/bin/gpuservice
  691    15080K    4568K    1556K    1320K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.cas@1.1-service
 1054    18684K    4948K    1533K     908K     344K     221K     124K      50K  /vendor/bin/wfdhdcphalservice
  465    41696K    5088K    1503K    1028K     984K     554K     288K     126K  /system/bin/ueventd
  719    59540K    4936K    1503K    1396K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.qteeconnector@1.0-service
 1254    92768K    4260K    1451K    1396K       0K       0K       0K       0K  /system/vendor/bin/adpl
 1098  2138408K    5276K    1393K    1184K       0K       0K       0K       0K  /system/bin/gatekeeperd
  991   117944K    5648K    1361K    1172K     212K      84K       4K      19K  /system/bin/perfservice
 1158    78240K    4504K    1359K     884K       0K       0K       0K       0K  /system/product/bin/dpmd
  923    73968K    3572K    1351K    1276K       0K       0K       0K       0K  /vendor/bin/adsprpcd
  590   182336K    4100K    1337K    1284K       0K       0K       0K       0K  /vendor/bin/time_daemon
  736   149016K    4452K    1317K    1256K       0K       0K       0K       0K  /vendor/bin/pm-service
  481    43100K    4840K    1289K    1124K     488K     240K      76K      55K  /system/bin/hwservicemanager
  724    76616K    4480K    1279K    1120K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.servicetracker@1.1-service
  711    60396K    4664K    1272K    1164K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.capabilityconfigstore@1.0-service
  463    40028K    4852K    1256K     776K    1116K     768K     488K     175K  /system/bin/init
  917    57876K    4328K    1235K    1176K       0K       0K       0K       0K  /system/vendor/bin/qcom-system-daemon
  919    80340K    4460K    1207K    1108K       0K       0K       0K       0K  /vendor/bin/ATFWD-daemon-Quec
  928    56204K    3876K    1194K    1164K       0K       0K       0K       0K  /system/vendor/bin/imsqmidaemon
  725    37824K    4352K    1175K    1116K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.soter@1.0-service
 1097    80456K    4436K    1157K    1056K       0K       0K       0K       0K  /vendor/bin/ATFWD-daemon
  705    59000K    4076K    1150K    1124K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.usb@1.0-service
 1268   165584K    3480K    1132K    1112K       0K       0K       0K       0K  /vendor/bin/hvdcp_opti
  519    37868K    4284K    1113K    1048K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.gatekeeper@1.0-service-qti
 1086    74668K    3612K    1091K    1048K       0K       0K       0K       0K  /system/vendor/bin/loc_launcher
  518    37628K    4084K    1076K    1044K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.boot@1.0-service
  710    37136K    4452K    1073K     984K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.esepowermanager@1.0-service
  735    60276K    3732K    1064K    1024K       0K       0K       0K       0K  /vendor/bin/pd-mapper
  716    37992K    4256K    1063K    1008K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.qdutils_disp@1.0-service-qti
  697    37624K    4100K    1062K     912K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.health@2.0-service
  701    38904K    4376K    1046K     936K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.power@1.0-service
  520    36972K    4244K    1045K    1008K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.cryptfshw@1.0-service-qti
  704    37464K    4008K    1043K    1016K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.thermal@1.0-service
 1035    38860K    4092K    1037K     984K     416K     164K      12K      37K  /system/bin/wificond
  914    93232K    3884K    1036K     996K       0K       0K       0K       0K  /vendor/bin/pm-proxy
  727    38040K    4300K    1035K     992K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.power.pasrmanager@1.0-service
 1117    56148K    4456K    1012K     524K       0K       0K       0K       0K  /system/product/bin/dpmd
  726    36972K    4268K    1008K     924K       0K       0K       0K       0K  /vendor/bin/hw/vendor.qti.hardware.tui_comm@1.0-service-qti
  483    39352K    4176K    1001K     940K     312K     114K       4K      26K  /vendor/bin/hw/android.hardware.keymaster@4.0-service-qti
  706    37432K    3988K     999K     972K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.vibrator@1.0-service
  698    37436K    3992K     995K     968K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.light@2.0-service
  699    37424K    3960K     971K     944K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.memtrack@1.0-service
  515    55036K    3396K     941K     920K       0K       0K       0K       0K  /system/vendor/bin/ipacm-diag
  517    37392K    3856K     938K     912K       0K       0K       0K       0K  /vendor/bin/hw/android.hardware.atrace@1.0-service
  485   192368K    4608K     913K     720K     720K     286K      16K      65K  /vendor/bin/qseecomd
 1176    34084K    2496K     909K     900K       0K       0K       0K       0K  /system/bin/ip6tables-restore
 1175    34076K    2512K     901K     892K       0K       0K       0K       0K  /system/bin/iptables-restore
  687    38276K    3996K     888K     848K       0K       0K       0K       0K  /system/bin/hw/android.hidl.allocator@1.0-service
  758    38852K    2916K     885K     868K       0K       0K       0K       0K  /vendor/bin/tftp_server
  754    93788K    3216K     878K     852K       0K       0K       0K       0K  /vendor/bin/rmt_storage
 1085    74360K    3304K     868K     792K       0K       0K       0K       0K  /vendor/bin/mlid
  742    37096K    3584K     848K     816K       0K       0K       0K       0K  /system/bin/lmkd
  924    73968K    3084K     847K     772K       0K       0K       0K       0K  /vendor/bin/adsprpcd
27394    33752K    3176K     833K     632K       0K       0K       0K       0K  /data/local/tmp/.studio/process-tracker
  926    73968K    3040K     829K     732K       0K       0K       0K       0K  /vendor/bin/cdsprpcd
  922    73968K    3092K     827K     752K       0K       0K       0K       0K  /vendor/bin/adsprpcd
 9533    33600K    3240K     826K     620K       0K       0K       0K       0K  -/system/bin/sh
 3210    72896K    3336K     803K     780K       0K       0K       0K       0K  /system/vendor/bin/port-bridge
 1073    14400K    3264K     793K     536K     252K     197K     152K      45K  /vendor/bin/wfdvndservice
 1191    35352K    3108K     781K     764K       0K       0K       0K       0K  /vendor/bin/msm_irqbalance
27396    33752K    3244K     780K     580K       0K       0K       0K       0K  /data/local/tmp/.studio/process-tracker
  737    35984K    3136K     742K     720K       0K       0K       0K       0K  /system/bin/ashmemd
 1069    62216K    4400K     729K     672K     752K     529K     384K     120K  /system/vendor/bin/dpmQmiMgr
  912    33600K    2412K     709K     584K       0K       0K       0K       0K  /system/bin/sh
  486    59420K    3824K     678K     592K     584K     214K       0K      48K  /vendor/bin/hw/vendor.qti.hardware.qseecom@1.0-service
 1103    34212K    2328K     630K     620K       0K       0K       0K       0K  /system/bin/tombstoned
  730    34204K    2600K     607K     592K       0K       0K       0K       0K  /vendor/bin/qrtr-ns
 1080     8152K    1828K     506K     436K       0K       0K       0K       0K  /vendor/bin/ssgqmigd
  492    35164K    2744K     441K     420K     256K     111K      24K      25K  /system/vendor/bin/qcomserver
  464    39132K    3752K     427K       4K    1448K     960K     608K     219K  /system/bin/init
  480    35712K    2488K     314K     288K     572K     407K     292K      92K  /system/bin/servicemanager
  482    36380K    2676K     306K     264K     588K     397K     272K      90K  /vendor/bin/vndservicemanager
                           ------   ------   ------   ------   ------   ------  ------
                          1565494K  1263264K   51976K   16129K    7040K    3682K  TOTAL

ZRAM: 6776K physical used for 29680K in swap (2097148K total swap)
 RAM: 3711580K total, 98652K free, 9792K buffers, 1510588K cached, 5760K shmem, 272600K slab

2.6 showmap

用于查看虚拟地址区域的内存情况

  showmap -a [pid]

该命令的输出每一行代表一个虚拟地址区域(vm area)

showmap -a 13199
......
-------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- ------------------------------
           start              end  virtual                     shared   shared  private  private
            addr             addr     size      RSS      PSS    clean    dirty    clean    dirty     swap  swapPSS object
-------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- ------------------------------
                                   5846184   213156   110041    89108    20904     7224    95920        0        0 TOTAL
符号描述
start addr和end addr分别代表进程空间的起止虚拟地址;
virtual size/ RSS /PSS这些前面介绍过;
shared clean代表多个进程的虚拟地址可指向这块物理空间,即有多少个进程共享这个库;
shared共享数据
private该进程私有数据
clean干净数据,是指该内存数据与disk数据一致,当内存紧张时,可直接释放内存,不需要回写到disk
dirty脏数据,与disk数据不一致,需要先回写到disk,才能被释放。

功能与cat /proc/[pid]/maps基本一致。


2.7 vmstat

不仅可以查看内存情况,还可以查看进程运行队列、系统切换、CPU时间占比等情况,另外该指令还是周期性地动态输出。

用法:

Usage: vmstat [ -n iterations ] [ -d delay ] [ -r header_repeat ]
-n iterations 数据循环输出的次数
-d delay 两次数据间的延迟时长(单位:S)
-r header_repeat 循环多少次,再输出一次头信息行

# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 2  0  29680  86520   9792 1519260   1    1     1     6    0   65  2  4 94  0

参数列总共16个参数,分为6大类:

  • procs(进程)
    r: Running队列中进程数量
    b: IO wait的进程数量
  • memory(内存)
    swpd :已经使用的虚拟内存(单位为KB)
    free: 可用内存大小
    buff:用作缓存的内存(单位为KB)
    cache:用作缓存的页内存(单位为KB)
  • swap(交换空间的使用状态)
    si:从磁盘交换到内存的数据量(单位为KB)
    so:从内存交换到磁盘的数据量(单位为KB)
  • io(I/O 活动状况)
    bi:每秒读取的块数(block-in)
    bo:每秒写入的块数(block-out)
  • system(系统)
    in: 每秒的中断次数(包括时钟中断)
    cs: 每秒上下文切换的次数
  • cpu(处理器)
    us:用户空间占用CPU的百分比
    sy:系统空间占用CPU的百分比
    id:空闲 CPU 时间的百分比
    wa:等待 I/O 的 CPU 时间百分比

二、总结

  • dumpsys meminfo: 查看进程的oom adj,或者dalvik/native等区域内存情况,或者某个进程或apk的内存情况,功能非常强大;
  • procrank: 查看进程的VSS/RSS/PSS/USS各个内存指标;
  • cat /proc/meminfo: 查看系统的详尽内存信息,包含内核情况;
  • free: 只查看系统的可用内存;
  • showmap: 查看进程的虚拟地址空间的内存分配情况;
  • vmstat: 周期性地打印出进程运行队列、系统切换、CPU时间占比等情况;
  • MemoryInfo:适合简单粗略的查看内存;
获取内存大小,可以获取总内存,剩余内存,以及已经使用的内存 文件目录: CheckMemory ...........\.idea ...........\.....\.name ...........\.....\androidDexCompiler.xml ...........\.....\compiler.xml ...........\.....\copyright ...........\.....\.........\profiles_settings.xml ...........\.....\encodings.xml ...........\.....\misc.xml ...........\.....\modules.xml ...........\.....\scopes ...........\.....\......\scope_settings.xml ...........\.....\uiDesigner.xml ...........\.....\vcs.xml ...........\.....\workspace.xml ...........\AndroidManifest.xml ...........\ant.properties ...........\assets ...........\bin ...........\build.xml ...........\CheckMemory.iml ...........\gen ...........\...\me ...........\...\..\normalhh ...........\...\..\........\checkmemory ...........\...\..\........\...........\BuildConfig.java ...........\...\..\........\...........\Manifest.java ...........\...\..\........\...........\R.java ...........\libs ...........\local.properties ...........\out ...........\...\production ...........\...\..........\CheckMemory ...........\...\..........\...........\CheckMemory.apk ...........\...\..........\...........\CheckMemory.unaligned.apk ...........\...\..........\...........\me ...........\...\..........\...........\..\normalhh ...........\...\..........\...........\..\........\checkmemory ...........\...\..........\...........\..\........\...........\BuildConfig.class ...........\...\..........\...........\..\........\...........\MyActivity.class ...........\...\..........\...........\..\........\...........\R$attr.class ...........\...\..........\...........\..\........\...........\R$drawable.class ...........\...\..........\...........\..\........\...........\R$id.class ...........\...\..........\...........\..\........\...........\R$layout.class ...........\...\..........\...........\..\........\...........\R$string.class ...........\...\..........\...........\..\........\...........\R.class ...........\proguard-project.txt ...........\project.properties ...........\res ...........\...\drawable-hdpi ...........\...\.............\ic_launcher.png ...........\...\drawable-ldpi ...........\...\.............\ic_launcher.png ...........\...\drawable-mdpi ...........\...\.............\ic_launcher.png ...........\...\drawable-xhdpi ...........\...\..............\ic_launcher.png ...........\...\layout ...........\...\......\main.xml ...........\...\values ...........\...\......\strings.xml ...........\src ...........\...\me ...........\...\..\normalhh ...........\...\..\........\checkmemory ...........\...\..\........\...........\MyActivity.java
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值