美文网首页
分析命令

分析命令

作者: superme_ | 来源:发表于2022-08-15 12:46 被阅读0次

1.内存的指标

Item全称描述类型

USS Unique Set Size进程独占的内存(不包含共享库占用的内存)物理内存

PSS  Proportional Set Size进程独占 + 比例分配共享库占用的内存物理内存

RSS Resident Set Size进程独占 + 共享库占用的内存物理内存

VSS Virtual Set SizeRSS + 未分配的物理内存虚拟内存

2.内存分析工具

2.1 proc/meminfo

查看详细的内存信息

cat proc/meminfo

MemTotal:        1002660 kB

MemFree:          39140 kB

MemAvailable:    609280 kB

Buffers:          20668 kB

Cached:          548972 kB

SwapCached:          856 kB

Active:          453564 kB

Inactive:        314604 kB

Active(anon):      83800 kB

Inactive(anon):  118824 kB

Active(file):    369764 kB

Inactive(file):  195780 kB

Unevictable:        2712 kB

Mlocked:            1044 kB

HighTotal:        504636 kB

HighFree:          2256 kB

LowTotal:        498024 kB

LowFree:          36884 kB

SwapTotal:        751988 kB

SwapFree:        738184 kB

Dirty:                68 kB

Writeback:            0 kB

AnonPages:        200976 kB

Mapped:          259604 kB

Shmem:              2428 kB

Slab:              45996 kB

SReclaimable:      19152 kB

SUnreclaim:        26844 kB

KernelStack:        7656 kB

PageTables:        15224 kB

NFS_Unstable:          0 kB

Bounce:                0 kB

WritebackTmp:          0 kB

CommitLimit:    1253316 kB

Committed_AS:  16471656 kB

VmallocTotal:    499712 kB

VmallocUsed:          0 kB

VmallocChunk:          0 kB

CmaTotal:              0 kB

CmaFree:              0 kB

MemTotal:表示系统内存总数 // 1002660 kB

系统从上电启动到引导完成,内核中需要保留部分内存,剩下的内存总数即为 MemTotal,这个值在系统运行期间保持不变。

MemFree:空闲内存总数//  39140 kB

表示系统中尚未使用的内存, MemTotal - MemFree 表示已经用掉的内存。

MemAvailable:可用内存 //609280 kB

应用程序可用内存数,系统中存在一些已经被使用但是可以回收的内存,比如Buffers、Cached和slab的部分,所以 MemFree 不能代表全部可用的内存,加上可以回收的内存才是系统可用内存的总和。//  39140 kB +  20668 kB + 548972 kB = 608780

比如 MemAvailable ≈ MemFree + Buffers + Cached,这里是内核计算出来的估值。MemFree表示系统层面,MemAvailable泛指应用层面。

Buffers:缓冲区内存

Cached:缓存区内存

2.2 free

# freetotal        used        free      shared    buffersMem: 4033196032 1199968256 2833227776 119869440 56078336-/+ buffers/cache:    1143889920  2889306112Swap: 2016256000 0 2016256000# free -mtotal        used        free      shared    buffersMem: 3846 1144 2701 114 53-/+ buffers/cache:          1091        2755Swap: 1922 0 1922

轻量级的内存查看工具,内容来源于proc/meminfo.

Mem.total = Mem.used + Mem.free,即 3846 = 1144 + 2701;

Mem.used - Mem.buffers = buffers.used,即 1144 - 53 = 1091;

Mem.free + Mem.buffers = buffers.free, 即 2701 + 53 = 2755;

2.3 dumpsys meminfo

输出的结果大致按照4个部分排序,分别Total PSS by process、Total PSS by OOM adjustment、Total PSS by category 和 Total RAM.

Total PSS by process:以进程的PSS从大到小排序

Total PSS by OOM adjustment:分别显示每个类型进程的情况,Native/System/Persistent/Foreground/Visible/Perceptible/A Services/Home/B Services/Cached.

Total PSS by category:以Dalvik/Native/.art mmap/.dex map等划分的各类进程的总PSS情况

Total:显示总内存、可用内存、已使用内存、其他内存.

tb8765ap1_bsp_1g:/ # dumpsys meminfo

Applications Memory Usage (in Kilobytes):

Uptime: 53063974 Realtime: 53063974

