4
7

More than 5 years have passed since last update.

プロセスごとの統計をレポートする、pidstat

Posted at

「pidstat」はプロセスごとの統計をレポートするコマンド。
vmstat、iostatなどのstat系コマンドと同様に以下の書式で使用する。

pidstat [options] [ interval [ count ] ]

ここでの確認は以下のバージョン

$ pidstat -V
sysstat version 10.1.5

CPUの統計を監視(デフォルト)

1秒間隔で20回、プロセスのCPUの統計を出力する。「-u」はデフォルトのため省略可能。
「-l」はコマンドをすべての引数つきで表示する。

$  pidstat 1 20 -u -l
Linux 4.1.12-61.1.28.el7uek.x86_64 (ol122a)     05/29/2018      _x86_64_        (2 CPU)

02:07:09 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command
02:07:10 PM     0       559    0.00    0.99    0.00    0.99     0  kworker/0:1H
02:07:10 PM 54321      3818    0.00   14.85    0.00   14.85     1  ora_vktm_orcl
02:07:10 PM 54321      3848    0.99    0.00    0.00    0.99     0  ora_dbw0_orcl
02:07:10 PM 54321      3850    0.00    0.99    0.00    0.99     0  ora_lgwr_orcl
02:07:10 PM 54321      3854    0.99    0.00    0.00    0.99     0  ora_lg00_orcl
02:07:10 PM 54321      3876    0.99    0.00    0.00    0.99     1  ora_mmnl_orcl
02:07:10 PM 54321      4624    0.99    0.00    0.00    0.99     0  ora_w003_orcl
02:07:10 PM     0      4917    0.00    0.99    0.00    0.99     0  kworker/0:3
02:07:10 PM 54321      6463   32.67    0.99    0.00   33.66     1  oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
02:07:10 PM 54321      6538    0.99    1.98    0.00    2.97     1  pidstat 1 20 -u -l

メモリ統計を監視

1秒間隔で20回、プロセスのメモリの統計を出力する。

$  pidstat -r 1 20 -l
Linux 4.1.12-61.1.28.el7uek.x86_64 (ol122a)     05/29/2018      _x86_64_        (2 CPU)

02:04:29 PM   UID       PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
02:04:30 PM 54321      3918      3.96      0.00 1163444 162080   9.09  ora_cjq0_orcl
02:04:30 PM 54321      6417    699.01      0.00  108432   2400   0.13  pidstat -r 1 20 -l

02:04:30 PM   UID       PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
02:04:31 PM 54321      3918      4.95      0.00 1163444 162080   9.09  ora_cjq0_orcl
02:04:31 PM 54321      6416     12.87      0.00 1162476 145860   8.18  oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
02:04:31 PM 54321      6417    634.65      0.00  108432   2452   0.14  pidstat -r 1 20 -l

02:04:31 PM   UID       PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
02:04:32 PM 54321      3838      6.93      0.00 1154108 119168   6.68  ora_dbrm_orcl
02:04:32 PM 54321      3918      3.96      0.00 1163444 162080   9.09  ora_cjq0_orcl
02:04:32 PM 54321      6416      1.98      0.00 1162476 145860   8.18  oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
02:04:32 PM 54321      6417    621.78      0.00  108432   2452   0.14  pidstat -r 1 20 -l

I/Oの統計を監視

1秒間隔で20回、プロセスのIOの統計を出力する。

$ pidstat -d 1 20 -l
Linux 4.1.12-61.1.28.el7uek.x86_64 (ol122a)     05/29/2018      _x86_64_        (2 CPU)

01:55:21 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command

01:55:22 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
01:55:23 PM 54321      3852      0.00     31.37      0.00  ora_ckpt_orcl

01:55:23 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command

01:55:24 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command

01:55:25 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
01:55:26 PM 54321      3852      0.00     32.00      0.00  ora_ckpt_orcl
01:55:26 PM 54321      3854      0.00      4.00      0.00  ora_lg00_orcl
01:55:26 PM 54321      5633   1336.00      8.00      0.00  oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

01:55:26 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
01:55:27 PM 54321      3848    128.00  11952.00      0.00  ora_dbw0_orcl
01:55:27 PM 54321      3854      0.00      8.00      0.00  ora_lg00_orcl
01:55:27 PM 54321      3858      4.00      4.00      0.00  ora_lg01_orcl
01:55:27 PM 54321      5633    392.00    128.00      0.00  oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

