Detailed explanation of top command of Linux performance analysis tool

The top command is a commonly used performance analysis tool under Linux. It can display the resource occupancy status of each process in the system in real time, and is often used for server performance analysis.

top command description

[www.linuxidc.com@linuxidc-t-tomcat-188-193 ~]$ top
top - 16:07:37 up 241 days, 20:11,  1 user,  load average: 0.96, 1.13, 1.25
Tasks: 231 total,   1 running, 230 sleeping,   0 stopped,   0 zombie
Cpu(s): 12.7%us,  8.4%sy,  0.0%ni, 77.1%id,  0.0%wa,  0.0%hi,  1.8%si,  0.0%st
Mem:  12196436k total, 12056552k used,   139884k free,    64564k buffers
Swap:  2097144k total,   151016k used,  1946128k free,  3120236k cached

PID     USER      PR    NI   VIRT    RES     SHR    S   %CPU    %MEM        TIME+   COMMAND
18411   pplive    20     0  11.9g   7.8g    5372    S  220.2    67.1     16761:00   java
 1875   pplive    20     0  3958m   127m    4564    S    4.6     1.1     12497:35   java
    4   root      20     0      0      0       0    S    0.3     0.0    184:01.76   ksoftirqd/0
   13   root      20     0      0      0       0    S    0.3     0.0    135:49.83   ksoftirqd/2
   25   root      20     0      0      0       0    S    0.3     0.0    136:54.49   ksoftirqd/5
The result of the top command is divided into two parts:
  • Statistical information: The first five lines are the overall statistical information of the system;
  • Process information: The similar table area below the statistics shows the detailed information of each process, which is refreshed every 5 seconds by default.
Statistics Description:
  • Line 1: Top task queue information (system running status and average load), the same as the result of the uptime command. 
    • Section 1: The current time of the system, for example: 16:07:37
    • Section 2: The system running time, the time it has not been restarted, the longer the time, the more stable the system. 
      • Format: up xx days, HH:MM
      • For example: 241 days, 20:11, which means 241 days, 20 hours and 11 minutes of continuous operation
    • Paragraph 3: The number of currently logged-in users, for example: 1 user, indicating that only 1 user is currently logged in
    • Section 4: System load, that is, the average length of the task queue, three values ​​​​respectively count the system average load in the last 1, 5, and 15 minutes 
      • System average load: In the case of a single-core CPU, 0.00 means no load, 1.00 means just full load, more than 1 side means overload, the ideal value is 0.7;
      • Multi-core CPU load: the number of CPU cores * ideal value 0.7 = ideal load, for example: 4-core CPU load does not exceed 2.8, which means that there is no high load.
  • Line 2: Tasks process related information 
    • Section 1: The total number of processes, for example: Tasks: 231 total, which means a total of 231 processes are running
    • Paragraph 2: The number of running processes, for example: 1 running,
    • Paragraph 3: The number of sleeping processes, for example: 230 sleeping,
    • Paragraph 4: The number of stopped processes, for example: 0 stopped,
    • Paragraph 5: The number of zombie processes, for example: 0 zombie
  • Line 3: Cpus CPU related information. If it is a multi-core CPU, press the number 1 to display the CPU information of each core. At this time, line 1 will be converted to the Cpu core number line, and the number 1 can be switched back and forth. 
    • Section 1: The us percentage of CPU occupied by user space, for example: Cpu(s): 12.7%us,
    • Section 2: The sy percentage of CPU occupied by kernel space, for example: 8.4%sy,
    • 第3段:ni 用户进程空间内改变过优先级的进程占用CPU百分比,例如:0.0%ni,
    • 第4段:id 空闲CPU百分比,例如:77.1%id,
    • 第5段:wa 等待输入输出的CPU时间百分比,例如:0.0%wa,
    • 第6段:hi CPU服务于硬件中断所耗费的时间总额,例如:0.0%hi,
    • 第7段:si CPU服务软中断所耗费的时间总额,例如:1.8%si,
    • 第8段:st Steal time 虚拟机被hypervisor偷去的CPU时间(如果当前处于一个hypervisor下的vm,实际上hypervisor也是要消耗一部分CPU处理时间的)
  • 第4行:Mem 内存相关信息(Mem: 12196436k total, 12056552k used, 139884k free, 64564k buffers) 
    • 第1段:物理内存总量,例如:Mem: 12196436k total,
    • 第2段:使用的物理内存总量,例如:12056552k used,
    • 第3段:空闲内存总量,例如:Mem: 139884k free,
    • 第4段:用作内核缓存的内存量,例如:64564k buffers
  • 第5行:Swap 交换分区相关信息(Swap: 2097144k total, 151016k used, 1946128k free, 3120236k cached) 
    • 第1段:交换区总量,例如:Swap: 2097144k total,
    • 第2段:使用的交换区总量,例如:151016k used,
    • 第3段:空闲交换区总量,例如:1946128k free,
    • 第4段:缓冲的交换区总量,3120236k cached

进程信息:

在top命令中按f按可以查看显示的列信息,按对应字母来开启/关闭列,大写字母表示开启,小写字母表示关闭。带*号的是默认列。

  • A: PID = (Process Id) 进程Id;
  • E: USER = (User Name) 进程所有者的用户名;
  • H: PR = (Priority) 优先级
  • I: NI = (Nice value) nice值。负值表示高优先级,正值表示低优先级
  • O: VIRT = (Virtual Image (kb)) 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
  • Q: RES = (Resident size (kb)) 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
  • T: SHR = (Shared Mem size (kb)) 共享内存大小,单位kb
  • W: S = (Process Status) 进程状态。D=不可中断的睡眠状态,R=运行,S=睡眠,T=跟踪/停止,Z=僵尸进程
  • K: %CPU = (CPU usage) 上次更新到现在的CPU时间占用百分比
  • N: %MEM = (Memory usage (RES)) 进程使用的物理内存百分比
  • M: TIME+ = (CPU Time, hundredths) 进程使用的CPU时间总计,单位1/100秒 
    b: PPID = (Parent Process Pid) 父进程Id 
    c: RUSER = (Real user name) 
    d: UID = (User Id) 进程所有者的用户id 
    f: GROUP = (Group Name) 进程所有者的组名 
    g: TTY = (Controlling Tty) 启动进程的终端名。不是从终端启动的进程则显示为 ? 
    j: P = (Last used cpu (SMP)) 最后使用的CPU,仅在多CPU环境下有意义 
    p: SWAP = (Swapped size (kb)) 进程使用的虚拟内存中,被换出的大小,单位kb 
    l: TIME = (CPU Time) 进程使用的CPU时间总计,单位秒 
    r: CODE = (Code size (kb)) 可执行代码占用的物理内存大小,单位kb 
    s: DATA = (Data+Stack size (kb)) 可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb 
    u: nFLT = (Page Fault count) 页面错误次数 
    v: nDRT = (Dirty Pages count) 最后一次写入到现在,被修改过的页面数 
    y: WCHAN = (Sleeping in Function) 若该进程在睡眠,则显示睡眠中的系统函数名 
    z: Flags = (Task Flags <sched.h>) 任务标志,参考 sched.h
  • X: COMMAND = (Command name/line) 命令名/命令行

top命令选项

  • -b:以批处理模式操作;
  • -c:显示完整的治命令;
  • -d:屏幕刷新间隔时间;
  • -I:忽略失效过程;
  • -s:保密模式;
  • -S:累积模式;
  • -i<时间>:设置间隔时间;
  • -u<用户名>:指定用户名;
  • -p<进程号>:指定进程;
  • -n<次数>:循环显示的次数。

top命令交互

  • 常用交互操作 
    • 基础操作 
      • 1:显示CPU详细信息,每核显示一行
      • d / s :修改刷新频率,单位为秒
      • h:可显示帮助界面
      • n:指定进程列表显示行数,默认为满屏行数
      • q:退出top
    • 面板隐藏显示 
      • l:隐藏/显示第1行负载信息;
      • t:隐藏/显示第2~3行CPU信息;
      • m:隐藏/显示第4~5行内存信息;
    • 进程列表排序 
      • M:根据驻留内存大小进行排序;
      • P:根据CPU使用百分比大小进行排序;
      • T:根据时间/累计时间进行排序;
  • 详细交互指令:h / ? 可显示帮助界面,原始为英文版,简单翻译如下:
Help for Interactive Commands - procps version 3.2.8
Window 1:Def: Cumulative mode Off.  System: Delay 3.0 secs; Secure mode Off.

  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold
            Z:修改颜色配置;B:关闭/开启粗体
  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info
            l:隐藏/显示第1行负载信息;t:隐藏/显示第2~3行CPU信息;m:隐藏/显示第4~5行内存信息;
  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode
            1:单行/多行显示CPU信息;I:Irix/Solaris模式切换
  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order
            f:列显示控制;o:列排序控制,按字母进行调整
  F or O  . Select sort field  选择排序列
  <,>     . Move sort field: '<' next col left; '>' next col right 上下移动内容
  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads
            R:内容排序;H:显示线程
  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time
            c:COMMAND列命令名称与完整命令行路径切换;i:忽略闲置和僵死进程开关;S:累计模式切换
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
            x:列排序;y:运行任务
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
            z:颜色模式;b:粗体开关 仅适用于x,y模式中
  u       . Show specific user only 按用户进行过滤,当输入错误可按Ctrl + Backspace进行删除
  n or #  . Set maximum tasks displayed 设置进程最大显示条数

  k,r       Manipulate tasks: 'k' kill; 'r' renice
            k:终止一个进程;r:重新设置一个进程的优先级别
  d or s    Set update interval  改变两次刷新之间的延迟时间(单位为s),如果有小数,就换算成ms。输入0值则系统将不断刷新,默认值是5s;
  W         Write configuration file 将当前设置写入~/.toprc文件中
  q         Quit       退出
          ( commands shown with '.' require a visible task display window )
            注意:带.的命令需要一个可见的任务显示窗口

Guess you like

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