I'm working on creating a tool to display system stats on Linux. I'm using the /sys and /proc APIs for this to learn how they work.
Currently, I'm reading
/sys/block/<dev>/stat to get block device statistics (docs). This works great for seeing how much reading and writing is happening on disk, but I'm wondering if it is possible to see the total block device I/O from an application's perspective.
Here's an example to demonstrate what I mean:
> cat somebigfile > /dev/zero # Takes some time, triggers device I/O > cat somebigfile > /dev/zero # Runs quickly a second time, no device I/O
I believe the difference between the two runs is due to the kernel going to the buffer cache rather than the disk for the second read. I have confirmed this by flushing the cache using
/proc/sys/vm/drop_caches causing the command to execute like the first time again.
What is the easiest way to see the total bytes read from block devices, including bytes served from the buffer cache, over some time period?
I have also considering summing the values in
/proc/<pid>/io, but this includes all I/O and isn't split out by device or type.
I am aware that I could do this using something like System Tap, but I'm wondering if there is a simpler way.