Total PSS by process:

    99,553K: com.baidu.launcher (pid 1628 / activities)

    46,172K: system (pid 631)

    36,404K: com.baidu.launcher:remote (pid 423)

    30,586K: com.baidu.input (pid 1835)

    22,029K: com.baidu.duer.thirdapp (pid 1446)

    18,381K: logd (pid 260)

    14,762K: camerahalserver (pid 361)

    13,589K: surfaceflinger (pid 305)

    10,911K: android.process.acore (pid 1549)

    10,244K: android.process.media (pid 1498)

    10,147K: zygote (pid 288)

      9,986K: com.baidu.duer.thirdapp:ota (pid 1981)

      8,502K: com.baidu.duer.ota:ota (pid 2062)

      7,983K: cameraserver (pid 344)

      7,426K: visionmanagerserver (pid 387)

      7,246K: android.hardware.audio@2.0-service-mediatek (pid 291)

      6,850K: com.baidu.duer.ota (pid 1424)

      6,727K: media.codec (pid 359)

      6,507K: mediaserver (pid 351)

      6,134K: android.hardware.graphics.composer@2.1-service (pid 298)

      6,035K: com.baidu.duershow.statistic (pid 1416)

      6,018K: com.mediatek.engineermode (pid 1766)

      5,768K: merged_hal_service (pid 300)

      4,809K: com.baidu.oases (pid 2448)

      4,723K: com.baidu.mesh.provisioner (pid 1477)

      4,706K: audioserver (pid 342)

      4,620K: vulture.watchdog (pid 1461)

      4,203K: com.mediatek.bluetooth.dtt (pid 2477)

      4,060K: com.mediatek.providers.drm (pid 2507)

      3,543K: com.mediatek.thermalmanager (pid 2556)

      3,540K: wpa_supplicant (pid 2712)

      3,416K: media.extractor (pid 350)

      3,349K: drmserver (pid 345)

      2,894K: /init (pid 1)

      1,873K: android.hardware.wifi@1.0-service (pid 299)

      1,702K: android.hardware.drm@1.0-service.widevine (pid 296)

      1,688K: mnld (pid 340)

      1,622K: vold (pid 277)

      1,543K: netd (pid 287)

      1,503K: lmkd (pid 304)

      1,335K: mtk_advcamserver (pid 355)

      1,324K: keystore (pid 348)

      1,225K: vendor.mediatek.hardware.pq@2.0-service (pid 371)

      1,190K: installd (pid 347)

      1,180K: ueventd (pid 214)

      1,160K: hwservicemanager (pid 262)

      1,124K: wificond (pid 358)

      1,113K: android.hardware.sensors@1.0-service-mediatek (pid 360)

      1,079K: adbd (pid 1346)

      1,056K: android.hardware.keymaster@3.0-service (pid 276)

      1,037K: ged_srv (pid 1361)

        918K: mediadrmserver (pid 349)

        877K: gatekeeperd (pid 373)

        873K: vendor.mediatek.hardware.dfps@1.0-service (pid 301)

        851K: thermalserviced (pid 306)

        802K: storaged (pid 357)

        780K: android.hardware.broadcastradio@1.1-service (pid 293)

        763K: healthd (pid 302)

        762K: aee_aedv (pid 684)

        757K: android.hardware.bluetooth@1.0-service-mediatek (pid 292)

        720K: android.hardware.gatekeeper@1.0-service (pid 297)

        718K: android.hardware.cas@1.0-service (pid 294)

        682K: aee_aed (pid 534)

        680K: ip6tables-restore (pid 315)

        674K: iptables-restore (pid 314)

        674K: netdagent (pid 377)

        647K: fuelgauged (pid 336)

        637K: android.hardware.configstore@1.0-service (pid 295)

        627K: netdiag (pid 356)

        619K: servicemanager (pid 261)

        590K: mobile_log_d (pid 353)

        573K: android.hidl.allocator@1.0-service (pid 290)

        573K: hardcoder_server (pid 339)

        571K: program_binary_service (pid 374)

        567K: dumpsys (pid 3739)

        560K: vndservicemanager (pid 263)

        548K: sh (pid 2799)

        541K: sh (pid 6705)

        538K: sh (pid 333)

        530K: thermald (pid 346)

        525K: tombstoned (pid 376)

        523K: batterywarning (pid 343)

        518K: logcat (pid 337)

        506K: ipsec_mon (pid 368)

        495K: met_log_d (pid 352)

        493K: asguard (pid 726)

        477K: thermalloadalgod (pid 335)

        460K: oasesd (pid 727)

        449K: klogd (pid 338)

        445K: duershow_localservice (pid 303)

        442K: sysenv_daemon (pid 370)

        421K: wifi2agps (pid 372)

        410K: thermal (pid 365)

        404K: wmt_launcher (pid 313)

