diff --git a/.gitignore b/.gitignore index e9a2f4a..2d353ec 100644 --- a/.gitignore +++ b/.gitignore @@ -48,5 +48,6 @@ Thumbs.db *.mov *.wmv -# C objects -*.o \ No newline at end of file +# C objects and binary +*.o +aix-disk-perfstat diff --git a/Makefile b/Makefile index daea141..9f20174 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,14 @@ CC=gcc CFLAGS= +BIN=aix-disk-perfstat -default: test +default: main -test: test.o - $(CC) -lperfstat -o test test.o +main: main.o + $(CC) -lperfstat -o $(BIN) main.c clean: - -rm -f test.o - -rm -f test + -rm -f main.o + -rm -f $(BIN) diff --git a/test.c b/main.c similarity index 84% rename from test.c rename to main.c index 9592d93..7a00f8a 100644 --- a/test.c +++ b/main.c @@ -3,17 +3,25 @@ Repeatable prints disk statistics and sleeps for 10 seconds Modified example from: https://www.ibm.com/docs/en/aix/7.3?topic=interfaces-perfstat-disk-interface */ +#include #include #include #include #include #include +int startsWith(const char *a, const char *b) { + if(strncmp(a, b, strlen(b)) == 0) return 1; + return 0; +} + + int main(int argc, char* argv[]) { int i, ret, tot; perfstat_disk_t *statp; perfstat_id_t first; + time_t now; /* check how many perfstat_disk_t structures are available */ tot = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0); @@ -50,9 +58,17 @@ int main(int argc, char* argv[]) { } + // Obtain current time + // `time()` returns the current time of the system as a `time_t` value + time(&now); + /* print statistics for each of the disks */ for (i = 0; i < ret; i++) { + if(!startsWith(statp[i].name, "hdisk")) { + continue; + } + 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. @@ -90,16 +106,17 @@ int main(int argc, char* argv[]) { } - printf("%s => reads: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ], writes: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ]\n", - statp[i].name, - rblks, - drblbks, - rbytes, - drbytes, - wblks, - dwblbks, - wbytes, - dwbytes); + printf("%s - %s => reads: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ], writes: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ]\n", + strtok(ctime(&now), "\n"), + statp[i].name, + rblks, + drblbks, + rbytes, + drbytes, + wblks, + dwblbks, + wbytes, + dwbytes); history[i][0] = rblks; history[i][1] = rbytes; @@ -111,3 +128,4 @@ int main(int argc, char* argv[]) { } } +