pidstat

The pidstat tool reports process statistics. To report CPU utilisation on a per process basis we can run pidstat without arguments or with -u (default option):

marc:~> pidstat
10:55:40 PM   UID   PID   %usr   %system   %guest    %CPU CPU Command
10:55:40 PM     0     1   0.00      0.00     0.00    0.01   7 systemd
10:55:40 PM     0     2   0.00      0.00     0.00    0.00   3 kthreadd
10:55:40 PM     0     3   0.00      0.00     0.00    0.00   0 ksoftirqd/0
10:55:40 PM     0     7   0.00      0.01     0.00    0.01   3 rcu_sched
10:55:40 PM     0     9   0.00      0.00     0.00    0.00   4 rcuos/0
[…]
.
marc:~> pidstat -u
10:55:41 PM   UID   PID   %usr   %system   %guest    %CPU CPU Command
10:55:41 PM     0     1   0.00      0.00     0.00    0.01   7 systemd
10:55:41 PM     0     2   0.00      0.00     0.00    0.00   3 kthreadd
10:55:41 PM     0     3   0.00      0.00     0.00    0.00   0 ksoftirqd/0
10:55:41 PM     0     7   0.00      0.01     0.00    0.01   3 rcu_sched
10:55:41 PM     0     9   0.00      0.00     0.00    0.00   4 rcuos/0
[…]

We can monitor certain processes rather than all by specifying the PIDs (-p) or binary being run (-C):

marc:~> pidstat -­p 2569,2681
11:06:01 PM    UID   PID   %usr   %system   %guest  %CPU CPU Command
11:06:01 PM   1000  2569   1.18      0.17     0.00  1.34   0 insync
11:06:01 PM   1000  2681   0.04      0.01     0.00  0.05   5 gnome­-terminal­
marc:~> pidstat ­-C tracker
11:09:15 PM    UID   PID   %usr   %system   %guest  %CPU CPU Command
11:09:15 PM   1000  2512   0.02      0.00     0.00  0.02   0 tracker-­miner­f
11:09:15 PM   1000  2514   0.00      0.00     0.00  0.00   5 tracker­-miner­a
11:09:15 PM   1000  2515   0.01      0.00     0.00  0.01   0 tracker­-extract
11:09:15 PM   1000  2523   0.00      0.00     0.00  0.00   5 tracker-­miner­u
11:09:15 PM   1000  2527   0.01      0.01     0.00  0.02   5 tracker­-store

With the -d flag we get I/O statistics and we can specify intervals:

marc:~> pidstat ­-C rsyslog ­-d -­p ALL 5 2
11:14:28 PM   UID   PID   kB_rd/s   kB_wr/s    kB_ccwr/s    iodelay   Command
11:14:33 PM     0   2962 ­    1.00      1.00 ­        1.00          0   rsyslogd
.
11:14:33 PM   UID   PID   kB_rd/s   kB_wr/s    kB_ccwr/s    iodelay   Command
11:14:38 PM     0   2962 ­    1.00      1.00 ­        1.00          0   rsyslogd
.
Average:      UID   PID   kB_rd/s   kB_wr/s    kB_ccwr/s    iodelay   Command
Average:        0   2962 ­    1.00      1.00 ­        1.00          0   rsyslogd

The -l flag shows the command with all its arguments:

marc:~> pidstat -­l -­p 32061
11:18:01 PM    UID      PID    %usr    %system  %guest    %CPU   CPU   Command
11:18:01 PM      0    32061    0.00       0.00    0.00    0.00     4   dbus­launch
­­autolaunch=0473177a2c004ba7b87a9bb6ef882163 ­­binary­syntax –close­stderr

The -R flag shows priority and scheduling policy information:

marc:~> pidstat -­R -­p 32061
11:20:18 PM   UID   PID   prio   policy   Command
11:20:18 PM   0   32061      0   NORMAL   dbus­launch

Page faults and memory utilisation are reported with the -r flag:

marc:~> pidstat -­r -­p 32061
11:23:50 PM   UID   PID   minflt/s   majflt/s     VSZ     RSS     %MEM     Command
11:23:50 PM     0 32061       0.00       0.00   16060    1580     0.01     dbus­launch

Stack utilisation is reported with -s:

marc:~> pidstat ­-s -­p 2569
11:25:25 PM   UID    PID    StkSize    StkRef    Command
11:25:25 PM  1000   2569        136        76    insync

We can report statistics at the thread level with -t:

