# Tracking I/O Time For Each File Read or Write

This section describes how to monitor the amount of time it takes for each process to read from or write to any file. This is useful if you wish to determine what files are slow to load on a given system.

iotime.stp

tracks each time a system call opens, closes, reads from, and writes to a file. For each file any system call accesses, counts the number of microseconds it takes for any reads or writes to finish and tracks the amount of data (in bytes) read from or written to the file.

also uses the local variable `$count` to track the amount of data (in bytes) that any system call attempts to read or write. Note that `$return` (as used in from ) stores the actual amount of data read/written. `$count` can only be used on probes that track data reads or writes (e.g. `syscall.read` and `syscall.write`).

Sample Output

    [...]
    825946 3364 (NetworkManager) access /sys/class/net/eth0/carrier read: 8190 write: 0
    825955 3364 (NetworkManager) iotime /sys/class/net/eth0/carrier time: 9
    [...]
    117061 2460 (pcscd) access /dev/bus/usb/003/001 read: 43 write: 0
    117065 2460 (pcscd) iotime /dev/bus/usb/003/001 time: 7
    [...]
    3973737 2886 (sendmail) access /proc/loadavg read: 4096 write: 0
    3973744 2886 (sendmail) iotime /proc/loadavg time: 11
    [...]

prints out the following data:

- A timestamp, in microseconds.

- Process ID and process name.

- An `access` or `iotime` flag.

- The file accessed.

If a process was able to read or write any data, a pair of `access` and `iotime` lines should appear together. The `access` line's timestamp refers to the time that a given process started accessing a file; at the end of the line, it will show the amount of data read/written (in bytes). The `iotime` line will show the amount of time (in microseconds) that the process took in order to perform the read or write.

If an `access` line is not followed by an `iotime` line, it simply means that the process did not read or write any data.

script examples monitoring I/O time
examples of SystemTap scripts monitoring I/O time
monitoring I/O time examples of SystemTap scripts
I/O time, monitoring examples of SystemTap scripts
time of I/O examples of SystemTap scripts
local variables sample usage $count
variables (local) sample usage $count
$count sample usage local variables