diff options
| author | Allan Jude <allanjude@FreeBSD.org> | 2019-06-20 15:44:43 +0000 |
|---|---|---|
| committer | Allan Jude <allanjude@FreeBSD.org> | 2019-06-20 15:44:43 +0000 |
| commit | 2984a7167717c4ea4d96ef9349e6e6a81600ea53 (patch) | |
| tree | a89885219e7ad48df18c2db720384ce59b855499 /usr.bin | |
| parent | 8bd416a216a817cafd1af55e3d7694de327b05a5 (diff) | |
Notes
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/top/display.c | 6 | ||||
| -rw-r--r-- | usr.bin/top/machine.c | 25 |
2 files changed, 23 insertions, 8 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 539ddb4d536e2..00534fd7f4115 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -675,6 +675,9 @@ i_swap(int *stats) { swap_buffer = setup_buffer(swap_buffer, 0); + if (swap_names == NULL) + return; + fputs("\nSwap: ", stdout); lastline++; @@ -690,6 +693,9 @@ u_swap(int *stats) new = setup_buffer(new, 0); + if (swap_names == NULL) + return; + /* format the new line */ summary_format(new, stats, swap_names); line_update(swap_buffer, new, x_swap, y_swap); diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 563efc624e244..dd2b7a110419f 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -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. */ |