01:55:27 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
01:55:28 PM 54321      3848      0.00  10952.00      0.00  ora_dbw0_orcl

コマンドを指定して監視

「-C」オプションで指定した文字列を含むプロセスの情報を表示する。

「ora_」を含むプロセスの情報を表示。

$  pidstat -C "ora_"  1 20 -l
Linux 4.1.12-61.1.28.el7uek.x86_64 (ol122a)     05/29/2018      _x86_64_        (2 CPU)

02:10:50 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command
02:10:51 PM 54321      3822    0.00    0.97    0.00    0.97     1  ora_gen0_orcl
02:10:51 PM 54321      3848    2.91    0.00    0.00    2.91     1  ora_dbw0_orcl
02:10:51 PM 54321      3850    0.00    0.97    0.00    0.97     0  ora_lgwr_orcl

02:10:51 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command

02:10:52 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command
02:10:53 PM 54321      3918    1.00    0.00    0.00    1.00     1  ora_cjq0_orcl

02:10:53 PM   UID       PID    %usr %system  %guest    %CPU   CPU  Command
02:10:54 PM 54321      3848    7.00    3.00    0.00   10.00     0  ora_dbw0_orcl

正規表現で指定可能である。dbwまたはlgwrを含むプロセスの情報を表示する。

$ pidstat -C "dbw|lgwr"  1 20 -l -d
Linux 4.1.12-61.1.28.el7uek.x86_64 (ol122a)     05/29/2018      _x86_64_        (2 CPU)

02:17:32 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command

02:17:33 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
02:17:34 PM 54321      3848      0.00   2186.14      0.00  ora_dbw0_orcl

02:17:34 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
02:17:35 PM 54321      3848      0.00   9472.00      0.00  ora_dbw0_orcl

02:17:35 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
02:17:36 PM 54321      3848      0.00   8760.00      0.00  ora_dbw0_orcl

02:17:36 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
02:17:37 PM 54321      3848      0.00   1704.00      0.00  ora_dbw0_orcl
02:17:37 PM 54321      3850      4.00    392.00      0.00  ora_lgwr_orcl

ユーザを指定して監視

「-U」でOSユーザを指定することもできる。

oracleユーザのプロセスを監視する例。

$ pidstat -U oracle  1 20 -l
Linux 4.1.12-61.1.28.el7uek.x86_64 (ol122a)     05/29/2018      _x86_64_        (2 CPU)

02:12:16 PM     USER       PID    %usr %system  %guest    %CPU   CPU  Command
02:12:17 PM   oracle      3818    6.73    0.00    0.00    6.73     1  ora_vktm_orcl
02:12:17 PM   oracle      3848    2.88    7.69    0.00   10.58     0  ora_dbw0_orcl
02:12:17 PM   oracle      6961    0.96    0.96    0.00    1.92     0  oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
02:12:17 PM   oracle      7027    0.96    1.92    0.00    2.88     1  pidstat -U oracle 1 20 -l

プロセスを指定して監視

「-P」でプロセスIDを指定して監視することもできる。
また、SELFを指定するとpidstat自身、ALLを指定するとすべてのプロセス。

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

ora_dbw0_orclとora_lgwr_orclのPIDを指定して監視する例。

$ ps -ef | grep -e dbw -e lgwr | grep -v grep
oracle    3848     1  0 11:43 ?        00:00:20 ora_dbw0_orcl
oracle    3850     1  0 11:43 ?        00:00:06 ora_lgwr_orcl


$ pidstat -p 3850,3848  1 20 -l -d
Linux 4.1.12-61.1.28.el7uek.x86_64 (ol122a)     05/29/2018      _x86_64_        (2 CPU)

02:14:43 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
02:14:44 PM 54321      3850      0.00      0.00      0.00  ora_lgwr_orcl
02:14:44 PM 54321      3848      0.00   5227.72      0.00  ora_dbw0_orcl

02:14:44 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
02:14:45 PM 54321      3850      0.00      0.00      0.00  ora_lgwr_orcl
02:14:45 PM 54321      3848      0.00   5080.00      0.00  ora_dbw0_orcl

02:14:45 PM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
02:14:46 PM 54321      3850      0.00      4.00      0.00  ora_lgwr_orcl
02:14:46 PM 54321      3848      0.00   5928.00      0.00  ora_dbw0_orcl
4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7