I need to track read
system calls for specific files, and I'm currently doing this by parsing the output of strace
. Since read
operates on file descriptors I have to keep track of the current mapping between fd
and path
. Additionally, seek
has to be monitored to keep the current position up-to-date in the trace.
Is there a better way to get per-application, per-file-path IO traces in Linux?
First, you probably don't need to keep track because mapping between fd
and path
is available in /proc/PID/fd/
.
Second, maybe you should use the LD_PRELOAD trick and overload in C open
, seek
and read
system call. There are some article here and there about how to overload malloc/free.
I guess it won't be too different to apply the same kind of trick for those system calls. It needs to be implemented in C, but it should take far less code and be more precise than parsing strace
output.