version 1.15, 2002/02/16 21:27:58 |
version 1.16, 2002/05/23 10:35:07 |
|
|
#include <unistd.h> |
#include <unistd.h> |
#include "dkstats.h" |
#include "dkstats.h" |
|
|
|
#if !defined(NOKVM) |
static struct nlist namelist[] = { |
static struct nlist namelist[] = { |
#define X_TK_NIN 0 |
#define X_TK_NIN 0 |
{ "_tk_nin" }, /* tty characters in */ |
{ "_tk_nin" }, /* tty characters in */ |
|
|
{ "_disklist" }, /* TAILQ of disks */ |
{ "_disklist" }, /* TAILQ of disks */ |
{ NULL }, |
{ NULL }, |
}; |
}; |
|
#define KVM_ERROR(_string) { \ |
|
warnx("%s", (_string)); \ |
|
errx(1, "%s", kvm_geterr(kd)); \ |
|
} |
|
|
|
/* |
|
* Dereference the namelist pointer `v' and fill in the local copy |
|
* 'p' which is of size 's'. |
|
*/ |
|
#define deref_nl(v, p, s) deref_kptr((void *)namelist[(v)].n_value, (p), (s)); |
|
static void deref_kptr(void *, void *, size_t); |
|
#endif /* !defined(NOKVM) */ |
|
|
/* Structures to hold the statistics. */ |
/* Structures to hold the statistics. */ |
struct _disk cur, last; |
struct _disk cur, last; |
|
|
|
|
int *dk_select; |
int *dk_select; |
char **dr_name; |
char **dr_name; |
|
|
#define KVM_ERROR(_string) { \ |
|
warnx("%s", (_string)); \ |
|
errx(1, "%s", kvm_geterr(kd)); \ |
|
} |
|
|
|
/* |
|
* Dereference the namelist pointer `v' and fill in the local copy |
|
* 'p' which is of size 's'. |
|
*/ |
|
#define deref_nl(v, p, s) deref_kptr((void *)namelist[(v)].n_value, (p), (s)); |
|
|
|
/* Missing from <sys/time.h> */ |
/* Missing from <sys/time.h> */ |
#define timerset(tvp, uvp) ((uvp)->tv_sec = (tvp)->tv_sec); \ |
#define timerset(tvp, uvp) \ |
((uvp)->tv_usec = (tvp)->tv_usec) |
((uvp)->tv_sec = (tvp)->tv_sec); \ |
|
((uvp)->tv_usec = (tvp)->tv_usec) |
|
|
static void deref_kptr(void *, void *, size_t); |
#define SWAP(fld) tmp = cur.fld; \ |
|
cur.fld -= last.fld; \ |
|
last.fld = tmp |
|
|
/* |
/* |
* Take the delta between the present values and the last recorded |
* Take the delta between the present values and the last recorded |
|
|
void |
void |
dkswap() |
dkswap() |
{ |
{ |
#define SWAP(fld) tmp = cur.fld; \ |
|
cur.fld -= last.fld; \ |
|
last.fld = tmp |
|
u_int64_t tmp; |
u_int64_t tmp; |
int i; |
int i; |
|
|
|
|
cur.tk_nout = 0; |
cur.tk_nout = 0; |
} |
} |
} else { |
} else { |
|
#if !defined(NOKVM) |
p = dk_drivehead; |
p = dk_drivehead; |
|
|
for (i = 0; i < dk_ndrive; i++) { |
for (i = 0; i < dk_ndrive; i++) { |
|
|
timerset(&(cur_disk.dk_time), &(cur.dk_time[i])); |
timerset(&(cur_disk.dk_time), &(cur.dk_time[i])); |
p = cur_disk.dk_link.tqe_next; |
p = cur_disk.dk_link.tqe_next; |
} |
} |
|
|
deref_nl(X_CP_TIME, cur.cp_time, sizeof(cur.cp_time)); |
deref_nl(X_CP_TIME, cur.cp_time, sizeof(cur.cp_time)); |
deref_nl(X_TK_NIN, &cur.tk_nin, sizeof(cur.tk_nin)); |
deref_nl(X_TK_NIN, &cur.tk_nin, sizeof(cur.tk_nin)); |
deref_nl(X_TK_NOUT, &cur.tk_nout, sizeof(cur.tk_nout)); |
deref_nl(X_TK_NOUT, &cur.tk_nout, sizeof(cur.tk_nout)); |
|
#endif /* !defined(NOKVM) */ |
} |
} |
} |
} |
|
|
|
|
return(1); |
return(1); |
|
|
if (nlistf != NULL || memf != NULL) { |
if (nlistf != NULL || memf != NULL) { |
|
#if !defined(NOKVM) |
/* Open the kernel. */ |
/* Open the kernel. */ |
if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, |
if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, |
errbuf)) == NULL) |
errbuf)) == NULL) |
|
|
deref_nl(X_STATHZ, &hz, sizeof(hz)); |
deref_nl(X_STATHZ, &hz, sizeof(hz)); |
if (!hz) |
if (!hz) |
deref_nl(X_HZ, &hz, sizeof(hz)); |
deref_nl(X_HZ, &hz, sizeof(hz)); |
|
#endif /* !defined(NOKVM) */ |
} else { |
} else { |
/* Get the number of attached drives. */ |
/* Get the number of attached drives. */ |
mib[0] = CTL_HW; |
mib[0] = CTL_HW; |
|
|
cur.dk_select[i++] = select; |
cur.dk_select[i++] = select; |
} |
} |
} else { |
} else { |
|
#if !defined(NOKVM) |
p = dk_drivehead; |
p = dk_drivehead; |
for (i = 0; i < dk_ndrive; i++) { |
for (i = 0; i < dk_ndrive; i++) { |
char buf[10]; |
char buf[10]; |
|
|
deref_kptr(p, &cur_disk, sizeof(cur_disk)); |
deref_kptr(p, &cur_disk, sizeof(cur_disk)); |
deref_kptr(cur_disk.dk_name, buf, sizeof(buf)); |
deref_kptr(cur_disk.dk_name, buf, sizeof(buf)); |
cur.dk_name[i] = strdup(buf); |
cur.dk_name[i] = strdup(buf); |
|
|
|
|
p = cur_disk.dk_link.tqe_next; |
p = cur_disk.dk_link.tqe_next; |
} |
} |
|
#endif /* !defined(NOKVM) */ |
} |
} |
|
|
/* Never do this initalization again. */ |
/* Never do this initalization again. */ |
|
|
return(1); |
return(1); |
} |
} |
|
|
|
#if !defined(NOKVM) |
/* |
/* |
* Dereference the kernel pointer `kptr' and fill in the local copy |
* Dereference the kernel pointer `kptr' and fill in the local copy |
* pointed to by `ptr'. The storage space must be pre-allocated, |
* pointed to by `ptr'. The storage space must be pre-allocated, |
|
|
KVM_ERROR(buf); |
KVM_ERROR(buf); |
} |
} |
} |
} |
|
#endif /* !defined(NOKVM) */ |
|
|