adb shell top 使用


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 的使用方法。
:~$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机识别:
:~$adb devices
List of devices attached
d111a8ac device
 
进入android设备的shell:
:~$adb shell
:/ #
查看 top 指令的帮助菜单:
:/ #top -h
 
从帮助菜单可以看出,PC级别的系统的 top 指令和 android 设备的 top 指令的使用方法还是有点区别的。

top指令查看进程资源:
:/ #top
每隔 3s 更新一次显示:
:/ #top -d 3
按cpu大小列出5个进程列表:
:/ #top -m 5
根据进程的名字使用 grep 指令过滤输出 "com.hcb.parking" 进程的信息(图中实际上是每隔 1s 输出一次信息):
:/ #top -d 1 | grep "com.hcb.parking"
查看"com.hcb.parking" 应用(或者说"com.hcb.parking" 进程)中所有线程的CPU等信息:
:/ #top -d 1 -t | grep "com.hcb.parking"
 
每间隔 3s 将 "com.hcb.parking" 进程的CPU 信息保存到文件:
:/ #top -d 3 | grep "com.hcb.parking" > /data/topinfo.txt &

从android设备中将上一步保存的 topinfo.txt 日志信息复制出来(该命令是在退出adb shell 之后执行的):
:~/work$ adb pull /data/topinfo.txt .

原文:https://www.cnblogs.com/111testing/p/8911993.html

相关推荐