Using pidstat to gather process statistics

Pidstat is a statistics report tool for Linux which is part of the sysstat utilities. You can capture the CPU and memory utilization easily for processes. You can use PID’s and even regular expressions on the process names to filter them out.

# Filter on processes with regular expression that will match commands proc_a, proc_b, proc_c with an interval of 5 seconds:
$ pidstat -C 'proc_a|proc_b|proc_c' -hur -p ALL 5

You can output this information to a file. After you captured your file you can create csv file (comma separated values format) out of this raw data for plotting it in a spreadsheet processor like Microsoft Excel. I use sed to do so:

# remove the first line, lines that start with a hash, lines that are empty, remove the starting space and finally replace space(s) with a comma:
sed '1d;/^[#]/d;/^$/d;s/^[ ]*//;s/[ ]\+/,/g' raw_data_file_input > nice_data_file.csv

This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published.