Only show hdisk and append a timestamp
This commit is contained in:
parent
9a69ee1a41
commit
07de3cb84e
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -48,5 +48,6 @@ Thumbs.db
|
||||||
*.mov
|
*.mov
|
||||||
*.wmv
|
*.wmv
|
||||||
|
|
||||||
# C objects
|
# C objects and binary
|
||||||
*.o
|
*.o
|
||||||
|
aix-disk-perfstat
|
||||||
|
|
11
Makefile
11
Makefile
|
@ -3,13 +3,14 @@
|
||||||
|
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=
|
CFLAGS=
|
||||||
|
BIN=aix-disk-perfstat
|
||||||
|
|
||||||
default: test
|
default: main
|
||||||
|
|
||||||
test: test.o
|
main: main.o
|
||||||
$(CC) -lperfstat -o test test.o
|
$(CC) -lperfstat -o $(BIN) main.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f test.o
|
-rm -f main.o
|
||||||
-rm -f test
|
-rm -f $(BIN)
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,25 @@ 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
|
Modified example from: https://www.ibm.com/docs/en/aix/7.3?topic=interfaces-perfstat-disk-interface
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libperfstat.h>
|
#include <libperfstat.h>
|
||||||
|
|
||||||
|
int startsWith(const char *a, const char *b) {
|
||||||
|
if(strncmp(a, b, strlen(b)) == 0) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
time_t now;
|
||||||
|
|
||||||
/* 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);
|
||||||
|
@ -50,9 +58,17 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Obtain current time
|
||||||
|
// `time()` returns the current time of the system as a `time_t` value
|
||||||
|
time(&now);
|
||||||
|
|
||||||
/* 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++) {
|
||||||
|
|
||||||
|
if(!startsWith(statp[i].name, "hdisk")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long bsize = statp[i].bsize; // Disk block size (in bytes).
|
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 rblks = statp[i].rblks; // Number of blocks read from disk.
|
||||||
unsigned long wblks = statp[i].wblks; // Number of blocks written to disk.
|
unsigned long wblks = statp[i].wblks; // Number of blocks written to disk.
|
||||||
|
@ -90,16 +106,17 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
printf("%s => reads: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ], writes: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ]\n",
|
printf("%s - %s => reads: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ], writes: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ]\n",
|
||||||
statp[i].name,
|
strtok(ctime(&now), "\n"),
|
||||||
rblks,
|
statp[i].name,
|
||||||
drblbks,
|
rblks,
|
||||||
rbytes,
|
drblbks,
|
||||||
drbytes,
|
rbytes,
|
||||||
wblks,
|
drbytes,
|
||||||
dwblbks,
|
wblks,
|
||||||
wbytes,
|
dwblbks,
|
||||||
dwbytes);
|
wbytes,
|
||||||
|
dwbytes);
|
||||||
|
|
||||||
history[i][0] = rblks;
|
history[i][0] = rblks;
|
||||||
history[i][1] = rbytes;
|
history[i][1] = rbytes;
|
||||||
|
@ -111,3 +128,4 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue