zoukankan      html  css  js  c++  java
  • adb shell top 命令【实时的对系统处理器的状态监视】

    原文地址https://blog.csdn.net/kittyboy0001/article/details/38562515

    原文地址https://blog.csdn.net/u010503912/article/details/51518705

    adb shell top

    top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序.

    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.  显示帮助文档 
    复制代码

    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
    第一组数据的含义: 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 进程的名称


    Tasks: 552 total,   1 running, 510 sleeping,   0 stopped,   0 zombie 
    任务(进程) 系统现在共有552个进程,其中处于运行中的有1个,510个在休眠(sleep),stoped状态的有0个,zombie状态(僵尸)的有0个。

    Mem:   5849960k total,  4014628k used,  1835332k free,     5756k buffers   
    内存状态: 物理内存总量 (5.6G)  使用中的内存总量  空闲内存总量 缓存的内存量
    1TB=1024GB ,1GB=1024MB ,1MB=1024KB ,1KB=1024字节。

    Swap:  2293756k total,  1039804k used,  1253952k free,   918600k cached 
    swap交换分区: 交换区总量  使用的交换区总量  空闲交换区总量  缓冲的交换区总量

    如果出于习惯去计算可用内存数,这里有个近似的计算公式:
    Mem的free + Mem的buffers + Swap的cached
    按这个公式此台服务器的可用内存:1835332k + 5756k + 918600k = 2759688k(约2.6G)

    800%cpu  13%user   0%nice  31%sys 756%idle   0%iow   0%irq   0%sirq   0%host   
    cpu状态 
    800%cpu -- CPU总量
    13%user -- 用户空间占用CPU的百分比。
    0%nice -- 改变过优先级的进程占用CPU的百分比
    31%sys -- 内核空间占用CPU的百分比
    756%idle -- 空闲CPU百分比
    0%iow  --  IO等待占用CPU的百分比
    0%irq -- 硬中断(Hardware IRQ)占用CPU的百分比
    0%sirq --  软中断(Software Interrupts)占用CPU的百分比
    0%host --

     

    PID — 进程id
    USER — 进程所有者
    PR — 进程优先级
    NI — nice值。负值表示高优先级,正值表示低优先级
    VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
    RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
    SHR — 共享内存大小,单位kb
    S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
    %CPU — 上次更新到现在的CPU时间占用百分比
    %MEM — 进程使用的物理内存百分比
    TIME+ — 进程使用的CPU时间总计,单位1/100秒
    COMMAND — 进程名称(命令名/命令行)

      PID USER         PR  NI VIRT  RES  SHR S[%CPU] %MEM     TIME+ ARGS                                                 
    25059 shell        20   0  10M 2.4M 1.5M R 25.0   0.0   0:00.08 top
    20678 u0_a21       20   0 4.5G  27M  23M S  9.3   0.4   0:02.56 com.google.android.gms.unstable
    24458 root         20   0    0    0    0 S  3.1   0.0   0:01.81 [kworker/u16:4]
    24367 root         20   0    0    0    0 S  3.1   0.0   0:03.28 [kworker/2:1]
    1092 system       18  -2 4.9G 184M  90M S  3.1   3.2 417:44.25 system_server
    复制代码

    具体信息可以查看源代码中: xxsystemcore oolbox op.c

    监控CPU的命令使用实战

    复制代码
    >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
    
    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调试之top指令查看系统资源

    为了有效地排除CPU资源消耗问题,对top指令进行了研究,本文不会面面俱到地谈top指令各种参数的使用,而是选择部分比较实用的参数来谈谈调试的一些技巧。
    在 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 .
     
     
    【备注】
    如无法查看cpu信息,则需要先运行打印信息指令:
    adb root
    adb remount
    adb shell "echo 1 117000 0 mtktscpu-sysrst 0 0 no-cooler 0 0 no-cooler 0 0 no-cooler 0 0 no-cooler 0 0 no-cooler 0 0 no-cooler 0 0 no-cooler 0 0 no-cooler 0 0 no-cooler 1000 1 > /proc/driver/thermal/tzcpu"
    adb shell "cat /proc/thermlmt"
    adb shell "echo 4 4 > /proc/ppm/policy/ut_fix_core_num"
    adb shell "echo 0 0 > /proc/ppm/policy/ut_fix_freq_idx"
    adb shell "cat /sys/devices/system/cpu/online"
    adb shell "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
    adb shell "cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq"
    adb shell "cat /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq"
    adb shell "cat /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq"
    adb shell "cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq"
    adb shell "cat /sys/devices/system/cpu/cpu5/cpufreq/scaling_cur_freq"
    adb shell "cat /sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq"
    adb shell "cat /sys/devices/system/cpu/cpu7/cpufreq/scaling_cur_freq"
    @pause
    【复制上段代码,建文本并且保存为.bat文件即可直接运行 打印信息指令】
  • 相关阅读:
    bzoj3280
    bzoj3876
    洛谷 p1625
    bzoj1407
    bzoj1227
    bzoj1477 && exgcd学习笔记
    bzoj1345
    c#程序的config文件问题
    思维角度的重要性
    python异步初步窥探
  • 原文地址:https://www.cnblogs.com/flyingcode/p/13690223.html
Copyright © 2011-2022 走看看