Total PSS by OOM adjustment:

    171,549K: Native

        18,381K: logd (pid 260)

        14,762K: camerahalserver (pid 361)

        13,589K: surfaceflinger (pid 305)

        10,147K: zygote (pid 288)

          7,983K: cameraserver (pid 344)

          7,426K: visionmanagerserver (pid 387)

          7,246K: android.hardware.audio@2.0-service-mediatek (pid 291)

          6,727K: media.codec (pid 359)

          6,507K: mediaserver (pid 351)

          6,134K: android.hardware.graphics.composer@2.1-service (pid 298)

          5,768K: merged_hal_service (pid 300)

          4,706K: audioserver (pid 342)

          3,540K: wpa_supplicant (pid 2712)

          3,416K: media.extractor (pid 350)

          3,349K: drmserver (pid 345)

          2,894K: /init (pid 1)

          1,873K: android.hardware.wifi@1.0-service (pid 299)

          1,702K: android.hardware.drm@1.0-service.widevine (pid 296)

          1,688K: mnld (pid 340)

          1,622K: vold (pid 277)

          1,543K: netd (pid 287)

          1,503K: lmkd (pid 304)

          1,335K: mtk_advcamserver (pid 355)

          1,324K: keystore (pid 348)

          1,225K: vendor.mediatek.hardware.pq@2.0-service (pid 371)

          1,190K: installd (pid 347)

          1,180K: ueventd (pid 214)

          1,160K: hwservicemanager (pid 262)

          1,124K: wificond (pid 358)

          1,113K: android.hardware.sensors@1.0-service-mediatek (pid 360)

          1,079K: adbd (pid 1346)

          1,056K: android.hardware.keymaster@3.0-service (pid 276)

          1,037K: ged_srv (pid 1361)

            918K: mediadrmserver (pid 349)

            877K: gatekeeperd (pid 373)

            873K: vendor.mediatek.hardware.dfps@1.0-service (pid 301)

            851K: thermalserviced (pid 306)

            802K: storaged (pid 357)

            780K: android.hardware.broadcastradio@1.1-service (pid 293)

            763K: healthd (pid 302)

            762K: aee_aedv (pid 684)

            757K: android.hardware.bluetooth@1.0-service-mediatek (pid 292)

            720K: android.hardware.gatekeeper@1.0-service (pid 297)

            718K: android.hardware.cas@1.0-service (pid 294)

            682K: aee_aed (pid 534)

            680K: ip6tables-restore (pid 315)

            674K: iptables-restore (pid 314)

            674K: netdagent (pid 377)

            647K: fuelgauged (pid 336)

            637K: android.hardware.configstore@1.0-service (pid 295)

            627K: netdiag (pid 356)

            619K: servicemanager (pid 261)

            590K: mobile_log_d (pid 353)

            573K: android.hidl.allocator@1.0-service (pid 290)

            573K: hardcoder_server (pid 339)

            571K: program_binary_service (pid 374)

            567K: dumpsys (pid 3739)

            560K: vndservicemanager (pid 263)

            548K: sh (pid 2799)

            541K: sh (pid 6705)

            538K: sh (pid 333)

            530K: thermald (pid 346)

            525K: tombstoned (pid 376)

            523K: batterywarning (pid 343)

            518K: logcat (pid 337)

            506K: ipsec_mon (pid 368)

            495K: met_log_d (pid 352)

            493K: asguard (pid 726)

            477K: thermalloadalgod (pid 335)

            460K: oasesd (pid 727)

            449K: klogd (pid 338)

            445K: duershow_localservice (pid 303)

            442K: sysenv_daemon (pid 370)

            421K: wifi2agps (pid 372)

            410K: thermal (pid 365)

            404K: wmt_launcher (pid 313)

    46,172K: System

        46,172K: system (pid 631)

    198,702K: Persistent

        99,553K: com.baidu.launcher (pid 1628 / activities)

        36,404K: com.baidu.launcher:remote (pid 423)

        22,029K: com.baidu.duer.thirdapp (pid 1446)

          9,986K: com.baidu.duer.thirdapp:ota (pid 1981)

          8,502K: com.baidu.duer.ota:ota (pid 2062)

          6,850K: com.baidu.duer.ota (pid 1424)

          6,035K: com.baidu.duershow.statistic (pid 1416)

          4,723K: com.baidu.mesh.provisioner (pid 1477)

          4,620K: vulture.watchdog (pid 1461)

    74,374K: Cached

        30,586K: com.baidu.input (pid 1835)

        10,911K: android.process.acore (pid 1549)

        10,244K: android.process.media (pid 1498)

          6,018K: com.mediatek.engineermode (pid 1766)

          4,809K: com.baidu.oases (pid 2448)

          4,203K: com.mediatek.bluetooth.dtt (pid 2477)

          4,060K: com.mediatek.providers.drm (pid 2507)

          3,543K: com.mediatek.thermalmanager (pid 2556)

