From fe3e238ffbc696aa96f102e43366ad4a7e15f379 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Fri, 11 Nov 2022 11:44:28 +0100 Subject: [PATCH] More data printed --- Makefile | 5 +-- test.c | 100 +++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index e831373..daea141 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,8 @@ CFLAGS= default: test -%.0: %.c - $(CC) -c -o $@ $< $(CFLAGS) - test: test.o - gcc -lperfstat -o test test.o + $(CC) -lperfstat -o test test.o clean: -rm -f test.o diff --git a/test.c b/test.c index 7a77c7d..f3031f2 100644 --- a/test.c +++ b/test.c @@ -11,15 +11,13 @@ Modified example from: https://www.ibm.com/docs/en/aix/7.3?topic=interfaces-perf int main(int argc, char* argv[]) { - int i, ret, tot; - perfstat_disk_t *statp; - perfstat_id_t first; - - while(1) { + int i, ret, tot; + perfstat_disk_t *statp; + perfstat_id_t first; /* check how many perfstat_disk_t structures are available */ tot = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0); - + /* check for error */ if (tot < 0) { perror("perfstat_disk"); @@ -30,34 +28,70 @@ int main(int argc, char* argv[]) { exit(-1); } - /* allocate enough memory for all the structures */ - statp = calloc(tot, sizeof(perfstat_disk_t)); - - /* set name to first interface */ - strcpy(first.name, FIRST_DISK); - - /* ask to get all the structures available in one call */ - /* return code is number of structures returned */ - ret = perfstat_disk(&first, statp, sizeof(perfstat_disk_t), tot); - /* check for error */ - if (ret <= 0) { - perror("perfstat_disk"); - exit(-1); + long history[32][8]; + + while(1) { + + /* allocate enough memory for all the structures */ + statp = calloc(tot, sizeof(perfstat_disk_t)); + + /* set name to first interface */ + strcpy(first.name, FIRST_DISK); + + /* ask to get all the structures available in one call */ + /* return code is number of structures returned */ + ret = perfstat_disk(&first, statp, sizeof(perfstat_disk_t), tot); + + /* check for error */ + if (ret <= 0) { + perror("perfstat_disk"); + exit(-1); + } + + + /* print statistics for each of the disks */ + for (i = 0; i < ret; i++) { + + unsigned long bsize = statp[i].bsize; // Disk block size (in bytes). + unsigned long rblks = statp[i].rblks; // Number of blocks read from disk. + unsigned long wblks = statp[i].wblks; // Number of blocks written to disk. + + unsigned long rbytes = 0; + if(rblks > 0) { + rbytes = rblks * bsize; + } + + unsigned long rdiff = 0; + if(history[i][0] > 0) { + rdiff = rbytes - history[i][0]; + } + + unsigned long wbytes = 0; + if(wblks > 0) { + wbytes = wblks * bsize; + } + + unsigned long wdiff = 0; + if(history[i][1] > 0) { + wdiff = wbytes - history[i][1]; + } + + printf("%s => reads [ blocks: %10u, bytes %10u, diff %8u ], writes [ blocks: %10u, bytes: %10u, diff: %8u ]\n", + statp[i].name, + rblks, + rbytes, + rdiff, + wblks, + wbytes, + wdiff + ); + + history[i][0] = rbytes; + history[i][1] = wbytes; + } + + sleep(10); } - /* print statistics for each of the disks */ - for (i = 0; i < ret; i++) { - printf("%s: %11u blocks of %11u bytes read, %11u blocks of %11u bytes written\n", - statp[i].name, - statp[i].rblks, - statp[i].bsize, - statp[i].wblks, - statp[i].bsize - ); - } - - sleep(10); - } - }