Android——top命令

时间:2025-03-30 09:38:33

一、top命令

adb shell top --help
usage: top [-Hbq] [-k FIELD,] [-o FIELD,] [-s SORT] [-n NUMBER] [-d SECONDS] [-p PID,] [-u USER,]

Show process activity in real time.

-H      Show threads
-k      Fallback sort FIELDS (default -S,-%CPU,-ETIME,-PID)
-o      Show FIELDS (def PID,USER,PR,NI,VIRT,RES,SHR,S,%CPU,%MEM,TIME+,CMDLINE)
-O      Add FIELDS (replacing PR,NI,VIRT,RES,SHR,S from default)
-s      Sort by field number (1-X, default 9) 选择根据某项(cpu,vss,rss,thr)来排序
-b      Batch mode (no tty)
-d      Delay SECONDS between each cycle (default 3)
		更新的时间间隔,默认是每隔3s更新下状态,top -d 0时会持续地输出,不过很占CPU。
-n      Exit after NUMBER iterations  显示n次top的结果后命令就会退出
-p      Show these PIDs
-u      Show these USERs
-q      Quiet (no header lines)

Cursor LEFT/RIGHT to change sort, UP/DOWN move list, space to force
update, R to reverse sort, Q to exit.
adb shell top
[?25l[0m[H[J[s[999C[999B[6n[uTasks: 445 total,   1 running, 435 sleeping,   0 stopped,   2 zombie
Mem:   2866500k total,  2794280k used,    72220k free,    77912k buffers
Swap:   520908k total,   315604k used,   205304k free,   978836k cached
800%cpu  14%user   0%nice  29%sys 757%idle   0%iow   0%irq   0%sirq   0%host
PID    USER        PR  NI VIRT  RES SHR S [%CPU] %MEM     TIME+ ARGS            [0m
14357 shell        20   0  10M 2.1M 1.4M R 22.8   0.0   0:00.13 top
12739 root         20   0    0    0    0 S  2.8   0.0   0:05.11 [kworker/u16:2]
11967 root          0 -20    0    0    0 S  2.8   0.0   0:00.91 [kworker/u17:1]
 7704 u0_a127      20   0 1.7G  65M  47M S  2.8   2.3   1:20.68 com.tencent.mob+

VIRT:虚拟内存,假如进程申请10m的内存,但实际只使用了5m,那么它会增长10m,而不是实际的使用量。
RES:常驻内存,进程当前使用的内存大小,但不包括swap out。
SHR:共享内存,除了自身进程的共享内存,也包括其他进程的共享内存
计算某个进程所占的物理内存大小公式:RES – SHR