version 1.14, 2004/07/03 22:25:15 |
version 1.15, 2004/07/09 16:33:15 |
|
|
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <nlist.h> |
|
#include <err.h> |
#include <err.h> |
#include <paths.h> |
#include <paths.h> |
#include "systat.h" |
#include "systat.h" |
#include "extern.h" |
#include "extern.h" |
|
|
static struct mbstat *mb; |
static struct mbstat mb; |
|
|
char *mtnames[] = { |
char *mtnames[] = { |
"free", |
"free", |
|
|
int i, j, max, index; |
int i, j, max, index; |
char buf[13]; |
char buf[13]; |
|
|
if (mb == 0) |
|
return; |
|
for (j = 0; j < wnd->_maxy; j++) { |
for (j = 0; j < wnd->_maxy; j++) { |
max = 0, index = -1; |
max = 0, index = -1; |
for (i = 0; i < wnd->_maxy; i++) |
for (i = 0; i < wnd->_maxy; i++) |
if (mb->m_mtypes[i] > max) { |
if (mb.m_mtypes[i] > max) { |
max = mb->m_mtypes[i]; |
max = mb.m_mtypes[i]; |
index = i; |
index = i; |
} |
} |
if (max == 0) |
if (max == 0) |
|
|
waddch(wnd, 'X'); |
waddch(wnd, 'X'); |
wclrtoeol(wnd); |
wclrtoeol(wnd); |
} |
} |
mb->m_mtypes[index] = 0; |
mb.m_mtypes[index] = 0; |
} |
} |
wmove(wnd, 1+j, 0); wclrtobot(wnd); |
wmove(wnd, 1+j, 0); wclrtobot(wnd); |
} |
} |
|
|
static struct nlist namelist[] = { |
|
#define X_MBSTAT 0 /* sysctl */ |
|
{ "_mbstat" }, |
|
{ "" } |
|
}; |
|
|
|
int |
|
initmbufs(void) |
|
{ |
|
int ret; |
|
|
|
if (kd != NULL) { |
|
if (namelist[X_MBSTAT].n_type == 0) { |
|
if ((ret = kvm_nlist(kd, namelist)) == -1) |
|
errx(1, "%s", kvm_geterr(kd)); |
|
else if (ret) |
|
nlisterr(namelist); |
|
if (namelist[X_MBSTAT].n_type == 0) { |
|
error("namelist on %s failed", _PATH_UNIX); |
|
return(0); |
|
} |
|
} |
|
} |
|
if (mb == 0) |
|
mb = (struct mbstat *)calloc(1, sizeof (*mb)); |
|
return(1); |
|
} |
|
|
|
void |
void |
fetchmbufs(void) |
fetchmbufs(void) |
{ |
{ |
int mib[2]; |
int mib[2]; |
size_t size = sizeof (*mb); |
size_t size = sizeof (mb); |
|
|
if (kd == NULL) { |
mib[0] = CTL_KERN; |
mib[0] = CTL_KERN; |
mib[1] = KERN_MBSTAT; |
mib[1] = KERN_MBSTAT; |
if (sysctl(mib, 2, &mb, &size, NULL, 0) < 0) |
if (sysctl(mib, 2, mb, &size, NULL, 0) < 0) |
err(1, "sysctl(KERN_MBSTAT) failed"); |
err(1, "sysctl(KERN_MBSTAT) failed"); |
} |
} else { |
|
if (namelist[X_MBSTAT].n_type == 0) |
int |
return; |
initmbufs(void) |
NREAD(X_MBSTAT, mb, size); |
{ |
} |
return (1); |
} |
} |