Total PSS by category:

    107,935K: .so mmap

    102,685K: .dex mmap

    81,292K: Native

    35,131K: .apk mmap

    33,565K: Unknown

    30,561K: Dalvik

    18,331K: .art mmap

    16,827K: Other mmap

    15,580K: .oat mmap

    10,677K: GL mtrack

    10,372K: Dalvik Other

    10,131K: EGL mtrack

      2,664K: Stack

      1,800K: Ashmem

        574K: Other dev

        268K: .ttf mmap

          0K: Cursor

          0K: Gfx dev

          0K: .jar mmap

          0K: Other mtrack

Total RAM: 1,002,660K (status moderate)

Free RAM:  441,070K (  74,374K cached pss +  330,464K cached kernel +    36,232K free)

Used RAM:  492,779K (  416,423K used pss +    76,356K kernel)

Lost RAM:    71,241K

    ZRAM:    5,032K physical used for    13,364K in swap (  751,988K total swap)

  Tuning: 128 (large 256), oom  184,320K, restore limit    61,440K (low-ram)

dumpsys meminfo <pid> // 输出指定pid的某一进程

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

2.4 procrank

获取所有进程的内存使用的排行榜,排行是以Pss的大小而排序.

# procrankPID      Vss      Rss      Pss      Uss  cmdline4694715244K199568K93953K76772K  system_server6284774604K184272K79868K63260K  com.android.systemui3781581340K116848K63536K35956K  zygote10545048780K130504K33086K20376K  com.android.launcher33774239348K130300K28338K8012K  zygote646871333924K54604K25609K5504K  /system/bin/webview_zygote327494338336K108900K25539K16612K  com.android.phone26375200K27620K18690K16088K  /vendor/bin/hw/android.hardware.neuralnetworks@1.0-service-armnn6064330764K91380K15649K9656K  com.android.inputmethod.latin269312884K27868K13869K10336K  /system/bin/surfaceflinger11704321764K92900K13701K6336K  android.process.media13024323936K84736K13004K8064K  com.android.email25553284K21308K10199K6972K  /vendor/bin/hw/android.hardware.camera.provider@2.4-service11404317440K82832K9876K3808K  android.rockchip.update.service18504318536K75692K8379K4096K  com.android.calendar12844315752K77148K8185K3796K  com.android.providers.calendar38773924K18420K7686K5064K  /system/bin/mediaserver11904315400K71948K7137K2800K  com.android.quicksearchbox18764315996K74824K6986K2668K  com.android.mtp39131860K12104K6845K5644K  media.codec10214315960K70452K6835K3020K  com.android.printspooler10114314012K69076K6658K2864K  com.cghs.stresstest37943520K12616K6621K4920K  /system/bin/audioserver3852164032K18588K6493K4324K  media.extractor14074315816K70584K6403K2296K  android.ext.services11144314788K69144K5972K2240K  com.android.keychain10694313648K67308K5792K2156K  com.android.smspush25316256K7892K4116K2808K  /vendor/bin/hw/android.hardware.audio@2.0-service38024908K11124K3948K2544K  /system/bin/cameraserver3862128240K11312K3220K2156K  media.metrics26133120K7556K3022K2432K  /vendor/bin/hw/android.hardware.graphics.composer@2.1-service23219996K5304K2915K2820K  /system/bin/logd38118964K9884K2836K1652K  /system/bin/drmserver26614404K6140K2798K2604K  /vendor/bin/hw/android.hardware.wifi@1.0-service25812756K6560K2463K1904K  /vendor/bin/hw/android.hardware.drm@1.0-service24555064K7468K2421K2024K  /system/bin/vold38831004K6548K2225K1980K  /system/bin/netd25911140K5328K1985K1588K  /vendor/bin/hw/android.hardware.drm@1.0-service.widevine38319280K6492K1811K1348K  /system/bin/keystore38219676K5636K1809K1616K  /system/bin/installd111968K2436K1714K1092K  /init23414408K5576K1653K1352K  /system/bin/hwservicemanager184112932K1700K1511K1504K  /system/bin/adbd39015096K5632K1507K1312K  /system/bin/wificond26516888K5044K1439K1164K  /vendor/bin/hw/android.hardware.sensors@1.0-service24414848K5904K1422K928K  /vendor/bin/hw/android.hardware.keymaster@3.0-service38410688K5308K1297K804K  /system/bin/mediadrmserver26017480K5224K1261K960K  /vendor/bin/hw/android.hardware.graphics.allocator@2.0-service39315560K5612K1245K1000K  /system/bin/gatekeeperd4039468K3296K1244K1188K  /system/bin/ip6tables-restore4029452K3200K1165K1116K  /system/bin/iptables-restore2076080K1768K1158K568K  /sbin/ueventd203816940K3304K1145K1088K  procrank27013924K5000K1142K944K  /system/bin/thermalserviced38915988K4292K1090K960K  /system/bin/storaged25412244K4212K1042K868K  /vendor/bin/hw/android.hardware.bluetooth@1.0-service2569048K4108K1018K596K  /vendor/bin/hw/android.hardware.cas@1.0-service25715372K4372K1017K828K  /vendor/bin/hw/android.hardware.configstore@1.0-service26713464K4504K993K860K  /system/bin/healthd26212136K4168K896K676K  /vendor/bin/hw/android.hardware.light@2.0-service26412140K4168K870K668K  /vendor/bin/hw/android.hardware.power@1.0-service23310444K3428K848K760K  /system/bin/servicemanager23510244K3256K805K696K  /vendor/bin/vndservicemanager25212088K4088K767K636K  /system/bin/hw/android.hidl.allocator@1.0-service19838932K3008K736K548K  /system/bin/sh2748932K2944K727K540K  /system/bin/sh2689180K3072K681K624K  /system/bin/lmkd3959028K3004K662K600K  /system/bin/tombstoned                          ------  ------  ------601566K385996K  TOTAL RAM:3938668K total,2765940K free,54772K buffers,683920K cached,117060K shmem,119748K slab

2.5 showmap

该命令的输出每一行代表一个虚拟地址区域(vm_area),内容基本和proc/pid/maps基本一致.

# showmap -a 1302startendvirtualsharedsharedprivateprivateaddr    addr    size      RSS      PSS    clean    dirty    clean    dirty    swap  swapPSSobject    -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- ------------------------------0b65b0000b65c000400000000[anon:thread stack guard page]

start addr: 虚拟地址的起始地址

end addr: 虚拟地址的结束地址

virutal size: 占用虚拟内存大小

RSS:进程独占内存 + 共享库占用内存的物理内存

PSS:进程独占内存 + 比例分配共享库占用的物理内存

shared:共享数据

private:私有数据

2.6 vmstat

vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----

r  b  swpd  free  buff  cache  si  so    bi    bo  in  cs us sy id wa

1  0  13284  47120  20668 542996    1    1    4    9    0  101  1  1 98  0

2.7 ps

ps -A -eo USER,MAJFL,MINFL,PID,RSS,CPU,TIME 其中的 MAJFL,MINFL分别是磁盘交换/swap交换次数

相关文章

网友评论

      本文标题:分析命令

      本文链接:https://www.haomeiwen.com/subject/swdnrktx.html