From 7eced6773455e73b2867745fc0e95d7e315edd3b Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Fri, 11 Nov 2022 08:51:27 +0100 Subject: [PATCH] Initial commit --- .gitignore | 2 ++ Makefile | 18 ++++++++++++++++ test.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 Makefile create mode 100644 test.c diff --git a/.gitignore b/.gitignore index b24d71e..e9a2f4a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ Thumbs.db *.mov *.wmv +# C objects +*.o \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e831373 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +# +# gcc -I/usr/include -L/usr/lib -lperfstat -o test test.c + +CC=gcc +CFLAGS= + +default: test + +%.0: %.c + $(CC) -c -o $@ $< $(CFLAGS) + +test: test.o + gcc -lperfstat -o test test.o + +clean: + -rm -f test.o + -rm -f test + diff --git a/test.c b/test.c new file mode 100644 index 0000000..7a77c7d --- /dev/null +++ b/test.c @@ -0,0 +1,63 @@ +/* +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 + +int main(int argc, char* argv[]) { + + int i, ret, tot; + perfstat_disk_t *statp; + perfstat_id_t first; + + while(1) { + + /* 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"); + exit(-1); + } + if (tot == 0) { + printf("No disks found in the system\n"); + 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); + } + + /* 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); + } + +}