Back to story
/*
* Copyright (c) 1994 by Sun Microsystems, Inc.
*/
#ifndef _P_IOSTAT_CLASS_SE_
#define _P_IOSTAT_CLASS_SE_
/* this file requires the following include files
*
* #include
* #include
* #include
* #include
*/
class p_iostat {
int number$;
string name$;
int disk_count;
double reads;
double writes;
double read_writes;
double utilization;
double kreads;
double kwrites;
double kread_writes;
double avg_wait;
double avg_run;
double service;
double wait_percent;
double run_percent;
p_iostat$()
{
/* by default, local variables are static */
ks_disks kstat$disk;
ks_disks tmp_disk;
ks_system_misc kstat$misc;
/* per disk vars */
double rps[MAX_DISK];
double wps[MAX_DISK];
double util[MAX_DISK];
double krps[MAX_DISK];
double kwps[MAX_DISK];
double avw[MAX_DISK];
double avr[MAX_DISK];
double serv[MAX_DISK];
double w_pct[MAX_DISK];
double r_pct[MAX_DISK];
ulong old_rps[MAX_DISK];
ulong old_wps[MAX_DISK];
longlong old_update[MAX_DISK];
longlong old_rtime[MAX_DISK];
longlong old_wtime[MAX_DISK];
ulonglong old_nread[MAX_DISK];
ulonglong old_nwritten[MAX_DISK];
longlong old_wlentime[MAX_DISK];
longlong old_rlentime[MAX_DISK];
string disk_name[MAX_DISK];
/* I even need different elapsed times for each disk */
ulong etime[MAX_DISK];
ulong old_time[MAX_DISK];
ulong new_time;
/* other stuff */
long hz = sysconf(_SC_CLK_TCK);
int ndisks;
int initialized = 0;
int last_number;
int i;
int n;
double hr_etime;
longlong rtime;
if (initialized == 0) {
/* count the disks */
for(kstat$disk.number$=0; kstat$disk.number$ != -1; kstat$disk.number$++){
ndisks = kstat$disk.number$ + 1;
}
disk_count = ndisks;
/* snag initial values */
n = kstat$misc.clk_intr;
for(i=0; i= ndisks) {
number$ = -1;
return;
}
/* disk index */
i = number$;
kstat$disk.number$ = i;
name$ = disk_name[i];
/* how much time has gone by */
new_time = kstat$misc.clk_intr;
etime[i] = (new_time - old_time[i]) / hz;
/* no time has gone by, return */
if (etime[i] == 0) {
if (i != last_number) {
reads = rps[i];
writes = wps[i];
read_writes = rps[i] + wps[i];
last_number = i;
}
return;
}
old_time[i] = new_time;
/* cut down on system calls */
tmp_disk = kstat$disk;
/* compute */
rps[i] = ((tmp_disk.reads - old_rps[i]) * 1.0) / etime[i];
wps[i] = ((tmp_disk.writes - old_wps[i]) * 1.0) / etime[i];
hr_etime = tmp_disk.wlastupdate - old_update[i];
rtime = tmp_disk.rtime - old_rtime[i];
if (hr_etime == 0) {
hr_etime = NANOSEC;
}
util[i] = (rtime * 100.0) / hr_etime;
krps[i] = (tmp_disk.nread - old_nread[i]) / etime[i] / 1024.0;
kwps[i] = (tmp_disk.nwritten - old_nwritten[i]) / etime[i] / 1024.0;
avw[i] = (tmp_disk.wlentime - old_wlentime[i]) / hr_etime;
avr[i] = (tmp_disk.rlentime - old_rlentime[i]) / hr_etime;
read_writes = rps[i] + wps[i];
if (read_writes > 0) {
serv[i] = ((avr[i] + avw[i]) * 1000.0) / read_writes;
} else {
serv[i] = 0.0;
}
w_pct[i] = ((tmp_disk.wtime - old_wtime[i]) * 100.0) / hr_etime;
r_pct[i] = ((tmp_disk.rtime - old_rtime[i]) * 100.0) / hr_etime;
/* save old */
old_rps[i] = tmp_disk.reads;
old_wps[i] = tmp_disk.writes;
old_update[i] = tmp_disk.wlastupdate;
old_rtime[i] = tmp_disk.rtime;
old_wtime[i] = tmp_disk.wtime;
old_nread[i] = tmp_disk.nread;
old_nwritten[i] = tmp_disk.nwritten;
old_wlentime[i] = tmp_disk.wlentime;
old_rlentime[i] = tmp_disk.rlentime;
/* update and return */
reads = rps[i];
writes = wps[i];
utilization = util[i];
kreads = krps[i];
kwrites = kwps[i];
kread_writes = krps[i] + kwps[i];
avg_wait = avw[i];
avg_run = avr[i];
service = serv[i];
wait_percent = w_pct[i];
run_percent = r_pct[i];
}
};
#endif /* _P_IOSTAT_CLASS_SE_ */
Back to story