Initial commit

This commit is contained in:
Mark Nellemann 2022-11-11 08:51:27 +01:00
parent 9773511774
commit 7eced67734
3 changed files with 83 additions and 0 deletions

2
.gitignore vendored
View file

@ -48,3 +48,5 @@ Thumbs.db
*.mov
*.wmv
# C objects
*.o

18
Makefile Normal file
View file

@ -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

63
test.c Normal file
View file

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libperfstat.h>
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);
}
}