More data printed
This commit is contained in:
parent
7eced67734
commit
fe3e238ffb
5
Makefile
5
Makefile
|
@ -6,11 +6,8 @@ CFLAGS=
|
||||||
|
|
||||||
default: test
|
default: test
|
||||||
|
|
||||||
%.0: %.c
|
|
||||||
$(CC) -c -o $@ $< $(CFLAGS)
|
|
||||||
|
|
||||||
test: test.o
|
test: test.o
|
||||||
gcc -lperfstat -o test test.o
|
$(CC) -lperfstat -o test test.o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f test.o
|
-rm -f test.o
|
||||||
|
|
100
test.c
100
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 main(int argc, char* argv[]) {
|
||||||
|
|
||||||
int i, ret, tot;
|
int i, ret, tot;
|
||||||
perfstat_disk_t *statp;
|
perfstat_disk_t *statp;
|
||||||
perfstat_id_t first;
|
perfstat_id_t first;
|
||||||
|
|
||||||
while(1) {
|
|
||||||
|
|
||||||
/* check how many perfstat_disk_t structures are available */
|
/* check how many perfstat_disk_t structures are available */
|
||||||
tot = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0);
|
tot = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0);
|
||||||
|
|
||||||
/* check for error */
|
/* check for error */
|
||||||
if (tot < 0) {
|
if (tot < 0) {
|
||||||
perror("perfstat_disk");
|
perror("perfstat_disk");
|
||||||
|
@ -30,34 +28,70 @@ int main(int argc, char* argv[]) {
|
||||||
exit(-1);
|
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 */
|
long history[32][8];
|
||||||
if (ret <= 0) {
|
|
||||||
perror("perfstat_disk");
|
while(1) {
|
||||||
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++) {
|
||||||
|
|
||||||
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue