6.18 Top

Top指令是Linux下的指令,因此Android上也可以使用Top指令来查看当前进程的CPU信息。在adb shell下,通过输入如下所示的代码来查看Top指令的使用方法。

  1. shell@mako:/ $ top -h
  2. Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
  3. -m num Maximum number of processes to display.
  4. -n num Updates to show before exiting.
  5. -d num Seconds to wait between updates.
  6. -s col Column to sort by (cpu,vss,rss,thr).
  7. -t Show threads instead of processes.
  8. -h Display this help screen.

常用的参数含义如下所示。

  • m,最多显示多少个进程。
  • n,刷新次数。
  • d,刷新间隔时间。
  • s,排序方式。

例如下面这些指令。

  1. shell@mako:/ $ top -n 1 -m 5 -d 1
  2.  
  3.  
  4.  
  5. User 8%, System 9%, IOW 0%, IRQ 0%
  6. User 18 + Nice 0 + Sys 19 + Idle 163 + IOW 2 + IRQ 0 + SIRQ 0 = 202
  7.  
  8. PID PR CPU% S #THR VSS RSS PCY UID Name
  9. 2238 0 6% S 94 1961132K 170656K fg u0_a255 com.hujiang.hjclass
  10. 18631 1 4% R 1 2420K 948K shell top
  11. 596 0 3% S 94 1616456K 112752K fg system system_server
  12. 173 1 1% S 17 81224K 10896K fg system /system/bin/surfaceflinger
  13. 207 1 1% S 8 9560K 680K nobody /system/bin/sensors.qcom

执行指令的含义为,刷新一次(-n 1),前5个进程(-m 5),间隔1秒(-d 1)。显示的信息列表,主要包含两个部分——总览和详细。