Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/top/machine.c
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | |||||
static int carc_stats[nitems(carcnames)]; | static int carc_stats[nitems(carcnames)]; | ||||
static const char *swapnames[] = { | static const char *swapnames[] = { | ||||
"K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out", | "K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out", | ||||
NULL | NULL | ||||
}; | }; | ||||
static int swap_stats[nitems(swapnames)]; | static int swap_stats[nitems(swapnames)]; | ||||
static int has_swap; | |||||
/* these are for keeping track of the proc array */ | /* these are for keeping track of the proc array */ | ||||
static int nproc; | static int nproc; | ||||
static int onproc = -1; | static int onproc = -1; | ||||
static int pref_len; | static int pref_len; | ||||
static struct kinfo_proc *pbase; | static struct kinfo_proc *pbase; | ||||
static struct kinfo_proc **pref; | static struct kinfo_proc **pref; | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | |||||
/* Adjust display based on ncpus and the ARC state. */ | /* Adjust display based on ncpus and the ARC state. */ | ||||
static void | static void | ||||
update_layout(void) | update_layout(void) | ||||
{ | { | ||||
y_mem = 3; | y_mem = 3; | ||||
y_arc = 4; | y_arc = 4; | ||||
y_carc = 5; | y_carc = 5; | ||||
y_swap = 4 + arc_enabled + carc_enabled; | y_swap = 3 + arc_enabled + carc_enabled + has_swap; | ||||
y_idlecursor = 5 + arc_enabled + carc_enabled; | y_idlecursor = 4 + arc_enabled + carc_enabled + has_swap; | ||||
y_message = 5 + arc_enabled + carc_enabled; | y_message = 4 + arc_enabled + carc_enabled + has_swap; | ||||
y_header = 6 + arc_enabled + carc_enabled; | y_header = 5 + arc_enabled + carc_enabled + has_swap; | ||||
y_procs = 7 + arc_enabled + carc_enabled; | y_procs = 6 + arc_enabled + carc_enabled + has_swap; | ||||
Header_lines = 7 + arc_enabled + carc_enabled; | Header_lines = 6 + arc_enabled + carc_enabled + has_swap; | ||||
if (pcpu_stats) { | if (pcpu_stats) { | ||||
y_mem += ncpus - 1; | y_mem += ncpus - 1; | ||||
y_arc += ncpus - 1; | y_arc += ncpus - 1; | ||||
y_carc += ncpus - 1; | y_carc += ncpus - 1; | ||||
y_swap += ncpus - 1; | y_swap += ncpus - 1; | ||||
y_idlecursor += ncpus - 1; | y_idlecursor += ncpus - 1; | ||||
y_message += ncpus - 1; | y_message += ncpus - 1; | ||||
y_header += ncpus - 1; | y_header += ncpus - 1; | ||||
y_procs += ncpus - 1; | y_procs += ncpus - 1; | ||||
Header_lines += ncpus - 1; | Header_lines += ncpus - 1; | ||||
} | } | ||||
} | } | ||||
int | int | ||||
machine_init(struct statics *statics) | machine_init(struct statics *statics) | ||||
{ | { | ||||
int i, j, empty, pagesize; | int i, j, empty, pagesize; | ||||
uint64_t arc_size; | uint64_t arc_size; | ||||
int carc_en; | int carc_en, nswapdev; | ||||
size_t size; | size_t size; | ||||
size = sizeof(smpmode); | size = sizeof(smpmode); | ||||
if ((sysctlbyname("machdep.smp_active", &smpmode, &size, | if ((sysctlbyname("machdep.smp_active", &smpmode, &size, | ||||
NULL, 0) != 0 && | NULL, 0) != 0 && | ||||
sysctlbyname("kern.smp.active", &smpmode, &size, | sysctlbyname("kern.smp.active", &smpmode, &size, | ||||
NULL, 0) != 0) || | NULL, 0) != 0) || | ||||
size != sizeof(smpmode)) | size != sizeof(smpmode)) | ||||
smpmode = 0; | smpmode = 0; | ||||
size = sizeof(arc_size); | size = sizeof(arc_size); | ||||
if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arc_size, &size, | if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arc_size, &size, | ||||
NULL, 0) == 0 && arc_size != 0) | NULL, 0) == 0 && arc_size != 0) | ||||
arc_enabled = 1; | arc_enabled = 1; | ||||
size = sizeof(carc_en); | size = sizeof(carc_en); | ||||
if (arc_enabled && | if (arc_enabled && | ||||
sysctlbyname("vfs.zfs.compressed_arc_enabled", &carc_en, &size, | sysctlbyname("vfs.zfs.compressed_arc_enabled", &carc_en, &size, | ||||
NULL, 0) == 0 && carc_en == 1) | NULL, 0) == 0 && carc_en == 1) | ||||
carc_enabled = 1; | carc_enabled = 1; | ||||
kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open"); | kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open"); | ||||
if (kd == NULL) | if (kd == NULL) | ||||
return (-1); | return (-1); | ||||
size = sizeof(nswapdev); | |||||
if (sysctlbyname("vm.nswapdev", &nswapdev, &size, NULL, | |||||
0) == 0 && nswapdev != 0) | |||||
has_swap = 1; | |||||
GETSYSCTL("kern.ccpu", ccpu); | GETSYSCTL("kern.ccpu", ccpu); | ||||
/* this is used in calculating WCPU -- calculate it ahead of time */ | /* this is used in calculating WCPU -- calculate it ahead of time */ | ||||
logcpu = log(loaddouble(ccpu)); | logcpu = log(loaddouble(ccpu)); | ||||
pbase = NULL; | pbase = NULL; | ||||
pref = NULL; | pref = NULL; | ||||
pcpu = NULL; | pcpu = NULL; | ||||
Show All 18 Lines | machine_init(struct statics *statics) | ||||
if (arc_enabled) | if (arc_enabled) | ||||
statics->arc_names = arcnames; | statics->arc_names = arcnames; | ||||
else | else | ||||
statics->arc_names = NULL; | statics->arc_names = NULL; | ||||
if (carc_enabled) | if (carc_enabled) | ||||
statics->carc_names = carcnames; | statics->carc_names = carcnames; | ||||
else | else | ||||
statics->carc_names = NULL; | statics->carc_names = NULL; | ||||
if (has_swap) | |||||
statics->swap_names = swapnames; | statics->swap_names = swapnames; | ||||
else | |||||
statics->swap_names = NULL; | |||||
statics->order_names = ordernames; | statics->order_names = ordernames; | ||||
/* Allocate state for per-CPU stats. */ | /* Allocate state for per-CPU stats. */ | ||||
cpumask = 0; | cpumask = 0; | ||||
ncpus = 0; | ncpus = 0; | ||||
GETSYSCTL("kern.smp.maxcpus", maxcpu); | GETSYSCTL("kern.smp.maxcpus", maxcpu); | ||||
times = calloc(maxcpu * CPUSTATES, sizeof(long)); | times = calloc(maxcpu * CPUSTATES, sizeof(long)); | ||||
if (times == NULL) | if (times == NULL) | ||||
▲ Show 20 Lines • Show All 1,209 Lines • Show Last 20 Lines |