1. 程式人生 > >adb shell 命令

adb shell 命令

adb shell top

top命令提供了實時的對系統處理器的狀態監視.它將顯示系統中CPU最“敏感”的任務列表.該命令可以按CPU使用.記憶體使用和執行時間對任務進行排序.

top 用法

 
  1. >adb shell top -h

  2. Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [-t ] [ -h ]

  3. -m num Maximum number of processes to display. 最多顯示多少個程序

  4. -n num Updates to show before exiting. 重新整理次數

  5. -d num Seconds to wait between updates. 重新整理間隔時間(預設5秒)

  6. -s col Column to sort by (cpu,vss,rss,thr). 按哪列排序

  7. -t Show threads instead of processes. 顯示執行緒資訊而不是程序

  8. -h Display this help screen. 顯示幫助文件

adb shell top

 
  1. > adb shell top

  2.  
  3. User 13%, System 5%, IOW 0%, IRQ 0%

  4. User 85 + Nice 0 + Sys 37 + Idle 509 + IOW 0 + IRQ 0 + SIRQ 0 = 631

  5.  
  6. PID PR CPU% S #THR VSS RSS PCY UID Name

  7. 22205 0 13% S 56 423416K 88160K fg u0_a92 com.tmall.wireless

  8. 24310 1 2% R 1 1232K 536K root top

  9. 22600 0 1% S 46 341712K 40872K fg u0_a90 com.wandoujia.phoenix2.usbproxy

  10. 31125 1 1% S 31 319976K 33284K fg u0_a74 com.android.Chinpower

  11. 1533 0 1% S 32 67320K 20552K fg system /system/bin/surfaceflinger

  12. 1852 0 1% S 112 445876K 80304K fg system system_server

  13. ...

  14. 10 0 0% S 1 0K 0K root watchdog/0

  15. 16 1 0% S 1 0K 0K root khelper

  16. 22 1 0% S 1 0K 0K root suspend_sys_syn

  17. 23 1 0% S 1 0K 0K root suspend

第一組資料的含義:

 
  1. User 處於使用者態的執行時間,不包含優先值為負程序

  2. Nice 優先值為負的程序所佔用的CPU時間

  3. Sys 處於核心態的執行時間

  4. Idle 除IO等待時間以外的其它等待時間

  5. IOW IO等待時間

  6. IRQ 硬中斷時間

  7. SIRQ 軟中斷時間

第二組資料的含義:

 
  1. PID 程序id

  2. PR 優先順序

  3. CPU% 當前瞬時CPU佔用率

  4. S 程序狀態:D=不可中斷的睡眠狀態, R=執行, S=睡眠, T=跟蹤/停止, Z=殭屍程序

  5. #THR 程式當前所用的執行緒數

  6. VSS Virtual Set Size 虛擬耗用記憶體(包含共享庫佔用的記憶體)

  7. RSS Resident Set Size 實際使用實體記憶體(包含共享庫佔用的記憶體)

  8. PCY 排程策略優先順序,SP_BACKGROUND/SP_FOREGROUND

  9. UID 程序所有者的使用者id

  10. Name 程序的名稱

具體資訊可以檢視原始碼中: xx\system\core\toolbox\top.c

監控CPU的命令使用實戰

>adb shell top  | findstr tmall > d:\cpu.txt   

列印 top命令,並查詢 包含 tmall的命令列,輸出至 d:\cpu.txt

result:

 
  1. 22137 1 0% S 10 304728K 28900K bg u0_a92 com.tmall.wireless:push

  2.  
  3. 22205 0 0% S 15 322944K 38236K bg u0_a92 com.tmall.wireless

  4.  
  5. 22205 1 27% R 34 345304K 49396K fg u0_a92 com.tmall.wireless

  6.  
  7. 22112 1 0% S 9 303704K 29380K bg u0_a92 com.tmall.wireless:containerprocess1

  8.  
  9. 22137 1 0% S 10 304728K 28900K bg u0_a92 com.tmall.wireless:push

  10.  
  11. 22252 1 0% S 9 302600K 28596K fg u0_a92 com.tmall.wireless:notify

  12.  
  13. 22205 0 45% R 40 365500K 56708K fg u0_a92 com.tmall.wireless

  14.  
  15. 22252 0 22% S 19 325476K 40868K bg u0_a92 com.tmall.wireless:notify

  16.  
  17. 22137 0 2% S 14 308944K 31320K fg u0_a92 com.tmall.wireless:push

  18.  
  19. 22112 0 0% S 9 305892K 29888K bg u0_a92 com.tmall.wireless:containerprocess1

  20.  
  21. 22137 1 14% S 17 323080K 39696K bg u0_a92 com.tmall.wireless:push

  22.  
  23. 22252 0 3% S 21 327656K 41556K bg u0_a92 com.tmall.wireless:notify

  24.  
  25. 22205 1 2% S 38 366420K 59700K fg u0_a92 com.tmall.wireless

  26.  
  27. 22112 0 0% S 9 305892K 29888K bg u0_a92 com.tmall.wireless:containerprocess1

  28.  
  29. 22408 0 0% R 9 278424K 21936K fg u0_a92 com.tmall.wireless:utremote

  30.  
  31. 22408 1 7% S 9 304180K 30964K bg u0_a92 com.tmall.wireless:utremote

  32.  
  33. 22205 0 2% R 39 367456K 59612K fg u0_a92 com.tmall.wireless