Author: allanjude Date: Thu Jun 20 15:44:43 2019 New Revision: 349235 URL: https://svnweb.freebsd.org/changeset/base/349235
Log: top(1): Don't show the swap line when there are no swap devices Submitted by: antran...@freebsd.am Reviewed by: bapt MFC after: 1 month Sponsored by: Klara Systems Differential Revision: https://reviews.freebsd.org/D18928 Modified: head/usr.bin/top/display.c head/usr.bin/top/machine.c Modified: head/usr.bin/top/display.c ============================================================================== --- head/usr.bin/top/display.c Thu Jun 20 14:40:36 2019 (r349234) +++ head/usr.bin/top/display.c Thu Jun 20 15:44:43 2019 (r349235) @@ -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: head/usr.bin/top/machine.c ============================================================================== --- head/usr.bin/top/machine.c Thu Jun 20 14:40:36 2019 (r349234) +++ head/usr.bin/top/machine.c Thu Jun 20 15:44:43 2019 (r349235) @@ -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. */ _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"