Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/systat/sysput.c
Show All 35 Lines | |||||
#include <string.h> | #include <string.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <libutil.h> | #include <libutil.h> | ||||
#include "systat.h" | #include "systat.h" | ||||
#include "extern.h" | #include "extern.h" | ||||
void | void | ||||
sysputstrs(WINDOW *wnd, int row, int col, int width) | sysputspaces(WINDOW *wd, int row, int col, int width) | ||||
{ | { | ||||
static char str40[] = " "; | |||||
mvwaddstr(wd, row, col, str40 + sizeof(str40) - width - 1); | |||||
} | |||||
void | |||||
sysputstrs(WINDOW *wd, int row, int col, int width) | |||||
{ | |||||
static char str40[] = "****************************************"; | static char str40[] = "****************************************"; | ||||
mvwaddstr(wnd, row, col, str40 + sizeof(str40) - width - 1); | mvwaddstr(wnd, row, col, str40 + sizeof(str40) - width - 1); | ||||
} | } | ||||
void | void | ||||
sysputuint64(WINDOW *wnd, int row, int col, int width, uint64_t val, int flags) | sysputuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags) | ||||
{ | { | ||||
char unit, *ptr, *start, wrtbuf[width + width + 1]; | char unit, *ptr, *start, wrtbuf[width + width + 1]; | ||||
int len; | int len; | ||||
unit = 0; | unit = 0; | ||||
start = wrtbuf; | start = wrtbuf; | ||||
flags |= HN_NOSPACE; | flags |= HN_NOSPACE; | ||||
if (val > INT64_MAX) | if (val > INT64_MAX) | ||||
goto error; | goto error; | ||||
else | else | ||||
len = humanize_number(&wrtbuf[width], width + 1, val, "", | len = humanize_number(&wrtbuf[width], width + 1, val, "", | ||||
HN_AUTOSCALE, flags); | HN_AUTOSCALE, flags); | ||||
if (len < 0) | if (len < 0) | ||||
goto error; | goto error; | ||||
else if (len < width) | else if (len < width) | ||||
memset(wrtbuf + len, ' ', width - len); | memset(wrtbuf + len, ' ', width - len); | ||||
start += len; | start += len; | ||||
mvwaddstr(wnd, row, col, start); | mvwaddstr(wd, row, col, start); | ||||
return; | return; | ||||
error: | error: | ||||
sysputstrs(wnd, row, col, width); | sysputstrs(wd, row, col, width); | ||||
} | |||||
void | |||||
sysputwuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags) | |||||
{ | |||||
if(val == 0) | |||||
sysputspaces(wd, row, col, width); | |||||
else | |||||
sysputuint64(wd, row, col, width, val, flags); | |||||
} | |||||
static int | |||||
calc_page_shift() | |||||
{ | |||||
u_int page_size; | |||||
int shifts; | |||||
shifts = 0; | |||||
GETSYSCTL("vm.stats.vm.v_page_size", page_size); | |||||
for(; page_size > 1; page_size >>= 1) | |||||
shifts++; | |||||
return shifts; | |||||
} | |||||
void | |||||
sysputpage(WINDOW *wd, int row, int col, int width, uint64_t pages, int flags) | |||||
{ | |||||
static int shifts = 0; | |||||
if (shifts == 0) | |||||
shifts = calc_page_shift(); | |||||
pages <<= shifts; | |||||
sysputuint64(wd, row, col, width, pages, flags); | |||||
} | } |