svn commit: r362469 - stable/12/usr.bin/top
Piotr Pawel Stefaniak
pstef at FreeBSD.org
Sun Jun 21 20:23:40 UTC 2020
Author: pstef
Date: Sun Jun 21 20:23:39 2020
New Revision: 362469
URL: https://svnweb.freebsd.org/changeset/base/362469
Log:
MFC r349235 (by allanjude):
top(1): Don't show the swap line when there are no swap devices
Modified:
stable/12/usr.bin/top/display.c
stable/12/usr.bin/top/machine.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/usr.bin/top/display.c
==============================================================================
--- stable/12/usr.bin/top/display.c Sun Jun 21 18:40:17 2020 (r362468)
+++ stable/12/usr.bin/top/display.c Sun Jun 21 20:23:39 2020 (r362469)
@@ -675,6 +675,9 @@ i_swap(int *stats)
{
swap_buffer = setup_buffer(swap_buffer, 0);
+ if (swap_names == NULL)
+ return;
+
fputs("\nSwap: ", stdout);
lastline++;
@@ -689,6 +692,9 @@ u_swap(int *stats)
static char *new = NULL;
new = setup_buffer(new, 0);
+
+ if (swap_names == NULL)
+ return;
/* format the new line */
summary_format(new, stats, swap_names);
Modified: stable/12/usr.bin/top/machine.c
==============================================================================
--- stable/12/usr.bin/top/machine.c Sun Jun 21 18:40:17 2020 (r362468)
+++ stable/12/usr.bin/top/machine.c Sun Jun 21 20:23:39 2020 (r362469)
@@ -150,6 +150,7 @@ static const char *swapnames[] = {
};
static int swap_stats[nitems(swapnames)];
+static int has_swap;
/* these are for keeping track of the proc array */
@@ -248,12 +249,12 @@ update_layout(void)
y_mem = 3;
y_arc = 4;
y_carc = 5;
- y_swap = 4 + arc_enabled + carc_enabled;
- y_idlecursor = 5 + arc_enabled + carc_enabled;
- y_message = 5 + arc_enabled + carc_enabled;
- y_header = 6 + arc_enabled + carc_enabled;
- y_procs = 7 + arc_enabled + carc_enabled;
- Header_lines = 7 + arc_enabled + carc_enabled;
+ y_swap = 3 + arc_enabled + carc_enabled + has_swap;
+ y_idlecursor = 4 + arc_enabled + carc_enabled + has_swap;
+ y_message = 4 + arc_enabled + carc_enabled + has_swap;
+ y_header = 5 + arc_enabled + carc_enabled + has_swap;
+ y_procs = 6 + arc_enabled + carc_enabled + has_swap;
+ Header_lines = 6 + arc_enabled + carc_enabled + has_swap;
if (pcpu_stats) {
y_mem += ncpus - 1;
@@ -273,7 +274,7 @@ machine_init(struct statics *statics)
{
int i, j, empty, pagesize;
uint64_t arc_size;
- int carc_en;
+ int carc_en, nswapdev;
size_t size;
size = sizeof(smpmode);
@@ -298,6 +299,11 @@ machine_init(struct statics *statics)
if (kd == NULL)
return (-1);
+ size = sizeof(nswapdev);
+ if (sysctlbyname("vm.nswapdev", &nswapdev, &size, NULL,
+ 0) == 0 && nswapdev != 0)
+ has_swap = 1;
+
GETSYSCTL("kern.ccpu", ccpu);
/* this is used in calculating WCPU -- calculate it ahead of time */
@@ -332,7 +338,10 @@ machine_init(struct statics *statics)
statics->carc_names = carcnames;
else
statics->carc_names = NULL;
- statics->swap_names = swapnames;
+ if (has_swap)
+ statics->swap_names = swapnames;
+ else
+ statics->swap_names = NULL;
statics->order_names = ordernames;
/* Allocate state for per-CPU stats. */
More information about the svn-src-all
mailing list