Linux系统监控:pidstat

简介:

Linux上可以使用sysstat包(可能需要自己安装)中的pidstat监控JAVA应用的让步式上下文切换和抢占式上下文切换。让步式上下文切换是指执行线程主动释放CPU,抢占式上下文切换是指线程因为分配的时间片用尽而被迫放弃CPU或被其他优先级更高的线程所抢占。

应用中挂起和唤醒线程会导致操作系统的让步式上下文切换,因此锁竞争严重的应用会表现出大量的让步式上下文切换,而让步式上下文切换耗费的时钟周期代价非常高。

抢占式上下文切换率高表明预备运行的线程数多于可用的虚拟处理器,所以此时用vmstat通常能看到很长的运行队列、很高的CPU使用率。

pidstat - Report statistics for Linux tasks. 

Linux任务的统计数据。

SYNOPSIS

pidstat [ -d ] [ -h ] [ -I ] [ -l ] [ -R ] [ -r ] [ -s ] [ -t ] [ -U [ username ] ] [ -u ] [ -V ] [ -v ] [ -w ] [ -C comm ] [ -G process_name ] [ -p { pid [,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ] [ interval [ count ] ]

DESCRIPTION

pidstat命令用来监控Linux内核管理的各个任务。它将使用-p选项指定的每个任务的活动情况输出到标准输出,可以使用-p All输出Linux内核管理的所有任务。不使用-p等同于-p ALL,但是只有活动的任务会出现在报告中。

pidstat命令也可以用来监控所选择任务的子进程。参考-T选项了解更多。

OPTIONS

-C comm

Display only tasks whose command name includes the string comm. This string can be a regular expression.

只展示命令名称包含字符串comm的任务。comm可以是正则表达式。

-d

Report I/O statistics (kernels 2.6.20 and later only). The following values may be displayed:

报告I/O统计数据(内核2.6.20或更高)。以下值将被展示:

UID

The real user identification number of the task being monitored.

被监控任务的用户id。

USER

The real user name of the task being monitored.

被监控任务的用户名。

PID

The identification number of the task being monitored.

被监控任务的PID。

kB_rd/s

Number of kilobytes the task has caused to be read from disk per second.

任务每秒从磁盘读取的数据,以kb为单位。

kB_wr/s

Number of kilobytes the task has caused, or shall cause to be written to disk per second.

任务每秒从磁盘写入或将要写入的数据,以kb为单位

kB_ccwr/s

Number of kilobytes whose writing to disk has been cancelled by the task. This may occur when the task truncates some dirty pagecache. In this case, some IO which another task has been accounted for will not be happening.

任务取消的写入磁盘的kb数。在任务压缩脏页缓存时可能发生这种情况。在这种情况下,其他任务发起的IO不会处理。

iodelay

Block I/O delay of the task being monitored, measured in clock ticks. This metric includes the delays spent waiting for sync block I/O completion and for swapin block I/O completion.

任务的I/O阻塞延迟,以时钟周期为单位。包括同步块I/O和换入块I/O。

Command

The command name of the task.

任务的命令名。

-G process_name

Display only processes whose command name includes the string process_name. This string can be a regular expression. If option -t is used together with option -G then the threads belonging to that process are also displayed (even if their command name doesn't include the string process_name).

-h

Display all activities horizontally on a single line. This is intended to make it easier to be parsed by other programs.

一行中展示所有的统计。便于其他程序解析。

-I

In an SMP environment, indicate that tasks CPU usage (as displayed by option -u ) should be divided by the total number of processors.

在SMP环境中,指示任务的CPU利用率(使用-u选项)应该除以处理器数目。

-p { pid [,...] | SELF | ALL }

Select tasks (processes) for which statistics are to be reported. pid is the process identification number. The SELF keyword indicates that statistics are to be reported for the pidstat process itself, whereas the ALL keyword indicates that statistics are to be reported for all the tasks managed by the system.

指定需要监控监控的任务。SELF表示监控pidstat进程自己,ALL表示监控所有的进程。

-R

Report realtime priority and scheduling policy information. The following values may be displayed:

报告实时优先级和调度策略信息。

UID

The real user identification number of the task being monitored.

USER

The name of the real user owning the task being monitored.

PID

The identification number of the task being monitored.

prio

The realtime priority of the task being monitored.

任务的实时优先级。

policy

The scheduling policy of the task being monitored.

被监控的任务的调度策略

Command

The command name of the task.

-r

Report page faults and memory utilization.

When reporting statistics for individual tasks, the following values may be displayed:

报告页错误和内存利用率。

UID

The real user identification number of the task being monitored.

USER

The real user name of the task being monitored.

PID

The identification number of the task being monitored.

minflt/s

Total number of minor faults the task has made per second, those which have not required loading a memory page from disk.

任务造成的小错误的总数。小错误指的是还不需要从磁盘中加载一个内存页。

majflt/s

Total number of major faults the task has made per second, those which have required loading a memory page from disk.

任务造成的大错误的总数。大错误指的是需要从磁盘中加载一个内存页。

VSZ

Virtual Size: The virtual memory usage of entire task in kilobytes.

虚拟大小:整个任务使用的虚拟内存大小,以kb为单位。

RSS

Resident Set Size: The non-swapped physical memory used by the task in kilobytes.

任务使用的没有被交换的物理内存,以kb为单位

%MEM

The tasks's currently used share of available physical memory.

任务占用的可用物理内存的比例。

Command

The command name of the task.

When reporting global statistics for tasks and all their children, the following values may be displayed:

UID

The real user identification number of the task which is being monitored together with its children.

USER

The real user name of the task which is being monitored together with its children.

PID

The identification number of the task which is being monitored together with its children.

minflt-nr

Total number of minor faults made by the task and all its children, and collected during the interval of time.

majflt-nr

Total number of major faults made by the task and all its children, and collected during the interval of time.

Command

The command name of the task which is being monitored together with its children.

-s

Report stack utilization. The following values may be displayed:

报告栈利用率。

UID

The real user identification number of the task being monitored.

USER

The real user name of the task being monitored.

PID

The identification number of the task being monitored.

StkSize

The amount of memory in kilobytes reserved for the task as stack, but not necessarily used.

该任务保留的栈大小,以kb为单位。

StkRef

The amount of memory in kilobytes used as stack, referenced by the task.

该任务使用的栈大小,以kb为单位,被任务引用。

Command

The command name of the task.

-T { TASK | CHILD | ALL }

This option specifies what has to be monitored by the pidstat command. The TASK keyword indicates that statistics are to be reported for individual tasks (this is the default option) whereas the CHILD keyword indicates that statistics are to be globally reported for the selected tasks and all their children. The ALLkeyword indicates that statistics are to be reported for individual tasks and globally for the selected tasks and their children.

Note: Global statistics for tasks and all their children are not available for all options of pidstat. Also these statistics are not necessarily relevant to current time interval: The statistics of a child process are collected only when it finishes or it is killed.

该选项指定pidstat命令要监控的内容。

-t

Also display statistics for threads associated with selected tasks.

This option adds the following values to the reports:

显示任务关联的线程的统计数据。

TGID

The identification number of the thread group leader.

线程组leader的表示

TID

The identification number of the thread being monitored.

线程id

-U [ username ]

Display the real user name of the tasks being monitored instead of the UID. If username is specified, then only tasks belonging to the specified user are displayed.

指定某个用户的任务。

-u

Report CPU utilization.

When reporting statistics for individual tasks, the following values may be displayed:

报告CPU利用率

UID

The real user identification number of the task being monitored.

USER

The real user name of the task being monitored.

PID

The identification number of the task being monitored.

%usr

Percentage of CPU used by the task while executing at the user level (application), with or without nice priority. Note that this field does NOT include time spent running a virtual processor.

%system

Percentage of CPU used by the task while executing at the system level (kernel).

%guest

Percentage of CPU spent by the task in virtual machine (running a virtual processor).

执行虚拟进程的CPU百分比

%CPU

Total percentage of CPU time used by the task. In an SMP environment, the task's CPU usage will be divided by the total number of CPU's if option -I has been entered on the command line.

任务消耗的CPU总百分比。

CPU

Processor number to which the task is attached.

Command

The command name of the task.

When reporting global statistics for tasks and all their children, the following values may be displayed:

UID

The real user identification number of the task which is being monitored together with its children.

USER

The real user name of the task which is being monitored together with its children.

PID

The identification number of the task which is being monitored together with its children.

usr-ms

Total number of milliseconds spent by the task and all its children while executing at the user level (application), with or without nice priority, and collected during the interval of time. Note that this field does NOT include time spent running a virtual processor.

system-ms

Total number of milliseconds spent by the task and all its children while executing at the system level (kernel), and collected during the interval of time.

guest-ms

Total number of milliseconds spent by the task and all its children in virtual machine (running a virtual processor).

Command

The command name of the task which is being monitored together with its children.

-V

Print version number then exit.

-v

Report values of some kernel tables. The following values may be displayed:

报告some kernel tables的值。

UID

The real user identification number of the task being monitored.

USER

The name of the real user owning the task being monitored.

PID

The identification number of the task being monitored.

threads

Number of threads associated with current task.

当前任务相关的线程数

fd-nr

Number of file descriptors associated with current task.

当前任务关联的文件描述符个数。

Command

The command name of the task.

-w

Report task switching activity (kernels 2.6.23 and later only). The following values may be displayed:

报告任务上下文切换的活动状态

UID

The real user identification number of the task being monitored.

USER

The real user name of the task being monitored.

PID

The identification number of the task being monitored.

cswch/s

Total number of voluntary context switches the task made per second. A voluntary context switch occurs when a task blocks because it requires a resource that is unavailable.

任务每秒主动式上下文切换的次数

nvcswch/s

Total number of non voluntary context switches the task made per second. A involuntary context switch takes place when a task executes for the duration of its time slice and then is forced to relinquish the processor.

任务每秒抢占式上下文切换的总次数。

Command

The command name of the task.

ENVIRONMENT

The pidstat command takes into account the following environment variable: 

S_TIME_FORMAT

If this variable exists and its value is ISO then the current locale will be ignored when printing the date in the report header. The pidstat command will use the ISO 8601 format (YYYY-MM-DD) instead.

EXAMPLES

pidstat 2 5 

Display five reports of CPU statistics for every active task in the system at two second intervals.

pidstat -r -p 1643 2 5 

Display five reports of page faults and memory statistics for PID 1643 at two second intervals.

pidstat -T CHILD -r 2 5

Display five reports of page faults statistics at two second intervals for the child processes of all tasks in the system. Only child processes with non-zero statistics values are displayed.

pidstat -C "fox|bird" -r -p ALL

Display global page faults and memory statistics for all the processes whose command name includes the string "fox" or "bird".

相关推荐