linux performance analysis commands ps,top,vmstat use

Keywords: less Unix Attribute SSL

ps

* Grammar: ps [options]
Note: This command looks at the instantaneous running state of a process at a given time, and looks at it discontinuously.
Three options are supported:
UNIX options such as - a (prefix -)
BSD options such as a
Display processes in the current terminal by default
The a option includes processes in all terminals
The x option includes processes with disconnected terminals (processes with TTY status of?
The u option displays information about the process owner
The f option shows the parent process of the process
The o attribute... Options to display customized information:
pid,comm,%cpu,%mem,state,tty,euser,ruser***

[14:38 root@Centos6.8/proc/10]# ps aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.0  19352  1548 ?        Ss   08:46   0:02 /sbin/init
root          2  0.0  0.0      0     0 ?        S    08:46   0:00 [kthreadd]
root       2007  0.0  0.0   4064   544 tty2     Ss+  08:48   0:00 /sbin/mingetty /dev/tty2
root       2012  0.0  0.0   4064   540 tty3     Ss+  08:48   0:00 /sbin/mingetty /dev/tty3
root       2014  0.0  0.0   4064   544 tty4     Ss+  08:48   0:00 /sbin/mingetty /dev/tty4
root       2017  0.0  0.0   4064   540 tty5     Ss+  08:48   0:00 /sbin/mingetty /dev/tty5
root       2019  0.0  0.0   4064   544 tty6     Ss+  08:48   0:00 /sbin/mingetty /dev/tty6
root       2028  0.0  0.1  12640  2876 ?        S<   08:48   0:00 /sbin/udevd -d
root       2060  0.0  0.1 164924  3564 ?        Sl   08:48   0:00 /usr/libexec/gdm-simple-slave --display-id /org/gnome/DisplayManager
root       2064  0.0  1.5 196384 29084 tty1     Ssl+ 08:48   0:04 /usr/bin/Xorg :0 -br -verbose -audit 4 -auth /var/run/gdm/auth-for-g
root       2087  0.0  0.1 1036464 3360 ?        Sl   08:48   0:00 /usr/sbin/console-kit-daemon --no-daemon
gdm        2159  0.0  0.0  20044   696 ?        S    08:48   0:00 /usr/bin/dbus-launch --exit-with-session

** USER: Users who initiate the process
PID:PID number
% CPU: Percentage of CPU used
% MEM: Percentage of memory used
VSZ: Virtual memory SiZe, virtual memory set, linear memory
RSS: ReSidentSize, Permanent Memory Set
TTY: Terminally related
STAT: Process state
START: Process Start Time
TIME: The time that a process actually runs on the CPU, not on the hang-up table
COMMANDD: The command to initiate a process, [If the command has middle brackets, it represents a kernel process]**

ps - Sort by how much memory the process consumes
ps -eo rss,pmem,pcpu,vsize,args | sort -k 1 -r -n | less

top

top

top - 16:55:12 up 4 days, 19:15,  3 users,  load average: 0.00, 0.00, 0.00
Tasks: 169 total,   1 running, 168 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.7%us,  0.7%sy,  0.0%ni, 98.3%id,  0.0%wa,  0.0%hi,  0.3%si,  0.0%st
Mem:   1004768k total,   876500k used,   128268k free,   114876k buffers
Swap:  2031612k total,        8k used,  2031604k free,   388272k cached


   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                  
  4635 w         20   0  291m  17m  14m S  1.0  1.8   8:20.21 vmtoolsd                                                  
  1552 root      20   0  173m 8104 4540 S  0.7  0.8  15:36.70 vmtoolsd                                                  
  3074 mysql     20   0  895m  73m  12m S  0.7  7.5   6:55.30 mysqld                                                    
  4572 w         20   0  494m  10m 8192 S  0.7  1.1   0:12.53 gnome-settings-                                           
     7 root      20   0     0    0    0 S  0.3  0.0   9:44.50 events/0                                                  
    24 root      20   0     0    0    0 S  0.3  0.0   3:02.92 ata_sff/0                                                 
   729 root      20   0     0    0    0 S  0.3  0.0   0:28.84 vmmemctl                                                  
  3492 root      20   0  134m 9528 1052 S  0.3  0.9   7:19.99 redis-server                                              
  4983 root      20   0 99976 4048 3088 S  0.3  0.4   0:03.41 sshd                                                      
  5373 root      20   0 15032 1272  928 R  0.3  0.1   0:00.17 top                                                       
     1 root      20   0 19356 1544 1228 S  0.0  0.2   0:07.43 init                                                      
     2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                  
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0                                               
     4 root      20   0     0    0    0 S  0.0  0.0   0:56.32 ksoftirqd/0                                               
     5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0                                                 
     6 root      RT   0     0    0    0 S  0.0  0.0   0:13.14 watchdog/0                                                
     8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events/0                                                  
     9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_long/0                                             
    10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_power_ef                                           
    11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup                                                    
    12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper                                                   
    13 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns                                                     
    14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr                                                 
    15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm                                                        
    16 root      20   0     0    0    0 S  0.0  0.0   0:06.45 sync_supers 

uptime

CPU load in the past 15 minutes
16:58:37 up 109 days, 16:57, 1 user, load average: 0.00, 0.00, 0.00

If this number is divided by the number of CPU s, the result above 5 indicates that the system is overloaded. Normally, it should be controlled within the range of less than 1. Usually we first look at the 15-minute load, if the load is very high, then look at the 1-minute and 5-minute load to see if there is a downward trend.

The first line is the task queue information, along with the execution results of the uptime command. Its contents are as follows:
01:06:48 Current Time
up 1:22 system runtime in time:
1 user Current number of logged-in users
load average: 0.06, 0.60, 0.48 system load, that is, the average length of the task queue.
The three values are 1 minute, 5 minutes and 15 minutes ago to the present average.

Second, third, the information of behavior process and CPU. When there are multiple CPUs, these contents may exceed two lines. The contents are as follows:
Tasks: 29 total process total
1 Number of running processes
Number of Sleeping Processes
Number of processes stopped by 0 stopped
Number of zombie botnet processes
Cpu(s): 0.3% us user space as a percentage of CPU
1.0% sy Kernel Space Percentage of CPU
Percentage of CPU occupied by processes that changed priority in 0.0% ni user process space
98.7% id idle CPU percentage
Percentage of CPU time for 0.0% wa to wait for input and output
0.0% hi
0.0% si

The last two behaviors are memory information. The contents are as follows:
Mem: 191272k total physical memory
Total physical memory used by 173656k user
17616k free Total Free Memory
The amount of memory 22052k buffers use as kernel caches
Swap: Total exchange area 192772k
Total switching area used by 0k user
Total Free Exchange Area 192772k
The total number of switches buffered by 123988k cache.

vmstat

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 629036 269024 553024    0    0     6     4  163  109  1  2 97  0  0    

When the value of SY is relatively high, it means that the CPU time consumed by the kernel is more; if us+sy exceeds 80%, it means that the CPU resources are insufficient.

r represents the run queue (that is, how many processes are actually allocated to the CPU), and if this value exceeds the number of CPUs, there will be CPU bottlenecks, which are related to the top load.
b denotes a blocking process
swpd virtual memory has been used size, if greater than 0 means machine physical memory is insufficient
Free denotes the size of free physical memory.
The buff linux/unix system is a cache used to store contents, permissions, etc. in a directory.
Cache is used to remember the files we open, to cache the files, and to cache the files and directories with the spare physical memory. It is to improve the performance of program execution when the program uses memory. Buffer / cache will be used quickly

The size of virtual memory read from disk by si per second, if greater than 0, indicates that physical memory is insufficient
so virtual memory per second is written to disk in the same size as above

The number of blocks received per second by a bi block device. The block device here is essentially all disks and other block devices on the system. The default block size is 1024 byte.
The number of blocks sent per second by bo devices is close to 0 for bi and bo Ibanez. Otherwise, IO is too frequent and needs to be adjusted.
The bi+bo reference value set here is 1000, and if it exceeds 1000 and wa value is relatively large, it indicates that the system disk IO performance bottleneck.

in the number of CPU interrupts per second, including time interrupts.
The number of context switching per second of cs, such as when we call system functions, we need to switch context, thread switching, and process context switching. The smaller the value, the better, the larger the value. We should consider lowering the number of threads or processes. For example, in web servers such as apache and nginx, we usually do thousands of concurrent or even tens of thousands of concurrent performance tests. Testing, the process of selecting the web server can be downgraded by the peak value of the process or thread until CS reaches a relatively small value, and the number of processes and threads is the appropriate value. System calls are also, every time we call system functions, our code will enter the kernel space, leading to context switching, which is very resource-intensive, but also try to avoid frequent calls to system functions. Too many context switching times mean that most of your CPU is wasted on context switching, resulting in less time for CPU to do serious work, and CPU is not fully utilized, which is not advisable.

U user CPU time, I used to do encryption and decryption on a very frequent server, you can see us close to 100,r run queue up to 80 (the machine in stress testing, poor performance).
When the value of us is relatively high, it means that the CPU time consumed by the user process is too much. If the CPU time is longer than 50%, we need to consider the optimization program.
When the value of SY is relatively high, it means that the CPU time consumed by the kernel is more; if us+sy exceeds 80%, it means that the CPU resources are insufficient.
sy system CPU time, if too high, means long system call time, such as frequent IO operations.
ID idle CPU time, generally speaking, id + us + sy = 100, generally I think id is idle CPU usage, us is user CPU usage, sy is system CPU usage.
wa waits for IO CPU time.
The wa list shows the percentage of CPU time IO waits take. The higher wa value, the more serious IO waiting. If wa value exceeds 20%, IO waits seriously.

Get memory usage information for a particular process

Get the pid of the mysqld process
[root@6 ~]# pidof mysqld
top Specifies View PID
[root@6 ~]# top -p 21538

Viewing Threads for a Specific Process
top -H -p

Change from: http://www.mamicode.com/info-detail-1519419.html
https://my.oschina.net/u/1396185/blog/366043

Posted by rickmans on Wed, 22 May 2019 14:19:39 -0700