Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

time is a brilliant command if you want to figure out how much CPU time a given command takes.

I am looking for something similar that can measure the disk I/O of the program and any children. Preferably it should distinguish between I/O that was cached (and thus did not cause the disk to spin) and I/O that was not cached.

So I would like to do:

iomeassure my_program my_args

and get output similar to:

Cached read: 10233303 Bytes
Cached write: 33303 Bytes  # This was probably a tmp file that was erased before making it to the disk
Non-cached read: 200002020 Bytes
Non-cached write: 202020 Bytes

I have looked at vmstat, iostat, and sar, but none of these are looking at a single process. Instead they look at the whole system.

I have looked at iotop, but that only gives me a view this instant.

--- edit ---

snap's answer seems close.

'File system inputs:' is the non-cached reads in 512-byte blocks.

'File system outputs:' is the cached writes in 512-byte blocks.

You can force the cache empty with:

sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null

I tested with:

 seq 10000000 > seq
 /usr/bin/time -v bash -c 'perl -e "open(G,\">f\"); print G <>;close G; unlink \"f\";" seq'
share|improve this question

1 Answer 1

up vote 7 down vote accepted

You did not specify which operating system you use.

Linux

Instead of using time foo which is (usually) a shell built-in you could try the external command /usr/bin/time foo. It gives some additional information such as number of file system inputs and outputs (but no information about cache hits or byte amounts). See man time and man getrusage for further instructions.

Note that this feature requires Linux kernel version 2.6.22 or newer.

FreeBSD

Use /usr/bin/time -l foo. It gives the number of inputs and outputs. See man time and man getrusage for further instructions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.