Home » 2014 » December » 5 » PIDSTAT command for debugging and analysis of Performance of Linux process

10:54 AM
PIDSTAT command for debugging and analysis of Performance of Linux process

pidstat - Report statistics for Linux tasks/processes.

FORMAT
       pidstat [ -C comm ] [ -d ] [ -I ] [ -p { pid | SELF | ALL } ] [ -r ] [ -t ] [ -T { TASK | CHILD | ALL } ] [ -u ] [ -V ] [ -w ] [ interval [ count ] ]

DESCRIPTION
       The pidstat command is used for monitoring individual tasks currently being managed by the Linux kernel.  

It writes to standard output activities for every  task  selected with option -p or for every task managed by the Linux kernel if option -p ALL has been used.

Not selecting any tasks is equivalent to specifying -p ALL but only active tasks (tasks with non-zero statistics values) will appear in the report.

       The pidstat command can also be used for monitoring the child processes of selected tasks.  Read about option -T below.


 

 -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.
  • ALL keyword indicates that statistics are to be reported for all the tasks managed by the system.

 

We will see several examples to understand the pidstat command

1.To print all the process with their PID , CPU%, user % and command name:

shanky@localhost:/proj:> pidstat -p ALL|head
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:32:10 PM       PID   %user %system    %CPU   CPU  Command
03:32:10 PM         1    0.00    0.00    0.00     0  init
03:32:10 PM         2    0.00    0.00    0.00     0  migration/0
03:32:10 PM         3    0.00    0.00    0.00     0  ksoftirqd/0
03:32:10 PM         4    0.00    0.00    0.00     0  events/0
03:32:10 PM         5    0.00    0.00    0.00     1  khelper
03:32:10 PM         6    0.00    0.00    0.00     0  kthread
03:32:10 PM         7    0.00    0.00    0.00     0  xenwatch

 

2. To get details about a specific process using its process id:

shanky@localhost:/proj:> pidstat -p 1380
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:33:12 PM       PID   %user %system    %CPU   CPU  Command
03:33:12 PM      1380    0.00    0.00    0.00     1  xfssyncd

 

 

3. To get the process details using the command name as string wiith -C option.

shanky@localhost:/proj:> pidstat -C xfssyncd
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:33:34 PM       PID   %user %system    %CPU   CPU  Command
03:33:34 PM      1371    0.00    0.00    0.00     1  xfssyncd
03:33:34 PM      1374    0.00    0.00    0.00     0  xfssyncd
03:33:34 PM      1380    0.00    0.00    0.00     1  xfssyncd


shanky@localhost:/proj:> pidstat -C "udevd"
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:33:50 PM       PID   %user %system    %CPU   CPU  Command
03:33:50 PM       707    0.00    0.00    0.00     1  udevd


 In the above commands the string used is nothing but the command name to start the process.

 

 

4.To get the processes with their page faults and memory utilization with -r option.

shanky@localhost:/proj:> pidstat -p ALL -r|head
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:36:08 PM       PID  minflt/s  majflt/s     VSZ    RSS   %MEM  Command
03:36:08 PM         1      0.00      0.00     800    308   0.00  init
03:36:08 PM         2      0.00      0.00       0      0   0.00  migration/0
03:36:08 PM         3      0.00      0.00       0      0   0.00  ksoftirqd/0
03:36:08 PM         4      0.00      0.00       0      0   0.00  events/0
03:36:08 PM         5      0.00      0.00       0      0   0.00  khelper
03:36:08 PM         6      0.00      0.00       0      0   0.00  kthread
03:36:08 PM         7      0.00      0.00       0      0   0.00  xenwatch

 

Here, below are the meaning of attributes shown in this output.

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.


 

 

5. To get the process list with their I/O read/write speed using -d option

shanky@localhost:/proj:> pidstat -p ALL -d|head
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:36:30 PM       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command

 

Here,below are the meaning of the attributes shown

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

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

 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.


 

 

 

6. You can also get the status of a specific process changing in a given interval. 

Below command will give the status of the process with PID 1380 at every interval of 1 second until you press Ctrl+C.

shanky@localhost:/proj:> pidstat -p 1380 1
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:38:39 PM       PID   %user %system    %CPU   CPU  Command
03:38:40 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:38:41 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:38:42 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:38:43 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:38:44 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:38:45 PM      1380    0.00    0.00    0.00     1  xfssyncd

 

 

7. Now, if you want to get the process details in a given interval for certain number of times, you  can give the number of times you want the output after the interval in second

For example, below command will give the live status of process id 1380 at an interval of 2 seconds four times.

shanky@localhost:/proj:> pidstat -p 1380 2 4
Linux 2.6.16.60-0.42.54.1.3977.0.PTF.748419-xen (localhost)      12/04/2014

03:39:21 PM       PID   %user %system    %CPU   CPU  Command
03:39:23 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:39:25 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:39:27 PM      1380    0.00    0.00    0.00     1  xfssyncd
03:39:29 PM      1380    0.00    0.00    0.00     1  xfssyncd
Average:         1380    0.00    0.00    0.00     -  xfssyncd


 

Some short example and their meaning


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.

 
 

Category: Open System-Linux | Views: 1355 | Added by: shanky | Tags: pidstat, pidstat command in linux, debug linux process, pidstat command in unix, check status of linux, analyse and debug performance of li | Rating: 5.0/1

Related blogs


You may also like to see:


[2014-11-19][Open System-Linux]
ETHTOOL : A tool in Linux to display or change ethernet card setting
[2016-01-23][Open System-Linux]
Some useful examples of netstat command in Linux for network statistics
[2014-02-19][Open System-Linux]
Shift Key is not working!! Mapping keyboard keys from one to another
[2014-12-22][Open System-Linux]
Key mapping inside VI editor
[2015-06-08][Open System-Linux]
CHAGE command in LINUX

Total comments: 0
avatar