I am trying to trace the total data that is written to or read from a disk for a particular process in Linux.
Using the dstat tool, I am able to trace system-wide read, write calls, by using dstat -d
.
Using strace -e trace=read,write
, I am able to trace the returning values of the system calls.
Here's a sample program for which I want to get real system read-write values (that includes the metadata written and read to and from the disk):
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main(){
char block[4096]="0";
int count=500;
int fd, size;
for(int i=0;i<4096;i++)
{
char a='0';
block[i]=a;
}
fd = open("file.txt",O_CREAT|O_WRONLY, 0644);
while(count--){
size = write(fd,block,4096);
}
fsync(fd); //Flush all data to disk
close(fd);
Tools like iotop
are also not useful since they give constantly changing values. The dstat -d
option is the closest I've gotten to tracing the real read, write values, but I want to narrow it down to one specific process only and dstat does not have such an option.
Thank you for your help!