adb shell top command

Original address https://blog.csdn.net/kittyboy0001/article/details/38562515

Original address https://blog.csdn.net/u010503912/article/details/51518705

adb shell top

The top command provides real-time monitoring of the system's processor status. It will display a list of the most CPU-sensitive tasks in the system. The command can sort tasks by CPU usage, memory usage, and execution time.

top usage

>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.  显示帮助文档 

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
22205  0  13% S    56 423416K  88160K  fg u0_a92   com.tmall.wireless
24310  1   2% R     1   1232K    536K     root     top
22600  0   1% S    46 341712K  40872K  fg u0_a90   com.wandoujia.phoenix2.usbproxy
31125  1   1% S    31 319976K  33284K  fg u0_a74   com.android.Chinpower
 1533  0   1% S    32  67320K  20552K  fg system   /system/bin/surfaceflinger
 1852  0   1% S   112 445876K  80304K  fg system   system_server
    ...
   10  0   0% S     1      0K      0K     root     watchdog/0
   16  1   0% S     1      0K      0K     root     khelper
   22  1   0% S     1      0K      0K     root     suspend_sys_syn
   23  1   0% S     1      0K      0K     root     suspend

The meaning of the first set of data:

User  处于用户态的运行时间,不包含优先值为负进程 
Nice  优先值为负的进程所占用的CPU时间 
Sys   处于核心态的运行时间 
Idle  除IO等待时间以外的其它等待时间 
IOW   IO等待时间 
IRQ   硬中断时间 
SIRQ  软中断时间 

The meaning of the second set of data:

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  进程的名称

Specific information can be found in the source code: xx\system\core\toolbox\top.c

Command usage of monitoring CPU

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

Print the top command and find the command line containing tmall, output to 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


======================================================================================================

android debugging top command to view system resources

Recently, when the application software developed by the customer was running on our customized android device (customized OS), the problem of black screen restart occurred. Before determining the problem, we need to reproduce the bug phenomenon reported by the customer. Due to the lack of understanding of the customer's software functions and other information at the beginning, it is difficult to reproduce the bug phenomenon during the test. When testing the printing function of the printer, it is accidentally found that the continuous printing of the printer will easily cause excessive CPU resource consumption. , and even cause the system to restart (the software does not respond, and the watchdog restarts the system after 5s). In order to effectively eliminate the problem of CPU resource consumption, the top command has been studied. This article will not talk about the use of various parameters of the top command, but select some of the more practical parameters to talk about some debugging skills.
Enter top -h in the ubuntu system to see how top is used.
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]
 
Here we mainly talk about the use of the top command under the android system, so first connect the PC and the device with a usb cable, and then enter the shell of the android device to view the related usage of the top command.
 
Check if the android device is recognized by the PC:
omj@pc-ubuntu:~$adb devices
List of devices attached
d111a8ac device
 
Enter the shell of the android device:
omj@pc-ubuntu:~$adb shell
root@msm8610:/ #
See the help menu for the top command:
root@msm8610:/ #top -h
 
 
As can be seen from the help menu, the top command of the PC-level system is slightly different from that of the android device.
 
The top command to view process resources:
root@msm8610:/ #top
 
Update the display every 3s:
root@msm8610:/ #top -d 3
 
List of 5 processes by cpu size:
root@msm8610:/ #top -m 5
 
 
Use the grep command to filter and output the information of the "com.hcb.parking" process according to the name of the process (in the figure, the information is actually output every 1s):
root@msm8610:/ #top -d 1 | grep "com.hcb.parking"
 
 
 
Check the CPU and other information of all threads in the "com.hcb.parking" application (or "com.hcb.parking" process):
root@msm8610:/ #top -d 1 -t | grep "com.hcb.parking"
 
 
Save the CPU information of the "com.hcb.parking" process to a file every 3s:
root@msm8610:/ #top -d 3 | grep "com.hcb.parking" > /data/topinfo.txt &
 
Copy the topinfo.txt log information saved in the previous step from the android device (this command is executed after exiting the adb shell):
omj@pc-ubuntu:~/work$ adb pull /data/topinfo.txt .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324657460&siteId=291194637