marc:~> pidstat ­-t -­p 2569
11:26:41 PM   UID  TGID   TID   %usr   %system   %guest   %CPU CPU Command
11:26:41 PM  1000  2569 ­    –   1.17      0.17     0.00   1.34   4 insync
11:26:41 PM  1000 ­    –  2569   0.13      0.01     0.00   0.13   4 |__insync
11:26:41 PM  1000 ­    –  2665   1.04      0.16     0.00   1.20   2 |__insync
11:26:41 PM  1000 ­    –  2703   0.00      0.00     0.00   0.00   0 |__dconf
11:26:41 PM  1000 ­    –  2704   0.00      0.00     0.00   0.00   4 |__gdbus
11:26:41 PM  1000 ­    –  2709   0.00      0.00     0.00   0.00   4 |__insync
11:26:41 PM  1000 ­    –  2710   0.00      0.00     0.00   0.00   1 |__insync
11:26:41 PM  1000 ­    –  2717   0.00      0.00     0.00   0.00   0 |__QThread
11:26:41 PM  1000 ­    –  2719   0.00      0.00     0.00   0.00   0 |__insync
11:26:41 PM  1000 ­    –  2720   0.00      0.00     0.00   0.00   4 |__Qthread
.
marc:~> pidstat ­-tr -­p 2569
11:27:43 PM   UID  TGID   TID   minflt/s   majflt/s        VSZ    RSS %MEM Command
11:27:43 PM  1000  2569 ­    –      51.24       0.00    2912684 205376 1.27 insync
11:27:43 PM  1000 ­    –  2569      27.19       0.00    2912684 205376 1.27 |__insync
11:27:43 PM  1000 ­    –  2665      23.79       0.00    2912684 205376 1.27 |__insync
11:27:43 PM  1000 ­    –  2703       0.00       0.00          0      0 0.00 |__dconf
11:27:43 PM  1000 ­    –  2704       0.00       0.00    2912684 205376 1.27 |__gdbus
11:27:43 PM  1000 ­    –  2709       0.05       0.00    2912684 205376 1.27 |__insync
11:27:43 PM  1000 ­    –  2710       0.01       0.00    2912684 205376 1.27 |__insync
11:27:43 PM  1000 ­    –  2717       0.15       0.00    2912684 205376 1.27 |__QThread
11:27:43 PM  1000 ­    –  2719       0.01       0.00    2912684 205376 1.27 |__insync
11:27:43 PM  1000 ­    –  2720       0.00       0.00    2912684 205376 1.27 |__Qthread
.
marc:~> pidstat ­-td -­p 2569
11:27:59 PM   UID  TGID   TID    kB_rd/s    kB_wr/s    kB_ccwr/s    iodelay   Command
11:27:59 PM  1000  2569 ­    –       0.84    113.78          0.02       749    insync
11:27:59 PM  1000     – ­ 2569       0.22      0.00          0.00       749    |__insync
11:27:59 PM  1000 ­    –  2665       0.13    113.74          0.00    351587    |__insync
11:27:59 PM  1000 ­    –  2703       0.00      0.00          0.00         0    |__dconf
11:27:59 PM  1000 ­    –  2704       0.00      0.00          0.00         0    |__gdbus
11:27:59 PM  1000 ­    –  2709       0.00      0.00          0.00         0    |__insync
11:27:59 PM  1000 ­    –  2710       0.00      0.00          0.00         0    |__insync
11:27:59 PM  1000 ­    –  2717       0.00      0.00          0.00         0    |__QThread
11:27:59 PM  1000 ­    –  2719       0.00      0.00          0.00         0    |__insync
11:27:59 PM  1000 ­    –  2720       0.00      0.00          0.00         0    |__Qthread

We can find out the number of threads and filehandles with the -v flag:

marc:~> pidstat -­v -­p 2569
11:29:34 PM   UID    PID    threads    fd­nr   Command
11:29:34 PM  1000   2569          9      49   insync

We can check the switching activity with -w:

marc:~> pidstat ­-w -­p 2569
Linux 4.1.8­100.fc21.x86_64 (envy17)   10/19/2015    _x86_64_   (8 CPU)
.
11:32:03 PM    UID    PID   cswch/s   nvcswch/s   Command
11:32:03 PM   1000   2569      1.30        0.02   insync

And we can combine more than one flag to get more statistics in one go:

marc:~> pidstat -­dRrsvwu -­p 2569
Linux 4.1.8­100.fc21.x86_64 (envy17)    10/19/2015    _x86_64_   (8 CPU)
.
11:34:40 PM   UID    PID   %usr   %system   %guest   %CPU   CPU   Command
11:34:40 PM  1000   2569   1.17      0.17     0.00   1.34     5   insync
.
11:34:40 PM   UID    PID   minflt/s   majflt/s       VSZ      RSS   %MEM   Command
11:34:40 PM  1000   2569      51.19       0.00   2912560   205648   1.27   insync
.
11:34:40 PM   UID    PID   StkSize   StkRef   Command
11:34:40 PM  1000   2569       136       76   insync
.
11:34:40 PM   UID    PID    kB_rd/s    kB_wr/s    kB_ccwr/s    iodelay    Command
11:34:40 PM  1000   2569       0.84     113.66         0.02        749    insync
.
11:34:40 PM   UID    PID    cswch/s    nvcswch/s    Command
11:34:40 PM  1000   2569       1.31         0.02    insync
.
11:34:40 PM   UID    PID    threads    fd­nr    Command
11:34:40 PM  1000   2569          9      49    insync
.
11:34:40 PM   UID    PID   prio   policy   Command
11:34:40 PM  1000   2569      0   NORMAL   insync

 

<< prtstat                             prlimit >>