Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/top/machine.c
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | #define ki_swap(kip) \ | ||||
((kip)->ki_swrss > (kip)->ki_rssize ? (kip)->ki_swrss - (kip)->ki_rssize : 0) | ((kip)->ki_swrss > (kip)->ki_rssize ? (kip)->ki_swrss - (kip)->ki_rssize : 0) | ||||
/* | /* | ||||
* Sorting orders. The first element is the default. | * Sorting orders. The first element is the default. | ||||
*/ | */ | ||||
static const char *ordernames[] = { | static const char *ordernames[] = { | ||||
"cpu", "size", "res", "time", "pri", "threads", | "cpu", "size", "res", "time", "pri", "threads", | ||||
"total", "read", "write", "fault", "vcsw", "ivcsw", | "total", "read", "write", "fault", "vcsw", "ivcsw", | ||||
"jid", "swap", "pid", NULL | "jid", "swap", "core", "pid", NULL | ||||
}; | }; | ||||
/* Per-cpu time states */ | /* Per-cpu time states */ | ||||
static int maxcpu; | static int maxcpu; | ||||
static int maxid; | static int maxid; | ||||
static int ncpus; | static int ncpus; | ||||
static unsigned long cpumask; | static unsigned long cpumask; | ||||
static long *times; | static long *times; | ||||
static long *pcpu_cp_time; | static long *pcpu_cp_time; | ||||
static long *pcpu_cp_old; | static long *pcpu_cp_old; | ||||
static long *pcpu_cp_diff; | static long *pcpu_cp_diff; | ||||
static int *pcpu_cpu_states; | static int *pcpu_cpu_states; | ||||
static int compare_swap(const void *a, const void *b); | static int compare_swap(const void *a, const void *b); | ||||
static int compare_jid(const void *a, const void *b); | static int compare_jid(const void *a, const void *b); | ||||
static int compare_pid(const void *a, const void *b); | static int compare_pid(const void *a, const void *b); | ||||
static int compare_tid(const void *a, const void *b); | static int compare_tid(const void *a, const void *b); | ||||
static int compare_core(const void *a, const void *b); | |||||
static const char *format_nice(const struct kinfo_proc *pp); | static const char *format_nice(const struct kinfo_proc *pp); | ||||
static void getsysctl(const char *name, void *ptr, size_t len); | static void getsysctl(const char *name, void *ptr, size_t len); | ||||
static int swapmode(int *retavail, int *retfree); | static int swapmode(int *retavail, int *retfree); | ||||
static void update_layout(void); | static void update_layout(void); | ||||
static int find_uid(uid_t needle, int *haystack); | static int find_uid(uid_t needle, int *haystack); | ||||
static int | static int | ||||
find_uid(uid_t needle, int *haystack) | find_uid(uid_t needle, int *haystack) | ||||
▲ Show 20 Lines • Show All 1,046 Lines • ▼ Show 20 Lines | |||||
} while (0) | } while (0) | ||||
#define ORDERKEY_SWAP(a, b) do { \ | #define ORDERKEY_SWAP(a, b) do { \ | ||||
int diff = (int)ki_swap(b) - (int)ki_swap(a); \ | int diff = (int)ki_swap(b) - (int)ki_swap(a); \ | ||||
if (diff != 0) \ | if (diff != 0) \ | ||||
return (diff > 0 ? 1 : -1); \ | return (diff > 0 ? 1 : -1); \ | ||||
} while (0) | } while (0) | ||||
#define ORDERKEY_CORE(a, b) do { \ | |||||
int cpu1, cpu2; \ | |||||
if ((int)(a)->ki_stat == SRUN && (int)(a)->ki_oncpu != NOCPU) \ | |||||
cpu1 = (int)(a)->ki_oncpu; \ | |||||
else \ | |||||
cpu1 = (int)(a)->ki_lastcpu; \ | |||||
if ((int)(b)->ki_stat == SRUN && (int)(b)->ki_oncpu != NOCPU) \ | |||||
cpu2 = (int)(b)->ki_oncpu; \ | |||||
else \ | |||||
cpu2 = (int)(b)->ki_lastcpu; \ | |||||
int diff = cpu2 - cpu1; \ | |||||
if (diff != 0) \ | |||||
return (diff > 0 ? 1 : -1); \ | |||||
} while (0) | |||||
/* compare_cpu - the comparison function for sorting by cpu percentage */ | /* compare_cpu - the comparison function for sorting by cpu percentage */ | ||||
static int | static int | ||||
compare_cpu(const void *arg1, const void *arg2) | compare_cpu(const void *arg1, const void *arg2) | ||||
{ | { | ||||
const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1; | const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1; | ||||
const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2; | const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2; | ||||
ORDERKEY_PCTCPU(p1, p2); | ORDERKEY_PCTCPU(p1, p2); | ||||
ORDERKEY_CPTICKS(p1, p2); | ORDERKEY_CPTICKS(p1, p2); | ||||
ORDERKEY_STATE(p1, p2); | ORDERKEY_STATE(p1, p2); | ||||
ORDERKEY_PRIO(p1, p2); | ORDERKEY_PRIO(p1, p2); | ||||
ORDERKEY_RSSIZE(p1, p2); | ORDERKEY_RSSIZE(p1, p2); | ||||
ORDERKEY_MEM(p1, p2); | ORDERKEY_MEM(p1, p2); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* compare_core - the comparison function for sorting by cpu core number */ | |||||
static int | |||||
compare_core(const void *arg1, const void *arg2) | |||||
{ | |||||
const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1; | |||||
const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2; | |||||
ORDERKEY_CORE(p1, p2); | |||||
ORDERKEY_PCTCPU(p1, p2); | |||||
ORDERKEY_CPTICKS(p1, p2); | |||||
ORDERKEY_STATE(p1, p2); | |||||
ORDERKEY_PRIO(p1, p2); | |||||
ORDERKEY_RSSIZE(p1, p2); | |||||
return(0); | |||||
} | |||||
/* compare_size - the comparison function for sorting by total memory usage */ | /* compare_size - the comparison function for sorting by total memory usage */ | ||||
static int | static int | ||||
compare_size(const void *arg1, const void *arg2) | compare_size(const void *arg1, const void *arg2) | ||||
{ | { | ||||
const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1; | const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1; | ||||
const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2; | const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2; | ||||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | int (*compares[])(const void *arg1, const void *arg2) = { | ||||
compare_iototal, | compare_iototal, | ||||
compare_ioread, | compare_ioread, | ||||
compare_iowrite, | compare_iowrite, | ||||
compare_iofault, | compare_iofault, | ||||
compare_vcsw, | compare_vcsw, | ||||
compare_ivcsw, | compare_ivcsw, | ||||
compare_jid, | compare_jid, | ||||
compare_swap, | compare_swap, | ||||
compare_core, | |||||
NULL | NULL | ||||
}; | }; | ||||
static int | static int | ||||
swapmode(int *retavail, int *retfree) | swapmode(int *retavail, int *retfree) | ||||
{ | { | ||||
int n; | int n; | ||||
Show All 31 Lines |