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
|
* Rename pwait to pidwait
|
||||||
* library: renamed to libproc-2 and reset to 0:0:0
|
* library: renamed to libproc-2 and reset to 0:0:0
|
||||||
* ps: Add OOM and OOMADJ fields issue #198
|
* ps: Add OOM and OOMADJ fields issue #198
|
||||||
|
* slabtop: Don't combine d and o options issue #160
|
||||||
|
|
||||||
procps-ng-3.3.17
|
procps-ng-3.3.17
|
||||||
---------------
|
---------------
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" Copyright (C) 2003 Chris Rivera
|
.\" Copyright (C) 2003 Chris Rivera
|
||||||
.\" Licensed under the terms of the GNU Library General Public License, v2
|
.\" 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
|
.SH NAME
|
||||||
slabtop \- display kernel slab cache information in real time
|
slabtop \- display kernel slab cache information in real time
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@ -25,7 +25,8 @@ Refresh the display every
|
|||||||
in seconds. By default,
|
in seconds. By default,
|
||||||
.B slabtop
|
.B slabtop
|
||||||
refreshes the display every three seconds. To exit the program, hit
|
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
|
.TP
|
||||||
\fB\-s\fR, \fB\-\-sort\fR=\fIS\fR
|
\fB\-s\fR, \fB\-\-sort\fR=\fIS\fR
|
||||||
Sort by \fIS\fR, where \fIS\fR is one of the sort criteria.
|
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 DEFAULT_SORT SLAB_NUM_OBJS
|
||||||
#define CHAINS_ALLOC 150
|
#define CHAINS_ALLOC 150
|
||||||
#define MAXTBL(t) (int)( sizeof(t) / sizeof(t[0]) )
|
#define MAXTBL(t) (int)( sizeof(t) / sizeof(t[0]) )
|
||||||
|
#define DEFAULT_DELAY 3
|
||||||
|
|
||||||
static unsigned short Cols, Rows;
|
static unsigned short Cols, Rows;
|
||||||
static struct termios Saved_tty;
|
static struct termios Saved_tty;
|
||||||
static long Delay = 3;
|
static long Delay = 0;
|
||||||
static int Run_once = 0;
|
static int Run_once = 0;
|
||||||
|
|
||||||
static struct slabinfo_info *Slab_info;
|
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) {
|
while ((o = getopt_long(argc, argv, "d:s:ohV", longopts, NULL)) != -1) {
|
||||||
switch (o) {
|
switch (o) {
|
||||||
case 'd':
|
case 'd':
|
||||||
|
if (Run_once)
|
||||||
|
xerrx(EXIT_FAILURE, _("Cannot combine -d and -o options"));
|
||||||
errno = 0;
|
errno = 0;
|
||||||
Delay = strtol_or_err(optarg, _("illegal delay"));
|
Delay = strtol_or_err(optarg, _("illegal delay"));
|
||||||
if (Delay < 1)
|
if (Delay < 1)
|
||||||
@ -190,8 +193,9 @@ static void parse_opts (int argc, char **argv)
|
|||||||
set_sort_stuff(optarg[0]);
|
set_sort_stuff(optarg[0]);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
|
if (Delay != 0)
|
||||||
|
xerrx(EXIT_FAILURE, _("Cannot combine -d and -o options"));
|
||||||
Run_once=1;
|
Run_once=1;
|
||||||
Delay = 0;
|
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
printf(PROCPS_NG_VERSION);
|
printf(PROCPS_NG_VERSION);
|
||||||
@ -204,6 +208,8 @@ static void parse_opts (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
if (optind != argc)
|
if (optind != argc)
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
|
if (!Run_once && Delay == 0)
|
||||||
|
Delay = DEFAULT_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_summary (void)
|
static void print_summary (void)
|
||||||
|
@ -31,6 +31,7 @@ DEJATOOL += \
|
|||||||
pkill \
|
pkill \
|
||||||
ps \
|
ps \
|
||||||
pwdx \
|
pwdx \
|
||||||
|
slabtop \
|
||||||
uptime \
|
uptime \
|
||||||
vmstat \
|
vmstat \
|
||||||
w
|
w
|
||||||
@ -51,6 +52,7 @@ EXTRA_DIST = \
|
|||||||
ps.test/ps_personality.exp \
|
ps.test/ps_personality.exp \
|
||||||
ps.test/ps_sched_batch.exp \
|
ps.test/ps_sched_batch.exp \
|
||||||
pwdx.test/pwdx.exp \
|
pwdx.test/pwdx.exp \
|
||||||
|
slabtop.test/slabtop.exp \
|
||||||
uptime.test/uptime.exp \
|
uptime.test/uptime.exp \
|
||||||
vmstat.test/vmstat.exp \
|
vmstat.test/vmstat.exp \
|
||||||
w.test/w.exp
|
w.test/w.exp
|
||||||
|
@ -7,15 +7,20 @@ set avst "Active / Total"
|
|||||||
set used "\\\(% used\\\)\\s+:"
|
set used "\\\(% used\\\)\\s+:"
|
||||||
set pct "\\\(\\d+\\.\\d+%\\\)"
|
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 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"
|
set test "slabtop help"
|
||||||
spawn $slabtop --help
|
spawn $slabtop --help
|
||||||
expect_pass $test "^\\s+Usage:\\s+\(lt-\)\?slabtop \\\[options\\\]"
|
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 {
|
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*"
|
"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*"
|
"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*"
|
"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*"
|
"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 {
|
foreach { flag desc match } $sort_tests {
|
||||||
set test "slabtop sorted by $desc"
|
set test "slabtop sorted by $desc"
|
||||||
spawn $slabtop -o -s $flag
|
spawn $slabtop -o -s $flag
|
||||||
expect_table_dsc $test $slabtop_header $match
|
expect_table_dsc $test $slabtop_header $match
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# END - Tests requiring /proc/slabinfo
|
||||||
|
Loading…
Reference in New Issue
Block a user