diff options
Diffstat (limited to 'src/diskinfo.c')
-rw-r--r-- | src/diskinfo.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/diskinfo.c b/src/diskinfo.c new file mode 100644 index 0000000..815f7df --- /dev/null +++ b/src/diskinfo.c @@ -0,0 +1,28 @@ +#include "diskinfo.h" + +int disk_io_kb(char* disk, + unsigned long long* read, + unsigned long long* write) { + char syspath[512] = {'\0'}; + unsigned long long stats[8] = {-1}; + FILE* fd = NULL; + + sprintf(syspath, "/sys/block/%s/stat", disk); + + fd = fopen(syspath, "r"); + if(!fd) + return -1; + + // read io read merge read sectors read ticks + // write io write merge write sectors write ticks + fscanf(fd, "%lld %lld %lld %lld %lld %lld %lld %lld ", + &stats[0], &stats[1], &stats[2], &stats[3], + &stats[4], &stats[5], &stats[6], &stats[7]); + + fclose(fd); + + *read = stats[2] / 2; + *write = stats[6] / 2; + + return 1; +} |