misc: adapted other pgms to changes in, <SLABINFO> api

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-06-05 00:00:00 -05:00 committed by Craig Small
parent 5d5a52a380
commit 8a7fcc02d1
2 changed files with 40 additions and 49 deletions

View File

@ -46,6 +46,7 @@
#define DEFAULT_SORT PROCPS_SLABNODE_OBJS #define DEFAULT_SORT PROCPS_SLABNODE_OBJS
#define CHAINS_ALLOC 150 #define CHAINS_ALLOC 150
#define MAXTBL(t) (int)( sizeof(t) / sizeof(t[0]) )
static unsigned short Cols, Rows; static unsigned short Cols, Rows;
static struct termios Saved_tty; static struct termios Saved_tty;
@ -54,16 +55,15 @@ static int Run_once = 0;
static struct procps_slabinfo *Slab_info; static struct procps_slabinfo *Slab_info;
enum slabnode_item Sort_item = DEFAULT_SORT; enum slabinfo_item Sort_item = DEFAULT_SORT;
enum slabnode_item Node_items[] = { enum slabinfo_item Node_items[] = {
PROCPS_SLABNODE_OBJS, PROCPS_SLABNODE_AOBJS, PROCPS_SLABNODE_USE, PROCPS_SLABNODE_OBJS, PROCPS_SLABNODE_AOBJS, PROCPS_SLABNODE_USE,
PROCPS_SLABNODE_OBJ_SIZE, PROCPS_SLABNODE_SLABS, PROCPS_SLABNODE_OBJS_PER_SLAB, PROCPS_SLABNODE_OBJ_SIZE, PROCPS_SLABNODE_SLABS, PROCPS_SLABNODE_OBJS_PER_SLAB,
PROCPS_SLABNODE_SIZE, PROCPS_SLABNODE_NAME, PROCPS_SLABNODE_SIZE, PROCPS_SLABNODE_NAME,
/* next 2 are sortable but are not displayable, /* next 2 are sortable but are not displayable,
thus they need not be represented in the Relative_enums */ thus they need not be represented in the Relative_enums */
PROCPS_SLABNODE_PAGES_PER_SLAB, PROCPS_SLABNODE_ASLABS, PROCPS_SLABNODE_PAGES_PER_SLAB, PROCPS_SLABNODE_ASLABS };
PROCPS_SLABNODE_stack_end };
enum Relative_enums { enum Relative_enums {
my_OBJS, my_AOBJS, my_USE, my_OSIZE, my_OBJS, my_AOBJS, my_USE, my_OSIZE,
@ -127,7 +127,7 @@ static void __attribute__((__noreturn__)) usage (FILE *out)
* set_sort_func - return the slab_sort_func that matches the given key. * set_sort_func - return the slab_sort_func that matches the given key.
* On unrecognizable key, DEFAULT_SORT is returned. * On unrecognizable key, DEFAULT_SORT is returned.
*/ */
static enum slabnode_item set_sort_item ( static enum slabinfo_item set_sort_item (
const char key) const char key)
{ {
switch (tolower(key)) { switch (tolower(key)) {
@ -195,28 +195,27 @@ static void parse_opts (int argc, char **argv)
static void print_summary (void) static void print_summary (void)
{ {
enum slabinfo_item items[] = {
PROCPS_SLABS_AOBJS, PROCPS_SLABS_OBJS,
PROCPS_SLABS_ASLABS, PROCPS_SLABS_SLABS,
PROCPS_SLABS_ACACHES, PROCPS_SLABS_CACHES,
PROCPS_SLABS_SIZE_ACTIVE, PROCPS_SLABS_SIZE_TOTAL,
PROCPS_SLABS_SIZE_MIN, PROCPS_SLABS_SIZE_AVG,
PROCPS_SLABS_SIZE_MAX
};
enum slabs_enums { enum slabs_enums {
stat_AOBJS, stat_OBJS, stat_ASLABS, stat_SLABS, stat_AOBJS, stat_OBJS, stat_ASLABS, stat_SLABS,
stat_ACACHES, stat_CACHES, stat_ACTIVE, stat_TOTAL, stat_ACACHES, stat_CACHES, stat_ACTIVE, stat_TOTAL,
stat_MIN, stat_AVG, stat_MAX stat_MIN, stat_AVG, stat_MAX
}; };
static struct slab_result stats[] = { struct slabinfo_stack *p;
{ PROCPS_SLABS_AOBJS, 0 }, struct slabinfo_result *stats;
{ PROCPS_SLABS_OBJS, 0 },
{ PROCPS_SLABS_ASLABS, 0 },
{ PROCPS_SLABS_SLABS, 0 },
{ PROCPS_SLABS_ACACHES, 0 },
{ PROCPS_SLABS_CACHES, 0 },
{ PROCPS_SLABS_SIZE_ACTIVE, 0 },
{ PROCPS_SLABS_SIZE_TOTAL, 0 },
{ PROCPS_SLABS_SIZE_MIN, 0 },
{ PROCPS_SLABS_SIZE_AVG, 0 },
{ PROCPS_SLABS_SIZE_MAX, 0 },
{ PROCPS_SLABS_stack_end, 0 }
};
if (procps_slabs_getstack(Slab_info, stats) < 0) \ if (!(p = procps_slabinfo_select(Slab_info, items, MAXTBL(items))))
xerrx(EXIT_FAILURE, _("Error getting slab summary results")); xerrx(EXIT_FAILURE, _("Error getting slab summary results"));
/* we really should use the provided PROCPS_SLABINFO_VAL macro but,
let's do this instead to salvage as much original code as possible ... */
stats = p->head;
PRINT_line(" %-35s: %u / %u (%.1f%%)\n" PRINT_line(" %-35s: %u / %u (%.1f%%)\n"
, /* Translation Hint: Next five strings must not , /* Translation Hint: Next five strings must not
@ -258,7 +257,7 @@ static void print_headings (void)
PRINT_line("%-78s\n", _(" OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME")); PRINT_line("%-78s\n", _(" OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME"));
} }
static void print_details (struct slabnode_stack *stack) static void print_details (struct slabinfo_stack *stack)
{ {
PRINT_line("%6u %6u %3u%% %7.2fK %6u %8u %9luK %-23s\n" PRINT_line("%6u %6u %3u%% %7.2fK %6u %8u %9luK %-23s\n"
, stack->head[my_OBJS ].result.u_int , stack->head[my_OBJS ].result.u_int
@ -276,9 +275,8 @@ static void print_details (struct slabnode_stack *stack)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int is_tty, nr_slabs, rc = EXIT_SUCCESS; int is_tty, rc = EXIT_SUCCESS;
unsigned short old_rows; unsigned short old_rows;
struct slabnode_stack **v;
#ifdef HAVE_PROGRAM_INVOCATION_NAME #ifdef HAVE_PROGRAM_INVOCATION_NAME
program_invocation_name = program_invocation_short_name; program_invocation_name = program_invocation_short_name;
@ -291,10 +289,7 @@ int main(int argc, char *argv[])
parse_opts(argc, argv); parse_opts(argc, argv);
if (procps_slabinfo_new(&Slab_info) < 0) if (procps_slabinfo_new(&Slab_info) < 0)
xerrx(EXIT_FAILURE, _("Unable to create slabinfo structure")); xerr(EXIT_FAILURE, _("Unable to create slabinfo structure"));
if (!(v = procps_slabnode_stacks_alloc(Slab_info, CHAINS_ALLOC, MAX_ITEMS, Node_items)))
xerrx(EXIT_FAILURE, _("Unable to allocate slabinfo nodes"));
if (!Run_once) { if (!Run_once) {
is_tty = isatty(STDIN_FILENO); is_tty = isatty(STDIN_FILENO);
@ -309,17 +304,18 @@ int main(int argc, char *argv[])
} }
do { do {
struct slabinfo_reap *reaped;
struct timeval tv; struct timeval tv;
fd_set readfds; fd_set readfds;
int i; int i;
// this next guy also performs the procps_slabnode_read() call if (!(reaped = procps_slabinfo_reap(Slab_info, Node_items, MAXTBL(Node_items)))) {
if ((nr_slabs = procps_slabnode_stacks_fill(Slab_info, v, CHAINS_ALLOC)) < 0) {
xwarn(_("Unable to get slabinfo node data")); xwarn(_("Unable to get slabinfo node data"));
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
break; break;
} }
if (!(v = procps_slabnode_stacks_sort(Slab_info, v, nr_slabs, Sort_item))) {
if (!(procps_slabinfo_sort(Slab_info, reaped->stacks, reaped->total, Sort_item, PROCPS_SLABINFO_DESCEND))) {
xwarn(_("Unable to sort slab nodes")); xwarn(_("Unable to sort slab nodes"));
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
break; break;
@ -328,8 +324,8 @@ int main(int argc, char *argv[])
if (Run_once) { if (Run_once) {
print_summary(); print_summary();
print_headings(); print_headings();
for (i = 0; i < nr_slabs; i++) for (i = 0; i < reaped->total; i++)
print_details(v[i]); print_details(reaped->stacks[i]);
break; break;
} }
@ -343,8 +339,8 @@ int main(int argc, char *argv[])
print_headings(); print_headings();
attroff(A_REVERSE); attroff(A_REVERSE);
for (i = 0; i < Rows - 8 && i < nr_slabs; i++) for (i = 0; i < Rows - 8 && i < reaped->total; i++)
print_details(v[i]); print_details(reaped->stacks[i]);
refresh(); refresh();
FD_ZERO(&readfds); FD_ZERO(&readfds);

View File

@ -650,35 +650,31 @@ static void slabheader(void)
static void slabformat (void) static void slabformat (void)
{ {
#define CHAINS_ALLOC 150
#define MAX_ITEMS (int)(sizeof(node_items) / sizeof(node_items[0])) #define MAX_ITEMS (int)(sizeof(node_items) / sizeof(node_items[0]))
struct procps_slabinfo *slab_info; struct procps_slabinfo *slab_info;
struct slabnode_stack **v, *p; struct slabinfo_reap *reaped;
int i, j, nr_slabs; int i, j;
enum slabnode_item node_items[] = { enum slabinfo_item node_items[] = {
PROCPS_SLABNODE_AOBJS, PROCPS_SLABNODE_OBJS, PROCPS_SLABNODE_AOBJS, PROCPS_SLABNODE_OBJS,
PROCPS_SLABNODE_OBJ_SIZE, PROCPS_SLABNODE_OBJS_PER_SLAB, PROCPS_SLABNODE_OBJ_SIZE, PROCPS_SLABNODE_OBJS_PER_SLAB,
PROCPS_SLABNODE_NAME, PROCPS_SLABNODE_stack_end }; PROCPS_SLABNODE_NAME };
enum rel_enums { enum rel_enums {
slab_AOBJS, slab_OBJS, slab_OSIZE, slab_OPS, slab_NAME }; slab_AOBJS, slab_OBJS, slab_OSIZE, slab_OPS, slab_NAME };
if (procps_slabinfo_new(&slab_info) < 0) if (procps_slabinfo_new(&slab_info) < 0)
xerrx(EXIT_FAILURE, _("Unable to create slabinfo structure")); xerr(EXIT_FAILURE, _("Unable to create slabinfo structure"));
if (!(v = procps_slabnode_stacks_alloc(slab_info, CHAINS_ALLOC, MAX_ITEMS, node_items)))
xerrx(EXIT_FAILURE, _("Unable to allocate slabinfo nodes"));
if (!moreheaders) if (!moreheaders)
slabheader(); slabheader();
for (i = 0; infinite_updates || i < num_updates; i++) { for (i = 0; infinite_updates || i < num_updates; i++) {
// this next guy also performs the procps_slabnode_read() call if (!(reaped = procps_slabinfo_reap(slab_info, node_items, MAX_ITEMS)))
if ((nr_slabs = procps_slabnode_stacks_fill(slab_info, v, CHAINS_ALLOC)) < 0) xerrx(EXIT_FAILURE, _("Unable to get slabinfo node data"));
xerrx(EXIT_FAILURE, _("Unable to get slabinfo node data, requires root permission")); if (!(procps_slabinfo_sort(slab_info, reaped->stacks, reaped->total, PROCPS_SLABNODE_NAME, PROCPS_SLABINFO_ASCEND)))
if (!(v = procps_slabnode_stacks_sort(slab_info, v, nr_slabs, PROCPS_SLABNODE_NAME)))
xerrx(EXIT_FAILURE, _("Unable to sort slab nodes")); xerrx(EXIT_FAILURE, _("Unable to sort slab nodes"));
for (j = 0; j < nr_slabs; j++) { for (j = 0; j < reaped->total; j++) {
p = v[j]; struct slabinfo_stack *p = reaped->stacks[j];
if (moreheaders && ((j % height) == 0)) if (moreheaders && ((j % height) == 0))
slabheader(); slabheader();
printf("%-24.24s %6u %6u %6u %6u\n", printf("%-24.24s %6u %6u %6u %6u\n",
@ -692,7 +688,6 @@ static void slabformat (void)
sleep(sleep_time); sleep(sleep_time);
} }
procps_slabinfo_unref(&slab_info); procps_slabinfo_unref(&slab_info);
#undef CHAINS_ALLOC
#undef MAX_ITEMS #undef MAX_ITEMS
} }