More data printed

This commit is contained in:
Mark Nellemann 2022-11-11 11:44:28 +01:00
parent 7eced67734
commit fe3e238ffb
2 changed files with 68 additions and 37 deletions

View File

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

48
test.c
View File

@ -15,8 +15,6 @@ int main(int argc, char* argv[]) {
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);
@ -30,6 +28,11 @@ int main(int argc, char* argv[]) {
exit(-1);
}
long history[32][8];
while(1) {
/* allocate enough memory for all the structures */
statp = calloc(tot, sizeof(perfstat_disk_t));
@ -46,15 +49,46 @@ int main(int argc, char* argv[]) {
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",
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,
statp[i].rblks,
statp[i].bsize,
statp[i].wblks,
statp[i].bsize
rblks,
rbytes,
rdiff,
wblks,
wbytes,
wdiff
);
history[i][0] = rbytes;
history[i][1] = wbytes;
}
sleep(10);