Hi, everyone.
I need to write a program to get io info based on libperfstat.
But the "write time" of a disk is just half of the value get from iostat.
I'm confused and can't explain. Help please.
How I calculate "write service time per sec":
In iostat:
write service time per sec = wps * avgserv
wps: write requests per sec
avgserv: avg service time per write request
In my program:
(new wserv - old wserv) / intervalTime
iostat cmd:
iostat -D hdisk1 10
My C code :
int i, ret, tot;
perfstat_disk_t *statp;
perfstat_id_t first;
unsigned long long oldValue = 0;
unsigned long long newValue = 0;
int interval = 10;
while (true) {
/* check how many perfstat_disk_t structures are available */
tot = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0);
/* 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);
/* print statistics for each of the disks */
for (i = 0; i < ret; i++) {
if (strcmp(statp.name, "hdisk1") == 0) {
printf("\nStatistics for disk : %s\n", statp.name);
printf("-------------------\n");
newValue = statp.wserv;
printf("write time : %llu /s\n", (newValue - oldValue)/interval);
oldValue = newValue;
}
}
sleep(interval); // sleep 10s
}