Changeset View
Standalone View
usr.bin/systat/vmstat.c
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
#include <sys/vmmeter.h> | #include <sys/vmmeter.h> | ||||
#include <vm/vm_param.h> | #include <vm/vm_param.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <langinfo.h> | #include <langinfo.h> | ||||
#include <libutil.h> | |||||
#include <nlist.h> | #include <nlist.h> | ||||
#include <paths.h> | #include <paths.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <utmpx.h> | #include <utmpx.h> | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
struct statinfo cur, last, run; | struct statinfo cur, last, run; | ||||
#define total s.Total | #define total s.Total | ||||
#define nchtotal s.nchstats | #define nchtotal s.nchstats | ||||
#define oldnchtotal s1.nchstats | #define oldnchtotal s1.nchstats | ||||
static enum state { BOOT, TIME, RUN } state = TIME; | static enum state { BOOT, TIME, RUN } state = TIME; | ||||
enum divider { IEC = 0, SI = HN_DIVISOR_1000 }; | |||||
static void allocinfo(struct Info *); | static void allocinfo(struct Info *); | ||||
static void copyinfo(struct Info *, struct Info *); | static void copyinfo(struct Info *, struct Info *); | ||||
static float cputime(int); | static float cputime(int); | ||||
static void dinfo(int, int, struct statinfo *, struct statinfo *); | static void dinfo(int, int, struct statinfo *, struct statinfo *); | ||||
static void getinfo(struct Info *); | static void getinfo(struct Info *); | ||||
static void putint(int, int, int, int); | static void putint(int, int, int, int); | ||||
static void putuint64(uint64_t, int, int, int); | |||||
static void do_putuint64(uint64_t, int, int, int, int); | |||||
static void putfloat(double, int, int, int, int, int); | static void putfloat(double, int, int, int, int, int); | ||||
static void putlongdouble(long double, int, int, int, int, int); | static void putlongdouble(long double, int, int, int, int, int); | ||||
static int ucount(void); | static int ucount(void); | ||||
static int ncpu; | static int ncpu; | ||||
static char buf[26]; | static char buf[26]; | ||||
static time_t t; | static time_t t; | ||||
static double etime; | static double etime; | ||||
▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | showkre(void) | ||||
putfloat(avenrun[2], STATROW, STATCOL + 32, 5, 2, 0); | putfloat(avenrun[2], STATROW, STATCOL + 32, 5, 2, 0); | ||||
mvaddstr(STATROW, STATCOL + 55, buf); | mvaddstr(STATROW, STATCOL + 55, buf); | ||||
#define pgtokb(pg) ((pg) * (s.v_page_size / 1024)) | #define pgtokb(pg) ((pg) * (s.v_page_size / 1024)) | ||||
putfloat(100.0 * (v_page_count - total.t_free) / v_page_count, | putfloat(100.0 * (v_page_count - total.t_free) / v_page_count, | ||||
STATROW + 1, STATCOL + 15, 2, 0, 1); | STATROW + 1, STATCOL + 15, 2, 0, 1); | ||||
putfloat(100.0 * s.v_kmem_map_size / kmem_size, | putfloat(100.0 * s.v_kmem_map_size / kmem_size, | ||||
STATROW + 1, STATCOL + 22, 2, 0, 1); | STATROW + 1, STATCOL + 22, 2, 0, 1); | ||||
putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7); | putuint64(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7); | ||||
putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7); | putuint64(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7); | ||||
putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8); | putuint64(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8); | ||||
putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8); | putuint64(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8); | ||||
putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7); | putuint64(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7); | ||||
putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7); | putuint64(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7); | ||||
putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8); | putuint64(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8); | ||||
putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8); | putuint64(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8); | ||||
putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7); | putuint64(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7); | ||||
putint(total.t_rq - 1, PROCSROW + 2, PROCSCOL, 3); | putint(total.t_rq - 1, PROCSROW + 2, PROCSCOL, 3); | ||||
putint(total.t_pw, PROCSROW + 2, PROCSCOL + 4, 3); | putint(total.t_pw, PROCSROW + 2, PROCSCOL + 4, 3); | ||||
putint(total.t_dw, PROCSROW + 2, PROCSCOL + 8, 3); | putint(total.t_dw, PROCSROW + 2, PROCSCOL + 8, 3); | ||||
putint(total.t_sl, PROCSROW + 2, PROCSCOL + 12, 3); | putint(total.t_sl, PROCSROW + 2, PROCSCOL + 12, 3); | ||||
putint(total.t_sw, PROCSROW + 2, PROCSCOL + 16, 3); | putint(total.t_sw, PROCSROW + 2, PROCSCOL + 16, 3); | ||||
PUTRATE(v_io_faults, VMSTATROW, VMSTATCOL + 2, 8 - 2); | PUTRATE(v_io_faults, VMSTATROW, VMSTATCOL + 2, 8 - 2); | ||||
PUTRATE(v_cow_faults, VMSTATROW + 1, VMSTATCOL + 2, 8 - 2); | PUTRATE(v_cow_faults, VMSTATROW + 1, VMSTATCOL + 2, 8 - 2); | ||||
PUTRATE(v_zfod, VMSTATROW + 2, VMSTATCOL + 2, 8 - 2); | PUTRATE(v_zfod, VMSTATROW + 2, VMSTATCOL + 2, 8 - 2); | ||||
PUTRATE(v_ozfod, VMSTATROW + 3, VMSTATCOL, 8); | PUTRATE(v_ozfod, VMSTATROW + 3, VMSTATCOL, 8); | ||||
putint(s.v_zfod != 0 ? (int)(s.v_ozfod * 100.0 / s.v_zfod) : 0, | putint(s.v_zfod != 0 ? (int)(s.v_ozfod * 100.0 / s.v_zfod) : 0, | ||||
VMSTATROW + 4, VMSTATCOL + 1, 8 - 1); | VMSTATROW + 4, VMSTATCOL + 1, 8 - 1); | ||||
PUTRATE(v_dfree, VMSTATROW + 5, VMSTATCOL + 2, 8 - 2); | PUTRATE(v_dfree, VMSTATROW + 5, VMSTATCOL + 2, 8 - 2); | ||||
PUTRATE(v_pfree, VMSTATROW + 6, VMSTATCOL + 2, 8 - 2); | PUTRATE(v_pfree, VMSTATROW + 6, VMSTATCOL + 2, 8 - 2); | ||||
PUTRATE(v_tfree, VMSTATROW + 7, VMSTATCOL, 8); | PUTRATE(v_tfree, VMSTATROW + 7, VMSTATCOL, 8); | ||||
PUTRATE(v_reactivated, VMSTATROW + 8, VMSTATCOL, 8); | PUTRATE(v_reactivated, VMSTATROW + 8, VMSTATCOL, 8); | ||||
PUTRATE(v_pdwakeups, VMSTATROW + 9, VMSTATCOL, 8); | PUTRATE(v_pdwakeups, VMSTATROW + 9, VMSTATCOL, 8); | ||||
PUTRATE(v_pdpages, VMSTATROW + 10, VMSTATCOL, 8); | PUTRATE(v_pdpages, VMSTATROW + 10, VMSTATCOL, 8); | ||||
PUTRATE(v_intrans, VMSTATROW + 11, VMSTATCOL, 8); | PUTRATE(v_intrans, VMSTATROW + 11, VMSTATCOL, 8); | ||||
putint(pgtokb(s.v_wire_count), VMSTATROW + 12, VMSTATCOL, 8); | putuint64(pgtokb(s.v_wire_count), VMSTATROW + 12, VMSTATCOL, 8); | ||||
putint(pgtokb(s.v_active_count), VMSTATROW + 13, VMSTATCOL, 8); | putuint64(pgtokb(s.v_active_count), VMSTATROW + 13, VMSTATCOL, 8); | ||||
putint(pgtokb(s.v_inactive_count), VMSTATROW + 14, VMSTATCOL, 8); | putuint64(pgtokb(s.v_inactive_count), VMSTATROW + 14, VMSTATCOL, 8); | ||||
putint(pgtokb(s.v_laundry_count), VMSTATROW + 15, VMSTATCOL, 8); | putuint64(pgtokb(s.v_laundry_count), VMSTATROW + 15, VMSTATCOL, 8); | ||||
putint(pgtokb(s.v_free_count), VMSTATROW + 16, VMSTATCOL, 8); | putuint64(pgtokb(s.v_free_count), VMSTATROW + 16, VMSTATCOL, 8); | ||||
if (LINES - 1 > VMSTATROW + 17) | if (LINES - 1 > VMSTATROW + 17) | ||||
putint(s.bufspace / 1024, VMSTATROW + 17, VMSTATCOL, 8); | putuint64(s.bufspace / 1024, VMSTATROW + 17, VMSTATCOL, 8); | ||||
PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5); | PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5); | ||||
PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 12, 5); | PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 12, 5); | ||||
PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 19, 5); | PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 19, 5); | ||||
PUTRATE(v_swapout, PAGEROW + 2, PAGECOL + 25, 5); | PUTRATE(v_swapout, PAGEROW + 2, PAGECOL + 25, 5); | ||||
PUTRATE(v_vnodepgsin, PAGEROW + 3, PAGECOL + 6, 5); | PUTRATE(v_vnodepgsin, PAGEROW + 3, PAGECOL + 6, 5); | ||||
PUTRATE(v_vnodepgsout, PAGEROW + 3, PAGECOL + 12, 5); | PUTRATE(v_vnodepgsout, PAGEROW + 3, PAGECOL + 12, 5); | ||||
PUTRATE(v_swappgsin, PAGEROW + 3, PAGECOL + 19, 5); | PUTRATE(v_swappgsin, PAGEROW + 3, PAGECOL + 19, 5); | ||||
PUTRATE(v_swappgsout, PAGEROW + 3, PAGECOL + 25, 5); | PUTRATE(v_swappgsout, PAGEROW + 3, PAGECOL + 25, 5); | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | cputime(int indx) | ||||
if (lt == 0.0) | if (lt == 0.0) | ||||
lt = 1.0; | lt = 1.0; | ||||
return (s.time[indx] * 100.0 / lt); | return (s.time[indx] * 100.0 / lt); | ||||
} | } | ||||
static void | static void | ||||
putint(int n, int l, int lc, int w) | putint(int n, int l, int lc, int w) | ||||
{ | { | ||||
kib: Blank line is required by style(9) after '{' if no local vars are defined. | |||||
do_putuint64(n, l, lc, w, SI); | |||||
} | |||||
static void | |||||
putuint64(uint64_t n, int l, int lc, int w) | |||||
{ | |||||
do_putuint64(n, l, lc, w, IEC); | |||||
} | |||||
Not Done Inline ActionsPerhaps name this function do_putuint64(). kib: Perhaps name this function do_putuint64(). | |||||
static void | |||||
do_putuint64(uint64_t n, int l, int lc, int w, int div) | |||||
Done Inline ActionsThe format specifier is wrong, type of n is not uintmax_t. kib: The format specifier is wrong, type of n is not uintmax_t. | |||||
{ | |||||
int snr; | int snr; | ||||
char b[128]; | char b[128]; | ||||
Not Done Inline ActionsWhy use DIV_1000 ? It is completely unexpected to have decimal suffix for the memory size. We do not sell harddrives. kib: Why use DIV_1000 ? It is completely unexpected to have decimal suffix for the memory size. We… | |||||
Not Done Inline ActionsI kept what the old version did, which was dividing bo 1000. kaktus: I kept what the old version did, which was dividing bo 1000. | |||||
Not Done Inline ActionsI think it is reasonable to use natural suffixes, instead of decimals. Especially because we do not stop at k. kib: I think it is reasonable to use natural suffixes, instead of decimals. Especially because we… | |||||
char buf[128]; | |||||
Not Done Inline ActionsWhy do you ever need this snprintf() ? To copy the string, use strlcpy(). kib: Why do you ever need this snprintf() ? To copy the string, use strlcpy(). | |||||
Not Done Inline ActionsBecause it pads the code to the length of w, returning the whole length that is used later. kaktus: Because it pads the code to the length of `w`, returning the whole length that is used later. | |||||
Not Done Inline Actionss/code/string/ kaktus: s/code/string/ | |||||
move(l, lc); | move(l, lc); | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
while (w-- > 0) | while (w-- > 0) | ||||
addch('*'); | addch('*'); | ||||
return; | return; | ||||
#endif | #endif | ||||
if (n == 0) { | if (n == 0) { | ||||
while (w-- > 0) | while (w-- > 0) | ||||
addch(' '); | addch(' '); | ||||
return; | return; | ||||
} | } | ||||
snr = snprintf(b, sizeof(b), "%*d", w, n); | snr = snprintf(b, sizeof(b), "%*jd", w, (uintmax_t)n); | ||||
if (snr != w) | if (snr != w) { | ||||
snr = snprintf(b, sizeof(b), "%*dk", w - 1, n / 1000); | humanize_number(buf, w, n, "", HN_AUTOSCALE, | ||||
if (snr != w) | HN_NOSPACE | HN_DECIMAL | div); | ||||
snr = snprintf(b, sizeof(b), "%*dM", w - 1, n / 1000000); | snr = snprintf(b, sizeof(b), "%*s", w, buf); | ||||
} | |||||
Not Done Inline ActionsThe cast of n to uintmax_t is what lot of places in the FreeBSD tree use. I believe there is almost no uses of PRIi64 in the non-contributed code, and some people dislike this feature loudly. kib: The cast of n to uintmax_t is what lot of places in the FreeBSD tree use. I believe there is… | |||||
if (snr != w) { | if (snr != w) { | ||||
while (w-- > 0) | while (w-- > 0) | ||||
addch('*'); | addch('*'); | ||||
return; | return; | ||||
} | } | ||||
addstr(b); | addstr(b); | ||||
} | } | ||||
Show All 16 Lines | #endif | ||||
} | } | ||||
snr = snprintf(b, sizeof(b), "%*.*f", w, d, f); | snr = snprintf(b, sizeof(b), "%*.*f", w, d, f); | ||||
if (snr != w) | if (snr != w) | ||||
snr = snprintf(b, sizeof(b), "%*.0f", w, f); | snr = snprintf(b, sizeof(b), "%*.0f", w, f); | ||||
if (snr != w) | if (snr != w) | ||||
snr = snprintf(b, sizeof(b), "%*.0fk", w - 1, f / 1000); | snr = snprintf(b, sizeof(b), "%*.0fk", w - 1, f / 1000); | ||||
if (snr != w) | if (snr != w) | ||||
snr = snprintf(b, sizeof(b), "%*.0fM", w - 1, f / 1000000); | snr = snprintf(b, sizeof(b), "%*.0fM", w - 1, f / 1000000); | ||||
if (snr != w) { | if (snr != w) { | ||||
Done Inline ActionsWhy the explicit cast for f is needed ? That said, use of humanize_number for floating-point value is weird. Why do you change this code, for which field it matters ? kib: Why the explicit cast for f is needed ?
That said, use of humanize_number for floating-point… | |||||
Not Done Inline ActionsI did the change for consistency with the putint() function. As you see in case of number larger enough the decimal part is dropped. Anyway, I think that the code is dead anyway because I wasn't able to cause any of the % field to grow beyond 100%. kaktus: I did the change for consistency with the putint() function. As you see in case of number… | |||||
while (--w >= 0) | while (--w >= 0) | ||||
addch('*'); | addch('*'); | ||||
return; | return; | ||||
} | } | ||||
addstr(b); | addstr(b); | ||||
} | } | ||||
static void | static void | ||||
Show All 15 Lines | #endif | ||||
} | } | ||||
snr = snprintf(b, sizeof(b), "%*.*Lf", w, d, f); | snr = snprintf(b, sizeof(b), "%*.*Lf", w, d, f); | ||||
if (snr != w) | if (snr != w) | ||||
snr = snprintf(b, sizeof(b), "%*.0Lf", w, f); | snr = snprintf(b, sizeof(b), "%*.0Lf", w, f); | ||||
if (snr != w) | if (snr != w) | ||||
snr = snprintf(b, sizeof(b), "%*.0Lfk", w - 1, f / 1000); | snr = snprintf(b, sizeof(b), "%*.0Lfk", w - 1, f / 1000); | ||||
if (snr != w) | if (snr != w) | ||||
snr = snprintf(b, sizeof(b), "%*.0LfM", w - 1, f / 1000000); | snr = snprintf(b, sizeof(b), "%*.0LfM", w - 1, f / 1000000); | ||||
if (snr != w) { | if (snr != w) { | ||||
Not Done Inline ActionsSame as above. kib: Same as above. | |||||
while (--w >= 0) | while (--w >= 0) | ||||
addch('*'); | addch('*'); | ||||
return; | return; | ||||
} | } | ||||
addstr(b); | addstr(b); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |
Blank line is required by style(9) after '{' if no local vars are defined.