Total I/O cost of a process

Solution 1:

Try pidstat. Use it like this: pidstat -d -e command

pidstat is able to report statistics for Linux tasks. The -d instructs pidstat to gather IO stats. pidstat will stop and print the report once the command finished.

Solution 2:

iotop has --batch option, which you can use to process it non-interactively. That would allow you to do (for example):

sudo iotop --batch -qqq --accumulated | fgrep --line-buffered '% dd ' | tee  ~/dd.log

which would provide output like:

19804 be/4 user  0.00 B      0.00 B  0.00 %  0.00 % dd if=/dev/zero of=/tmp/log.1 bs=1M count=10000
19804 be/4 user  0.00 B    755.18 M  0.00 % 30.99 % dd if=/dev/zero of=/tmp/log.1 bs=1M count=10000
19804 be/4 user  0.00 B   1029.48 M  0.00 % 50.96 % dd if=/dev/zero of=/tmp/log.1 bs=1M count=10000

Last line matching your fgrep(1) string (in this example looking for dd command) is your final cumulative line.

Also, the output remains in ~/dd.log for your later parsing as needed. (you can also reverse the ordering of tee and fgrep if you want to save ALL iotop output to logfile, not just output specific to dd in example)