slabtop: correct the sort behavior for that NAME field
When our <SLABINFO> was recently re-designed, the sort callback functions became table driven, whereas before a single callback used switch/case constructs based on an 'item'. Thus, sorting was made a tad more efficient but, it introduced a buglet into that slabtop program. The root cause of this bug was the fact that the field NAME required a low-to-high sort and all other slabtop fields used high-to-low. Fortunately, along with those <SLABINFO> table driven sort changes, that i/f offered users the option of either low-to-high or high-to-low. So this patch just exploits that choice. And, it means that such responsibilities are now properly located in calling code, not in what's a general purpose library. Reference(s): . most recent lib sort enhancement & breakage commit 5d5a52a3804f912f7be8c15f18bf87fe45bbcd99 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
b09014a7b6
commit
e80b48ce58
50
slabtop.c
50
slabtop.c
@ -56,6 +56,7 @@ static int Run_once = 0;
|
|||||||
static struct procps_slabinfo *Slab_info;
|
static struct procps_slabinfo *Slab_info;
|
||||||
|
|
||||||
enum slabinfo_item Sort_item = DEFAULT_SORT;
|
enum slabinfo_item Sort_item = DEFAULT_SORT;
|
||||||
|
enum slabinfo_sort_order Sort_Order = PROCPS_SLABINFO_DESCEND;
|
||||||
|
|
||||||
enum slabinfo_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,
|
||||||
@ -123,36 +124,45 @@ static void __attribute__((__noreturn__)) usage (FILE *out)
|
|||||||
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void set_sort_stuff (const char key)
|
||||||
* set_sort_func - return the slab_sort_func that matches the given key.
|
|
||||||
* On unrecognizable key, DEFAULT_SORT is returned.
|
|
||||||
*/
|
|
||||||
static enum slabinfo_item set_sort_item (
|
|
||||||
const char key)
|
|
||||||
{
|
{
|
||||||
|
Sort_item = DEFAULT_SORT;
|
||||||
|
Sort_Order = PROCPS_SLABINFO_DESCEND;
|
||||||
|
|
||||||
switch (tolower(key)) {
|
switch (tolower(key)) {
|
||||||
case 'n':
|
case 'n':
|
||||||
return PROCPS_SLABNODE_NAME;
|
Sort_item = PROCPS_SLABNODE_NAME;
|
||||||
|
Sort_Order = PROCPS_SLABINFO_ASCEND;
|
||||||
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
return PROCPS_SLABNODE_OBJS;
|
Sort_item = PROCPS_SLABNODE_OBJS;
|
||||||
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
return PROCPS_SLABNODE_AOBJS;
|
Sort_item = PROCPS_SLABNODE_AOBJS;
|
||||||
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
return PROCPS_SLABNODE_OBJ_SIZE;
|
Sort_item = PROCPS_SLABNODE_OBJ_SIZE;
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
return PROCPS_SLABNODE_OBJS_PER_SLAB;
|
Sort_item = PROCPS_SLABNODE_OBJS_PER_SLAB;
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
return PROCPS_SLABNODE_PAGES_PER_SLAB;
|
Sort_item = PROCPS_SLABNODE_PAGES_PER_SLAB;
|
||||||
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
return PROCPS_SLABNODE_SLABS;
|
Sort_item = PROCPS_SLABNODE_SLABS;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
return PROCPS_SLABNODE_ASLABS;
|
Sort_item = PROCPS_SLABNODE_ASLABS;
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
return PROCPS_SLABNODE_SIZE;
|
Sort_item = PROCPS_SLABNODE_SIZE;
|
||||||
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
return PROCPS_SLABNODE_USE;
|
Sort_item = PROCPS_SLABNODE_USE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return DEFAULT_SORT;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +186,7 @@ static void parse_opts (int argc, char **argv)
|
|||||||
xerrx(EXIT_FAILURE, _("delay must be positive integer"));
|
xerrx(EXIT_FAILURE, _("delay must be positive integer"));
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
Sort_item = set_sort_item(optarg[0]);
|
set_sort_stuff(optarg[0]);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
Run_once=1;
|
Run_once=1;
|
||||||
@ -315,7 +325,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(procps_slabinfo_sort(Slab_info, reaped->stacks, reaped->total, Sort_item, PROCPS_SLABINFO_DESCEND))) {
|
if (!(procps_slabinfo_sort(Slab_info, reaped->stacks, reaped->total, Sort_item, Sort_Order))) {
|
||||||
xwarn(_("Unable to sort slab nodes"));
|
xwarn(_("Unable to sort slab nodes"));
|
||||||
rc = EXIT_FAILURE;
|
rc = EXIT_FAILURE;
|
||||||
break;
|
break;
|
||||||
@ -352,7 +362,7 @@ int main(int argc, char *argv[])
|
|||||||
if (read(STDIN_FILENO, &c, 1) != 1
|
if (read(STDIN_FILENO, &c, 1) != 1
|
||||||
|| (c == 'Q' || c == 'q'))
|
|| (c == 'Q' || c == 'q'))
|
||||||
break;
|
break;
|
||||||
Sort_item = set_sort_item(c);
|
set_sort_stuff(c);
|
||||||
}
|
}
|
||||||
// made zero by sigint_handler()
|
// made zero by sigint_handler()
|
||||||
} while (Delay);
|
} while (Delay);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user