Provide argument for sleep-time

This commit is contained in:
Mark Nellemann 2022-11-12 14:32:31 +01:00
parent 243f0062d9
commit 66bac0e120
2 changed files with 107 additions and 90 deletions

View file

@ -5,25 +5,29 @@ Test code for [investigating](https://github.com/oshi/oshi/issues/2239) *wierd*
Example from PowerVS AIX 7.3
```
# ./test
hdisk0 => reads: [ blocks: 1995768 ( 0 ), bytes: 1021833216 ( 0 ) ], writes: [ blocks: 126169 ( 0 ), bytes: 64598528 ( 0 ) ]
hdisk0 => reads: [ blocks: 1999986 ( 4218 ), bytes: 1023992832 ( 2159616 ) ], writes: [ blocks: 126241 ( 72 ), bytes: 64635392 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2004196 ( 4210 ), bytes: 1026148352 ( 2155520 ) ], writes: [ blocks: 126321 ( 80 ), bytes: 64676352 ( 40960 ) ]
hdisk0 => reads: [ blocks: 2008406 ( 4210 ), bytes: 1028303872 ( 2155520 ) ], writes: [ blocks: 126393 ( 72 ), bytes: 64713216 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2012616 ( 4210 ), bytes: 1030459392 ( 2155520 ) ], writes: [ blocks: 127321 ( 928 ), bytes: 65188352 ( 475136 ) ]
hdisk0 => reads: [ blocks: 2016826 ( 4210 ), bytes: 1032614912 ( 2155520 ) ], writes: [ blocks: 127393 ( 72 ), bytes: 65225216 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2021036 ( 4210 ), bytes: 1034770432 ( 2155520 ) ], writes: [ blocks: 127465 ( 72 ), bytes: 65262080 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2025246 ( 4210 ), bytes: 1036925952 ( 2155520 ) ], writes: [ blocks: 127537 ( 72 ), bytes: 65298944 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2029456 ( 4210 ), bytes: 1039081472 ( 2155520 ) ], writes: [ blocks: 127617 ( 80 ), bytes: 65339904 ( 40960 ) ]
hdisk0 => reads: [ blocks: 2033666 ( 4210 ), bytes: 1041236992 ( 2155520 ) ], writes: [ blocks: 127689 ( 72 ), bytes: 65376768 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2037876 ( 4210 ), bytes: 1043392512 ( 2155520 ) ], writes: [ blocks: 128033 ( 344 ), bytes: 65552896 ( 176128 ) ]
hdisk0 => reads: [ blocks: 2042094 ( 4218 ), bytes: 1045552128 ( 2159616 ) ], writes: [ blocks: 128113 ( 80 ), bytes: 65593856 ( 40960 ) ]
hdisk0 => reads: [ blocks: 2046304 ( 4210 ), bytes: 1047707648 ( 2155520 ) ], writes: [ blocks: 128185 ( 72 ), bytes: 65630720 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2050514 ( 4210 ), bytes: 1049863168 ( 2155520 ) ], writes: [ blocks: 128257 ( 72 ), bytes: 65667584 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2054724 ( 4210 ), bytes: 1052018688 ( 2155520 ) ], writes: [ blocks: 128329 ( 72 ), bytes: 65704448 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2058934 ( 4210 ), bytes: 1054174208 ( 2155520 ) ], writes: [ blocks: 128441 ( 112 ), bytes: 65761792 ( 57344 ) ]
hdisk0 => reads: [ blocks: 2063152 ( 4218 ), bytes: 1056333824 ( 2159616 ) ], writes: [ blocks: 129297 ( 856 ), bytes: 66200064 ( 438272 ) ]
hdisk0 => reads: [ blocks: 2067362 ( 4210 ), bytes: 1058489344 ( 2155520 ) ], writes: [ blocks: 129369 ( 72 ), bytes: 66236928 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2071572 ( 4210 ), bytes: 1060644864 ( 2155520 ) ], writes: [ blocks: 129441 ( 72 ), bytes: 66273792 ( 36864 ) ]
hdisk0 => reads: [ blocks: 2075782 ( 4210 ), bytes: 1062800384 ( 2155520 ) ], writes: [ blocks: 129521 ( 80 ), bytes: 66314752 ( 40960 ) ]
# ./aix-disk-perfstat 2
Sat Nov 12 14:29:28 2022 - hdisk0 => reads: [ blocks: 41710376 ( 0 ), bytes: 4175843328 ( 0 ) ], writes: [ blocks: 52579577 ( 0 ), bytes: 1150939648 ( 0 ) ]
Sat Nov 12 14:29:30 2022 - hdisk0 => reads: [ blocks: 41710376 ( 0 ), bytes: 4175843328 ( 0 ) ], writes: [ blocks: 52579577 ( 0 ), bytes: 1150939648 ( 0 ) ]
Sat Nov 12 14:29:32 2022 - hdisk0 => reads: [ blocks: 41710376 ( 0 ), bytes: 4175843328 ( 0 ) ], writes: [ blocks: 52580401 ( 824 ), bytes: 1151361536 ( 421888 ) ]
Sat Nov 12 14:29:34 2022 - hdisk0 => reads: [ blocks: 41714586 ( 4210 ), bytes: 4177998848 ( 2155520 ) ], writes: [ blocks: 52580473 ( 72 ), bytes: 1151398400 ( 36864 ) ]
Sat Nov 12 14:29:36 2022 - hdisk0 => reads: [ blocks: 41714586 ( 0 ), bytes: 4177998848 ( 0 ) ], writes: [ blocks: 52580473 ( 0 ), bytes: 1151398400 ( 0 ) ]
Sat Nov 12 14:29:38 2022 - hdisk0 => reads: [ blocks: 41714586 ( 0 ), bytes: 4177998848 ( 0 ) ], writes: [ blocks: 52580473 ( 0 ), bytes: 1151398400 ( 0 ) ]
Sat Nov 12 14:29:40 2022 - hdisk0 => reads: [ blocks: 41714586 ( 0 ), bytes: 4177998848 ( 0 ) ], writes: [ blocks: 52580473 ( 0 ), bytes: 1151398400 ( 0 ) ]
Sat Nov 12 14:29:42 2022 - hdisk0 => reads: [ blocks: 41714586 ( 0 ), bytes: 4177998848 ( 0 ) ], writes: [ blocks: 52580473 ( 0 ), bytes: 1151398400 ( 0 ) ]
Sat Nov 12 14:29:44 2022 - hdisk0 => reads: [ blocks: 41718796 ( 4210 ), bytes: 4180154368 ( 2155520 ) ], writes: [ blocks: 52580553 ( 80 ), bytes: 1151439360 ( 40960 ) ]
Sat Nov 12 14:29:46 2022 - hdisk0 => reads: [ blocks: 41718796 ( 0 ), bytes: 4180154368 ( 0 ) ], writes: [ blocks: 52580553 ( 0 ), bytes: 1151439360 ( 0 ) ]
Sat Nov 12 14:29:48 2022 - hdisk0 => reads: [ blocks: 41718796 ( 0 ), bytes: 4180154368 ( 0 ) ], writes: [ blocks: 52580553 ( 0 ), bytes: 1151439360 ( 0 ) ]
Sat Nov 12 14:29:50 2022 - hdisk0 => reads: [ blocks: 41718796 ( 0 ), bytes: 4180154368 ( 0 ) ], writes: [ blocks: 52580553 ( 0 ), bytes: 1151439360 ( 0 ) ]
Sat Nov 12 14:29:52 2022 - hdisk0 => reads: [ blocks: 41718796 ( 0 ), bytes: 4180154368 ( 0 ) ], writes: [ blocks: 52580553 ( 0 ), bytes: 1151439360 ( 0 ) ]
Sat Nov 12 14:29:54 2022 - hdisk0 => reads: [ blocks: 41723006 ( 4210 ), bytes: 4182309888 ( 2155520 ) ], writes: [ blocks: 52580625 ( 72 ), bytes: 1151476224 ( 36864 ) ]
Sat Nov 12 14:29:56 2022 - hdisk0 => reads: [ blocks: 41723006 ( 0 ), bytes: 4182309888 ( 0 ) ], writes: [ blocks: 52580625 ( 0 ), bytes: 1151476224 ( 0 ) ]
Sat Nov 12 14:29:58 2022 - hdisk0 => reads: [ blocks: 41723006 ( 0 ), bytes: 4182309888 ( 0 ) ], writes: [ blocks: 52580625 ( 0 ), bytes: 1151476224 ( 0 ) ]
Sat Nov 12 14:30:00 2022 - hdisk0 => reads: [ blocks: 41723006 ( 0 ), bytes: 4182309888 ( 0 ) ], writes: [ blocks: 52580625 ( 0 ), bytes: 1151476224 ( 0 ) ]
Sat Nov 12 14:30:02 2022 - hdisk0 => reads: [ blocks: 41723006 ( 0 ), bytes: 4182309888 ( 0 ) ], writes: [ blocks: 52580657 ( 32 ), bytes: 1151492608 ( 16384 ) ]
Sat Nov 12 14:30:04 2022 - hdisk0 => reads: [ blocks: 41727216 ( 4210 ), bytes: 4184465408 ( 2155520 ) ], writes: [ blocks: 52580737 ( 80 ), bytes: 1151533568 ( 40960 ) ]
Sat Nov 12 14:30:06 2022 - hdisk0 => reads: [ blocks: 41727216 ( 0 ), bytes: 4184465408 ( 0 ) ], writes: [ blocks: 52580737 ( 0 ), bytes: 1151533568 ( 0 ) ]
Sat Nov 12 14:30:08 2022 - hdisk0 => reads: [ blocks: 41727216 ( 0 ), bytes: 4184465408 ( 0 ) ], writes: [ blocks: 52580737 ( 0 ), bytes: 1151533568 ( 0 ) ]
Sat Nov 12 14:30:10 2022 - hdisk0 => reads: [ blocks: 41727216 ( 0 ), bytes: 4184465408 ( 0 ) ], writes: [ blocks: 52580737 ( 0 ), bytes: 1151533568 ( 0 ) ]
Sat Nov 12 14:30:12 2022 - hdisk0 => reads: [ blocks: 41727216 ( 0 ), bytes: 4184465408 ( 0 ) ], writes: [ blocks: 52580737 ( 0 ), bytes: 1151533568 ( 0 ) ]
Sat Nov 12 14:30:14 2022 - hdisk0 => reads: [ blocks: 41731426 ( 4210 ), bytes: 4186620928 ( 2155520 ) ], writes: [ blocks: 52580849 ( 112 ), bytes: 1151590912 ( 57344 ) ]
```

29
main.c
View file

@ -10,19 +10,32 @@ Modified example from: https://www.ibm.com/docs/en/aix/7.3?topic=interfaces-perf
#include <unistd.h>
#include <libperfstat.h>
const int true = 1;
const int false = 0;
int startsWith(const char *a, const char *b) {
if(strncmp(a, b, strlen(b)) == 0) return 1;
return 0;
if(strncmp(a, b, strlen(b)) == 0) return true;
return false;
}
int main(int argc, char* argv[]) {
int i, ret, tot;
int i, ret, tot, sleepSecs;
perfstat_disk_t *statp;
perfstat_id_t first;
time_t now;
if(argc == 2) {
char *a = argv[1];
sleepSecs = atoi(a);
} else {
sleepSecs = 10;
}
/* check how many perfstat_disk_t structures are available */
tot = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0);
@ -36,17 +49,18 @@ int main(int argc, char* argv[]) {
exit(-1);
}
/* keep previous values to calculate difference */
long history[32][8] = { 0 };
while(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);
while (1)
{
/* 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);
@ -122,8 +136,7 @@ int main(int argc, char* argv[]) {
history[i][1] = wblks;
}
sleep(10);
sleep(sleepSecs);
}
}