1. 程式人生 > >PROC檔案中stat統計資訊

PROC檔案中stat統計資訊

翻譯檔案Documentation/filesystems/proc.txt的1.8節,關於/proc/stat檔案內容的描述:

1.8 位於/proc/stat檔案中的核心雜項統計
-------------------------------------------------

核心在檔案/proc/stat中儲存了有關自身活動的各種資訊。所有的統計數字都是自系統啟動後累加起來的。使用cat命令簡單的檢視下檔案:

  > cat /proc/stat
  cpu  2255 34 2290 22625563 6290 127 456 0 0 0
  cpu0 1132 34 1441 11311718 3675 127 438 0 0 0
  cpu1 1123 0 849 11313845 2614 0 18 0 0 0
  intr 114930548 113199788 3 0 5 263 0 4 [... lots more numbers ...]
  ctxt 1990473
  btime 1062191376
  processes 2915
  procs_running 1
  procs_blocked 0
  softirq 183433 0 21755 12 39 1137 231 21459 2263

以cpu開頭的第一行統計數字為之後行cpu統計值的總和。這些數字值標識cpu處理器不同型別的事務耗費的時間總和。單位為USER_HZ(典型值為100)。以下按照從左到右的順序說明每一列數字的含義。

- user: 使用者態正常程序執行時間

- nice: 使用者態nice值為負的程序執行時間

- system: 程序在核心態的執行時間

- idle: 空閒時間

- iowait: 簡單來說,iowait代表著等待I/O操作完成的時間。但是還有幾個問題:
  1. 處理器不會一直等待I/O操作完成,iowait是任務等待I/O完成的時間。當有任務的I/O操作未完成時處理器進入空閒狀態,其它的任務將排程到此處理器執行。
  2. 在多核處理器上,等待I/O操作完成的任務不在任何CPU上執行,所以每個CPU的iowait時間很難統計。
  3. PROC檔案stat中的iowait值在一定情況下還會減少。
  所以,檔案stat中的iowait值並不準確。

- irq: 硬體中斷的執行時間

- softirq: 軟中斷的執行時間

- steal: 非自主等待時間

- guest: 執行正常客戶機的時間

- guest_nice: 執行niced客戶機的時間

"intr"行顯示了自啟動以來服務的每種系統中斷的總和。第一列是所有中斷的總數包括沒有中斷號的體系結構特殊中斷;以後的每一列顯示一個特定具有中斷號的中斷總數。無中斷號的中斷未單獨顯示,包括在了第一列的總數中。

"ctxt"行顯示在所有CPU直接上下文切換的總數。

"btime"含顯示系統啟動的時間,其值為自1970年1月1日00:00.00後的秒數。

"processes"行顯示建立的程序和執行緒的總數,包括但不限於由fork和clone系統呼叫建立的。

"procs_running"行顯示在執行或者就緒狀態的執行緒總數(例如,可執行執行緒的總數)。

"procs_blocked"行顯示處於阻塞狀態等待I/O完成的程序總數。

"softirq"行顯示自系統啟動以來,服務的所有軟中斷的總數。第一列為所有軟中斷的總數,之後的每一列為某一特定軟中斷的總數。

英文原文:

1.8 Miscellaneous kernel statistics in /proc/stat

-------------------------------------------------

Various pieces   of  information about  kernel activity  are  available in the /proc/stat file.  All  of  the numbers reported  in  this file are  aggregates since the system first booted.  For a quick look, simply cat the file:

  > cat /proc/stat
  cpu  2255 34 2290 22625563 6290 127 456 0 0 0
  cpu0 1132 34 1441 11311718 3675 127 438 0 0 0
  cpu1 1123 0 849 11313845 2614 0 18 0 0 0
  intr 114930548 113199788 3 0 5 263 0 4 [... lots more numbers ...]
  ctxt 1990473
  btime 1062191376
  processes 2915
  procs_running 1
  procs_blocked 0
  softirq 183433 0 21755 12 39 1137 231 21459 2263

The very first  "cpu" line aggregates the  numbers in all  of the other "cpuN" lines.  These numbers identify the amount of time the CPU has spent performing different kinds of work.  Time units are in USER_HZ (typically hundredths of a second).  The meanings of the columns are as follows, from left to right:

- user: normal processes executing in user mode
- nice: niced processes executing in user mode
- system: processes executing in kernel mode
- idle: twiddling thumbs
- iowait: In a word, iowait stands for waiting for I/O to complete. But there are several problems:
  1. Cpu will not wait for I/O to complete, iowait is the time that a task is waiting for I/O to complete. When cpu goes into idle state for outstanding task io, another task will be scheduled on this CPU.
  2. In a multi-core CPU, the task waiting for I/O to complete is not running on any CPU, so the iowait of each CPU is difficult to calculate.
  3. The value of iowait field in /proc/stat will decrease in certain conditions.
  So, the iowait is not reliable by reading from /proc/stat.

- irq: servicing interrupts
- softirq: servicing softirqs
- steal: involuntary wait
- guest: running a normal guest
- guest_nice: running a niced guest

The "intr" line gives counts of interrupts  serviced since boot time, for each of the  possible system interrupts.   The first  column  is the  total of  all interrupts serviced  including  unnumbered  architecture specific  interrupts; each  subsequent column is the  total for that particular numbered interrupt. Unnumbered interrupts are not shown, only summed into the total.

The "ctxt" line gives the total number of context switches across all CPUs.

The "btime" line gives  the time at which the  system booted, in seconds since the Unix epoch.

The "processes" line gives the number  of processes and threads created, which includes (but  is not limited  to) those  created by  calls to the  fork() and clone() system calls.

The "procs_running" line gives the total number of threads that are running or ready to run (i.e., the total number of runnable threads).

The   "procs_blocked" line gives  the  number of  processes currently blocked, waiting for I/O to complete.


The "softirq" line gives counts of softirqs serviced since boot time, for each of the possible system softirqs. The first column is the total of all softirqs serviced; each subsequent column is the total for that particular softirq.