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
|
||||||
|
|
48
test.c
48
test.c
|
@ -15,8 +15,6 @@ int main(int argc, char* argv[]) {
|
||||||
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);
|
||||||
|
|
||||||
|
@ -30,6 +28,11 @@ int main(int argc, char* argv[]) {
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long history[32][8];
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
|
||||||
/* allocate enough memory for all the structures */
|
/* allocate enough memory for all the structures */
|
||||||
statp = calloc(tot, sizeof(perfstat_disk_t));
|
statp = calloc(tot, sizeof(perfstat_disk_t));
|
||||||
|
|
||||||
|
@ -46,15 +49,46 @@ int main(int argc, char* argv[]) {
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* print statistics for each of the disks */
|
/* print statistics for each of the disks */
|
||||||
for (i = 0; i < ret; i++) {
|
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].name,
|
||||||
statp[i].rblks,
|
rblks,
|
||||||
statp[i].bsize,
|
rbytes,
|
||||||
statp[i].wblks,
|
rdiff,
|
||||||
statp[i].bsize
|
wblks,
|
||||||
|
wbytes,
|
||||||
|
wdiff
|
||||||
);
|
);
|
||||||
|
|
||||||
|
history[i][0] = rbytes;
|
||||||
|
history[i][1] = wbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(10);
|
sleep(10);
|
||||||
|
|
Loading…
Reference in a new issue