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
|
||||
*.wmv
|
||||
|
||||
# C objects
|
||||
*.o
|
||||
# C objects and binary
|
||||
*.o
|
||||
aix-disk-perfstat
|
||||
|
|
11
Makefile
11
Makefile
|
@ -3,13 +3,14 @@
|
|||
|
||||
CC=gcc
|
||||
CFLAGS=
|
||||
BIN=aix-disk-perfstat
|
||||
|
||||
default: test
|
||||
default: main
|
||||
|
||||
test: test.o
|
||||
$(CC) -lperfstat -o test test.o
|
||||
main: main.o
|
||||
$(CC) -lperfstat -o $(BIN) main.c
|
||||
|
||||
clean:
|
||||
-rm -f test.o
|
||||
-rm -f test
|
||||
-rm -f main.o
|
||||
-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
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.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 i, ret, tot;
|
||||
perfstat_disk_t *statp;
|
||||
perfstat_id_t first;
|
||||
time_t now;
|
||||
|
||||
/* check how many perfstat_disk_t structures are available */
|
||||
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 */
|
||||
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 rblks = statp[i].rblks; // Number of blocks read from 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",
|
||||
statp[i].name,
|
||||
rblks,
|
||||
drblbks,
|
||||
rbytes,
|
||||
drbytes,
|
||||
wblks,
|
||||
dwblbks,
|
||||
wbytes,
|
||||
dwbytes);
|
||||
printf("%s - %s => reads: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ], writes: [ blocks: %10u (%8u ), bytes: %10u (%8u ) ]\n",
|
||||
strtok(ctime(&now), "\n"),
|
||||
statp[i].name,
|
||||
rblks,
|
||||
drblbks,
|
||||
rbytes,
|
||||
drbytes,
|
||||
wblks,
|
||||
dwblbks,
|
||||
wbytes,
|
||||
dwbytes);
|
||||
|
||||
history[i][0] = rblks;
|
||||
history[i][1] = rbytes;
|
||||
|
@ -111,3 +128,4 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in a new issue