adb shell top
top命令提供了實時的對系統處理器的狀態監視.它將顯示系統中CPU最“敏感”的任務列表.該命令可以按CPU使用.內存使用和執行時間對任務進行排序.
1)top 用法
>adb shell top -h
Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [-t ] [ -h ]
-m num Maximum number of processes to display. 最多顯示多少個進程
-n num Updates to show before exiting. 刷新次數
-d num Seconds to wait between updates. 刷新間隔時間(默認5秒)
-s col Column to sort by (cpu,vss,rss,thr). 按哪列排序
-t Show threads instead of processes. 顯示線程信息而不是進程
-h Display this help screen. 顯示幫助文檔
2)adb shell top
> adb shell top
User 13%, System 5%, IOW 0%, IRQ 0%
User 85 + Nice 0 + Sys 37 + Idle 509 + IOW 0 + IRQ 0 + SIRQ 0 = 631
PID PR CPU% S #THR VSS RSS PCY UID Name
0 13% S 56 423416K 88160K fg u0_a92 com.tmall.wireless
1 2% R 1 1232K 536K root top
0 1% S 46 341712K 40872K fg u0_a90 com.wandoujia.phoenix2.usbproxy
1 1% S 31 319976K 33284K fg u0_a74 com.android.Chinpower
0 1% S 32 67320K 20552K fg system /system/bin/surfaceflinger
0 1% S 112 445876K 80304K fg system system_server
...
0 0% S 1 0K 0K root watchdog/0
1 0% S 1 0K 0K root khelper
1 0% S 1 0K 0K root suspend_sys_syn
1 0% S 1 0K 0K root suspend
第一組數據的含義:
User 處於用戶態的運行時間,不包含優先值為負進程
Nice 優先值為負的進程所占用的CPU時間
Sys 處於核心態的運行時間
Idle 除IO等待時間以外的其它等待時間
IOW IO等待時間
IRQ 硬中斷時間
SIRQ 軟中斷時間
第二組數據的含義:
PID 進程id
PR 優先級
CPU% 當前瞬時CPU占用率
S 進程狀態:D=不可中斷的睡眠狀態, R=運行, S=睡眠, T=跟蹤/停止, Z=僵屍進程
#THR 程序當前所用的線程數
VSS Virtual Set Size 虛擬耗用內存(包含共享庫占用的內存)
RSS Resident Set Size 實際使用物理內存(包含共享庫占用的內存)
PCY 調度策略優先級,SP_BACKGROUND/SP_FOREGROUND
UID 進程所有者的用戶id
Name 進程的名稱
具體信息可以查看源代碼中: xx\system\core\toolbox\top.c
>adb shell top | findstr tmall > d:\cpu.txt
打印 top命令,並查找 包含 tmall的命令行,輸出至 d:\cpu.txt
result:
22137 1 0% S 10 304728K 28900K bg u0_a92 com.tmall.wireless:push
22205 0 0% S 15 322944K 38236K bg u0_a92 com.tmall.wireless
22205 1 27% R 34 345304K 49396K fg u0_a92 com.tmall.wireless
在 ubuntu 系統輸入top -h,可以看到 top 的使用方法。
omj@pc-ubuntu:~$top -h
procps-ng version 3.3.9
Usage:
top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
這里我們主要是談 top 指令在 android 系統下的使用,所以首先要用 usb 線連接PC和設備,然后進入android設備的 shell,查看 top 指令的相關用法。
查看android設備是否被PC機識別:
omj@pc-ubuntu:~$adb devices
List of devices attached
d111a8ac device
進入android設備的shell:
omj@pc-ubuntu:~$adb shell
root@msm8610:/ #
查看 top 指令的幫助菜單:
root@msm8610:/ #top -h
從幫助菜單可以看出,PC級別的系統的 top 指令和 android 設備的 top 指令的使用方法還是有點區別的。
top指令查看進程資源:
root@msm8610:/ #top
每隔 3s 更新一次顯示:
root@msm8610:/ #top -d 3
按cpu大小列出5個進程列表:
root@msm8610:/ #top -m 5
根據進程的名字使用 grep 指令過濾輸出 "com.hcb.parking" 進程的信息(圖中實際上是每隔 1s 輸出一次信息):
root@msm8610:/ #top -d 1 | grep "com.hcb.parking"
查看"com.hcb.parking" 應用(或者說"com.hcb.parking" 進程)中所有線程的CPU等信息:
root@msm8610:/ #top -d 1 -t | grep "com.hcb.parking"
每間隔 3s 將 "com.hcb.parking" 進程的CPU 信息保存到文件:
root@msm8610:/ #top -d 3 | grep "com.hcb.parking" > /data/topinfo.txt &
從android設備中將上一步保存的 topinfo.txt 日志信息復制出來(該命令是在退出adb shell 之后執行的):
omj@pc-ubuntu:~/work$ adb pull /data/topinfo.txt .
原文:https://www.cnblogs.com/111testing/p/8911993.html