While playing around with my Debian 5.0 host last week, I came across the pidstat utility. Pidstat allows you to display a number of statistics for processes running on a system (and threads inside that process), which can be incredibly useful for troubleshooting performance problems. To use pidstat to get a breakdown of how a given process is using the processors on a system, pidstat can be run with the “-p” option and the process ID to interrogate:
$ pidstat -p 3297 2
Linux 2.6.26-1-686 (disarm) 03/07/2009 i686
08:07:18 AM PID %user %system %CPU CPU Command 08:07:20 AM 3297 11.06 74.37 85.43 0 dd 08:07:22 AM 3297 13.00 70.00 83.00 0 dd 08:07:24 AM 3297 10.95 72.64 83.58 0 dd
If you are looking to see how much I/O a specific process is responsible for, you can run pidstat with the “-d” option:
$ pidstat -d -p 3288 2
Linux 2.6.26-1-686 (disarm) 03/07/2009 i686
08:06:35 AM PID kB_rd/s kB_wr/s kB_ccwr/s Command 08:06:37 AM 3288 3.98 113319.40 0.00 dd 08:06:39 AM 3288 4.00 112514.00 0.00 dd 08:06:41 AM 3288 4.00 81454.00 0.00 dd
And finally, to view paging activity per process, you can run pidstat with the “-r” option (and optionally the “-t” flag if you want to see thread activity):
$ pidstat -r -t -p 3338 2
Linux 2.6.26-1-686 (disarm) 03/07/2009 i686
08:10:20 AM PID TID minflt/s majflt/s VSZ RSS %MEM Command 08:10:22 AM 3338 - 0.00 0.00 3180 596 0.23 dd 08:10:22 AM - 3338 0.00 0.00 3180 596 0.23 |__dd
08:10:22 AM PID TID minflt/s majflt/s VSZ RSS %MEM Command 08:10:24 AM 3338 - 0.00 0.00 3180 596 0.23 dd 08:10:24 AM - 3338 0.00 0.00 3180 596 0.23 |__dd
08:10:24 AM PID TID minflt/s majflt/s VSZ RSS %MEM Command 08:10:26 AM 3338 - 0.00 0.00 3180 596 0.23 dd 08:10:26 AM - 3338 0.00 0.00 3180 596 0.23 |__dd
Pidstat is pretty darn cool, and I will definitely be using this in the future! Nice!