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.

2 Answers 2

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.

3
  • 1
    Thanks, what's the purpose of the -e flag? Couldn't find a source online for that.
    – user308485
    Commented Nov 7, 2019 at 9:06
  • 1
    You might not need -e. On ArchLinux man pidstat states for -e: Execute program with given arguments args and monitor it with pidstat. pidstat stops when program terminates. Commented Nov 7, 2019 at 9:23
  • I don't understand how this is supposed to work. No matter which program I run, the report is always sent right at the beginning, before the command actually outputs anything. So of course, everything is at 0,00. What is happening ?
    – Atralb
    Commented Jan 16, 2021 at 17:39
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)

2
  • But this runs every second lets say. If my process runs for 42.6 seconds, then the last 0.6 seconds of I/O would be missed by I/O top?
    – user308485
    Commented Nov 7, 2019 at 21:46
  • @user308485 yes, that is correct. You can use -d 0.1 for example to use even smaller polling unit than 1 second, but in the end with iotop you will always lose some small amount of I/O statistics. Also, it is possible that some process starts and ends very quickly (for example, 1/100th of the seconds) and so it might not show at all in iotop Commented Nov 8, 2019 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .