slabtop: Check for bad d and o option combination
If you run slabtop with the -d option and then -o option the delay gets set to zero and it runs forever. slabtop now checks for this combination and errors. Adding a DEJAGNU test also found that none of the slabtop checks were running so they got added to the list and only the ones that need /proc/slabinfo (if not readable) are skipped. References: #160
This commit is contained in:
parent
15c8b8e2cf
commit
2e1e8fcc85
1
NEWS
1
NEWS
@ -3,6 +3,7 @@ procps-ng-NEXT
|
||||
* Rename pwait to pidwait
|
||||
* library: renamed to libproc-2 and reset to 0:0:0
|
||||
* ps: Add OOM and OOMADJ fields issue #198
|
||||
* slabtop: Don't combine d and o options issue #160
|
||||
|
||||
procps-ng-3.3.17
|
||||
---------------
|
||||
|
@ -2,7 +2,7 @@
|
||||
.\"
|
||||
.\" Copyright (C) 2003 Chris Rivera
|
||||
.\" Licensed under the terms of the GNU Library General Public License, v2
|
||||
.TH SLABTOP "1" "June 2011" "procps-ng" "User Commands"
|
||||
.TH SLABTOP "1" "2021-03-11" "procps-ng" "User Commands"
|
||||
.SH NAME
|
||||
slabtop \- display kernel slab cache information in real time
|
||||
.SH SYNOPSIS
|
||||
@ -25,7 +25,8 @@ Refresh the display every
|
||||
in seconds. By default,
|
||||
.B slabtop
|
||||
refreshes the display every three seconds. To exit the program, hit
|
||||
.BR q.
|
||||
.BR q .
|
||||
This cannot be combined with the \fB-o\fR option.
|
||||
.TP
|
||||
\fB\-s\fR, \fB\-\-sort\fR=\fIS\fR
|
||||
Sort by \fIS\fR, where \fIS\fR is one of the sort criteria.
|
||||
|
10
slabtop.c
10
slabtop.c
@ -48,10 +48,11 @@
|
||||
#define DEFAULT_SORT SLAB_NUM_OBJS
|
||||
#define CHAINS_ALLOC 150
|
||||
#define MAXTBL(t) (int)( sizeof(t) / sizeof(t[0]) )
|
||||
#define DEFAULT_DELAY 3
|
||||
|
||||
static unsigned short Cols, Rows;
|
||||
static struct termios Saved_tty;
|
||||
static long Delay = 3;
|
||||
static long Delay = 0;
|
||||
static int Run_once = 0;
|
||||
|
||||
static struct slabinfo_info *Slab_info;
|
||||
@ -181,6 +182,8 @@ static void parse_opts (int argc, char **argv)
|
||||
while ((o = getopt_long(argc, argv, "d:s:ohV", longopts, NULL)) != -1) {
|
||||
switch (o) {
|
||||
case 'd':
|
||||
if (Run_once)
|
||||
xerrx(EXIT_FAILURE, _("Cannot combine -d and -o options"));
|
||||
errno = 0;
|
||||
Delay = strtol_or_err(optarg, _("illegal delay"));
|
||||
if (Delay < 1)
|
||||
@ -190,8 +193,9 @@ static void parse_opts (int argc, char **argv)
|
||||
set_sort_stuff(optarg[0]);
|
||||
break;
|
||||
case 'o':
|
||||
if (Delay != 0)
|
||||
xerrx(EXIT_FAILURE, _("Cannot combine -d and -o options"));
|
||||
Run_once=1;
|
||||
Delay = 0;
|
||||
break;
|
||||
case 'V':
|
||||
printf(PROCPS_NG_VERSION);
|
||||
@ -204,6 +208,8 @@ static void parse_opts (int argc, char **argv)
|
||||
}
|
||||
if (optind != argc)
|
||||
usage(stderr);
|
||||
if (!Run_once && Delay == 0)
|
||||
Delay = DEFAULT_DELAY;
|
||||
}
|
||||
|
||||
static void print_summary (void)
|
||||
|
@ -31,6 +31,7 @@ DEJATOOL += \
|
||||
pkill \
|
||||
ps \
|
||||
pwdx \
|
||||
slabtop \
|
||||
uptime \
|
||||
vmstat \
|
||||
w
|
||||
@ -51,6 +52,7 @@ EXTRA_DIST = \
|
||||
ps.test/ps_personality.exp \
|
||||
ps.test/ps_sched_batch.exp \
|
||||
pwdx.test/pwdx.exp \
|
||||
slabtop.test/slabtop.exp \
|
||||
uptime.test/uptime.exp \
|
||||
vmstat.test/vmstat.exp \
|
||||
w.test/w.exp
|
||||
|
@ -7,15 +7,20 @@ set avst "Active / Total"
|
||||
set used "\\\(% used\\\)\\s+:"
|
||||
set pct "\\\(\\d+\\.\\d+%\\\)"
|
||||
|
||||
if { [ file readable "/proc/slabinfo" ] == 0 } {
|
||||
unsupported "slabtop tests disabled as /proc/slabinfo is unreadable"
|
||||
} else {
|
||||
set slabtop_header "^ $avst Objects $used \\d+ / \\d+ ${pct}\\s+$avst Slabs $used \\d+ / \\d+ ${pct}\\s+$avst Caches $used \\d+ / \\d+ ${pct}\\s+$avst Size $used \\d+\\.\\d+K / \\d+\\.\\d+K ${pct}\\s+Minimum / Average / Maximum Object : \\d+\\.\\d+K / \\d+\\.\\d+K / \\d+\\.\\d+K\\s+OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME\\s+"
|
||||
|
||||
set test "slabtop help"
|
||||
spawn $slabtop --help
|
||||
expect_pass $test "^\\s+Usage:\\s+\(lt-\)\?slabtop \\\[options\\\]"
|
||||
|
||||
set test "slabtop o then d options"
|
||||
spawn $slabtop -o -d 10
|
||||
expect_pass $test "Cannot combine -d and -o options"
|
||||
|
||||
set test "slabtop d then o options"
|
||||
spawn $slabtop -d 10 -o
|
||||
expect_pass $test "Cannot combine -d and -o options"
|
||||
|
||||
set sort_tests {
|
||||
"a" "active objects" "^\\s*\\d+\\s+(\\d+)\\s+\\d+%\\s+\\d+\\.\\d+K\\s+\\d+\\s+\\d+\\s+\\d+K\\s+\\S\[^\r\]+\\s*"
|
||||
"b" "objects per slab" "^\\s*\\d+\\s+\\d+\\s+\\d+%\\s+\\d+\\.\\d+K\\s+\\d+\\s+(\\d+)\\s+\\d+K\\s+\\S\[^\r\]+\\s*"
|
||||
@ -25,9 +30,16 @@ set sort_tests {
|
||||
"s" "object size" "^\\s*\\d+\\s+\\d+\\s+\\d+%\\s+(\\d+\\.\\d+)K\\s+\\d+\\s+\\d+\\s+\\d+K\\s+\\S\[^\r\]+\\s*"
|
||||
"u" "utilisation" "^\\s*\\d+\\s+\\d+\\s+(\\d+)%\\s+\\d+\\.\\d+K\\s+\\d+\\s+\\d+\\s+\\d+K\\s+\\S\[^\r\]+\\s*"
|
||||
}
|
||||
|
||||
# BEGIN - Tests requiring /proc/slabinfo
|
||||
if { [ file readable "/proc/slabinfo" ] == 0 } {
|
||||
unsupported "slabtop tests disabled as /proc/slabinfo is unreadable"
|
||||
} else {
|
||||
|
||||
foreach { flag desc match } $sort_tests {
|
||||
set test "slabtop sorted by $desc"
|
||||
spawn $slabtop -o -s $flag
|
||||
expect_table_dsc $test $slabtop_header $match
|
||||
}
|
||||
}
|
||||
# END - Tests requiring /proc/slabinfo
|
||||
|
Loading…
Reference in New Issue
Block a user