17

I know that iotop lets me measure the disk bandwidth used by any or all processes in real time. iotop -a measures the accumulated disk bandwidth, which is closer to what I want.

However, when the process I run terminates, it disappears too soon in iotop for me to be able to see exactly how many I/Os the process used in total since it started. Is there a way to record the total I/O usage of a process when it ends, and perhaps have this saved to some file for further analysis?

Note that I am only looking for answers exclusive to Linux, specifically Ubuntu.

3 Answers3

19

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.

Marco
  • 1,864
1

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)

Matija Nalis
  • 2,512
0

If the application is a single process you can run, and you want the process IO counters at the end, then this answer may be useful:

It works by storing the shell process io counters from /proc/[pid]/io/ in an environment variable before running the process, and then subtracting them after the process ends. Essentially:

> head -c 100M < /dev/urandom > /tmp/test.tmp
> export proc_self_io="";while read line; do proc_self_io+="$line "; done < /proc/self/io

> dd if=/tmp/test.tmp of=/tmp/test2.tmp iflag=direct oflag=direct 204800+0 records in 204800+0 records out 104857600 bytes (105 MB, 100 MiB) copied, 11.9083 s, 8.8 MB/s

> perl -ane 'BEGIN{%prev=split / /,$ENV{proc_self_io}};printf( qq{%22s %i\n}, $F[0], $F[1]-$prev{$F[0]} ) ' /proc/$$/io rchar: 104863754 wchar: 104858310 syscr: 205049 syscw: 204863 read_bytes: 104857600 write_bytes: 104857600 cancelled_write_bytes: 0

> rm /tmp/test.tmp /tmp/test2.tmp