PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ PPID RUSER UID GROUP TTY P SWAP TIME CODE DATA nFLT nDRT WCHAN Flags COMMAND 21862 dc 20 0 5113m 551m 5096 S 0.0 3.5 25:34.77 1 dc 555 dc ? 4 0 25:34 4 4.8g 13k 0 futex_wai ..4.2... java 12692 dc 20 0 5109m 513m 5792 S 0.2 3.2 19:54.09 1 dc 555 dc ? 2 0 19:54 4 4.8g 30k 0 futex_wai ..4.2... java 20299 dc 20 0 5054m 508m 2644 S 0.0 3.2 179:37.25 1 dc 555 dc ? 4 0 179:37 4 4.8g 65k 0 futex_wai ..4.2... java ...
top命令可以实时显示正在执行进程的CPU使用率、内存使用率以及系统负载等信息
上半部分显示的是系统的统计信息,下半部分显示的是进程的使用率统计信息
系统的统计信息
Cpu
%us:用户空间占用CPU百分比
%sy:内核空间占用CPU百分比
%ni:用户进程空间内改变过优先级的进程占用CPU百分比
%id:空闲CPU百分比
%wa:等待输入输出的CPU时间百分比
%hi:硬件中断占用百分比
%si:软中断占用百分比
%st:虚拟机占用百分比
进程的使用率统计信息
PID: Process Id
The task’s unique process ID, which periodically wraps, though never restarting at zero.
PPID: Parent Process Pid
The process ID of a task’s parent.
RUSER: Real User Name
The real user name of the task’s owner.
UID: User Id
The effective user ID of the task’s owner.
USER: User Name
The effective user name of the task’s owner.
GROUP: Group Name
The effective group name of the task’s owner.
TTY: Controlling Tty
The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. However, a task need not be associated with a terminal, in which case you’ll see '?' displayed.
%CPU: CPU usage
The task’s share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
In a true SMP environment, if ‘Irix mode’ is Off, top will operate in ‘Solaris mode’ where a task’s cpu usage will be divided by the total number of CPUs. You toggle ‘Irix/Solaris’ modes with the ‘I’ interactive command.
S: Process Status
The status of the task which can be one of
'D' = uninterruptible sleep
'R' = running
'S' = sleeping
'T' = traced or stopped
'Z' = zombie
Tasks shown as running should be more properly thought of as ready to run
their task_struct is simply represented on the Linux run-queue.
Even without a true SMP machine, you may see numerous tasks in this state depending on top’s delay interval and nice value.
P: Last used CPU (SMP)
A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).
PR: Priority
The priority of the task.
NI: Nice value
The nice value of the task.
A negative nice value means higher priority, whereas a positive nice value means lower priority.
Zero in this field simply means priority will not be adjusted in determining a task’s dispatchability.
TIME: CPU Time
Total CPU time the task has used since it started.
TIME+: CPU Time, hundredths
The same as ‘TIME’, but reflecting more granularity through hundredths of a second.
%MEM: Memory usage (RES)
A task’s currently used share of available physical memory.
RES: Resident size (kb)
The non-swapped physical memory a task has used.
RES = CODE + DATA.
CODE: Code size (kb)
The amount of physical memory devoted to executable code, also known as the 'text resident set' size or TRS.
DATA: Data+Stack size (kb)
The amount of physical memory devoted to other than executable code, also known as the 'data resident set' size or DRS.
SWAP: Swapped size (kb)
Per-process swap values are now taken from /proc/#/status VmSwap field.
VIRT: Virtual Image (kb)
The total amount of virtual memory used by the task.
It includes all code, data and shared libraries plus pages that have been swapped out.
SHR: Shared Mem size (kb)
The amount of shared memory used by a task.
It simply reflects memory that could be potentially shared with other processes.
nFLT: Page Fault count
The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A major page fault is when disk access is involved in making that page available.
nDRT: Dirty Pages count
The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page.
WCHAN: Sleeping in Function
Depending on the availability of the kernel link map (‘System.map’), this field will show the name or the address of the kernel function in which the task is currently sleeping. Running tasks will display a dash (‘-‘) in this column.
Flags: Task Flags
This column represents the task’s current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed.
COMMAND: Command line or Program name
常用选项
-a : Sort by memory usage
This switch makes top to sort the processes by allocated memory
-d : Delay time interval as: -d ss.tt (seconds.tenths)
Specifies the delay between screen updates, and overrides the corresponding value in one’s personal configuration file or the startup default.
Later this can be changed with the 'd' or 's'interactive commands.
-H : Threads toggle
When this toggle is On, all individual threads will be displayed. Otherwise, top displays a summation of all threads in a process.
-M : Detect memory units
Show memory units (k/M/G) and display floating point values in the memory summary.
-n : Number of iterations limit as: -n number
Specifies the maximum number of iterations, or frames, top should produce before ending
Monitor only processes with specified process IDs. This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids. Co-mingling both approaches is permitted.
This is a command-line option only. And should you wish to return to normal operation, it is not necessary to quit and and restart top – just issue the ‘=’ interactive command.
f,o . Fields/Columns: 'f' add or remove; 'o' change display order 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 c,i,S . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time x,y . Toggle highlights: 'x' sort field; 'y' running tasks z,b . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y') u . Show specific user only n or # . Set maximum tasks displayed
k,r Manipulate tasks: 'k' kill; 'r' renice d or s Set update interval W Write configuration file q Quit ( commands shown with '.' require a visible task display window ) Press 'h' or '?' for help with Windows, any other key to continue
vmstat
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ vmstat -S M 1 5 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 2 0 0 295 1 5684 0 0 8 23 1 2 5 1 93 0 0 0 0 0 295 1 5684 0 0 0 0 11326 25112 6 5 90 0 0 0 0 0 295 1 5685 0 0 0 0 10855 24065 2 2 96 0 0 0 0 0 294 1 5686 0 0 0 4 11756 25472 4 2 94 0 0 0 0 0 294 1 5686 0 0 0 0 10208 22726 4 4 91 0 0
$ jmap -histo -F 23594 | head Attaching to process ID 23594, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.65-b04 Iterating over heap. This may take a while... Object Histogram:
$ jmap -dump:format=b,file=/tmp/wall.hprof -F 23594 Attaching to process ID 23594, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.65-b04 Dumping heap to /tmp/wall.hprof ... Heap dump file created