aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/gen/getbsize.35
-rw-r--r--usr.bin/systat/extern.h1
-rw-r--r--usr.bin/systat/swap.c116
-rw-r--r--usr.bin/systat/sysput.c21
4 files changed, 51 insertions, 92 deletions
diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3
index c0b46bf9e235..acbe409a8456 100644
--- a/lib/libc/gen/getbsize.3
+++ b/lib/libc/gen/getbsize.3
@@ -45,10 +45,9 @@ The
.Fn getbsize
function returns a preferred block size for reporting by system utilities
.Xr df 1 ,
-.Xr du 1 ,
-.Xr ls 1
+.Xr du 1
and
-.Xr systat 1 ,
+.Xr ls 1 ,
based on the value of the
.Ev BLOCKSIZE
environment variable.
diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h
index 6e3117bece4e..322065f79312 100644
--- a/usr.bin/systat/extern.h
+++ b/usr.bin/systat/extern.h
@@ -168,6 +168,7 @@ char *sysctl_dynread(const char *, size_t *);
void sysputpage(WINDOW* , int, int, int, uint64_t, int);
void sysputspaces(WINDOW* , int, int, int);
void sysputstrs(WINDOW* , int, int, int);
+void sysputXs(WINDOW* , int, int, int);
void sysputuint64(WINDOW* , int, int, int, uint64_t, int);
void sysputwuint64(WINDOW* , int, int, int, uint64_t, int);
diff --git a/usr.bin/systat/swap.c b/usr.bin/systat/swap.c
index fc44db7d7d42..29b04df0157f 100644
--- a/usr.bin/systat/swap.c
+++ b/usr.bin/systat/swap.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 1980, 1992, 1993
* The Regents of the University of California. All rights reserved.
- * Copyright (c) 2017 Yoshihiro Ota
+ * Copyright (c) 2017, 2020 Yoshihiro Ota
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -58,22 +58,19 @@ static const char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95";
#include "extern.h"
#include "devs.h"
-static char *header;
-static long blocksize;
-static int dlen, odlen;
-static int hlen;
-static int ulen, oulen;
-static int pagesize;
+static int pathlen;
WINDOW *
openswap(void)
{
- return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0));
+
+ return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0));
}
void
closeswap(WINDOW *w)
{
+
if (w == NULL)
return;
wclear(w);
@@ -92,29 +89,6 @@ closeswap(WINDOW *w)
static struct kvm_swap kvmsw[NSWAP];
static int kvnsw, okvnsw;
-static void calclens(void);
-
-#define CONVERT(v) ((int)((int64_t)(v) * pagesize / blocksize))
-
-static void
-calclens(void)
-{
- int i, n;
- int len;
-
- dlen = sizeof("Disk");
- for (i = 0; i < kvnsw; ++i) {
- len = strlen(kvmsw[i].ksw_devname);
- if (dlen < len)
- dlen = len;
- }
-
- ulen = sizeof("Used");
- for (n = CONVERT(kvmsw[kvnsw].ksw_used), len = 2; n /= 10; ++len);
- if (ulen < len)
- ulen = len;
-}
-
int
initswap(void)
{
@@ -123,22 +97,13 @@ initswap(void)
if (once)
return (1);
- header = getbsize(&hlen, &blocksize);
- pagesize = getpagesize();
-
if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
error("systat: kvm_getswapinfo failed");
return (0);
}
- okvnsw = kvnsw;
-
- calclens();
- odlen = dlen;
- oulen = ulen;
-
- once = 1;
-
+ pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */;
dsinit(12);
+ once = 1;
return (1);
}
@@ -146,16 +111,13 @@ initswap(void)
void
fetchswap(void)
{
+
okvnsw = kvnsw;
if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
error("systat: kvm_getswapinfo failed");
return;
}
- odlen = dlen;
- oulen = ulen;
- calclens();
-
struct devinfo *tmp_dinfo;
tmp_dinfo = last_dev.dinfo;
@@ -172,24 +134,23 @@ labelswap(void)
const char *name;
int i;
- fetchswap();
-
werase(wnd);
- mvwprintw(wnd, 0, 0, "%*s%*s%*s %s",
- -dlen, "Disk", hlen, header, ulen, "Used",
- "/0% /10 /20 /30 /40 /50 /60 /70 /80 /90 /100");
+ dslabel(12, 0, 18);
+
+ if (kvnsw <= 0) {
+ mvwprintw(wnd, 0, 0, "(swap not configured)");
+ return;
+ }
+
+ mvwprintw(wnd, 0, 0, "%*s%5s %5s %s",
+ -pathlen, "Device/Path", "Size", "Used",
+ "|0% /10 /20 /30 /40 / 60\\ 70\\ 80\\ 90\\ 100|");
for (i = 0; i <= kvnsw; ++i) {
- if (i == kvnsw) {
- if (kvnsw == 1)
- break;
- name = "Total";
- } else
- name = kvmsw[i].ksw_devname;
- mvwprintw(wnd, i + 1, 0, "%*s", -dlen, name);
+ name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname;
+ mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name);
}
- dslabel(12, 0, 18);
}
void
@@ -198,36 +159,23 @@ showswap(void)
int count;
int i;
- if (kvnsw != okvnsw || dlen != odlen || ulen != oulen)
+ if (kvnsw != okvnsw)
labelswap();
- for (i = 0; i <= kvnsw; ++i) {
- if (i == kvnsw) {
- if (kvnsw == 1)
- break;
- }
-
- if (kvmsw[i].ksw_total == 0) {
- mvwprintw(
- wnd,
- i + 1,
- dlen + hlen + ulen + 1,
- "(swap not configured)"
- );
- continue;
- }
-
- wmove(wnd, i + 1, dlen);
+ dsshow(12, 0, 18, &cur_dev, &last_dev);
- wprintw(wnd, "%*d", hlen, CONVERT(kvmsw[i].ksw_total));
- wprintw(wnd, "%*d", ulen, CONVERT(kvmsw[i].ksw_used));
+ if (kvnsw <= 0)
+ return;
- count = 50.0 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1;
+ for (i = 0; i <= kvnsw; ++i) {
+ sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0);
+ sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used,
+ 0);
- waddch(wnd, ' ');
- while (count--)
- waddch(wnd, 'X');
+ if (kvmsw[i].ksw_used > 0) {
+ count = 50 * kvmsw[i].ksw_used / kvmsw[i].ksw_total;
+ sysputXs(wnd, i + 1, pathlen + 5 + 1 + 5 + 1, count);
+ }
wclrtoeol(wnd);
}
- dsshow(12, 0, 18, &cur_dev, &last_dev);
}
diff --git a/usr.bin/systat/sysput.c b/usr.bin/systat/sysput.c
index 31c9127a83b7..10401cee772a 100644
--- a/usr.bin/systat/sysput.c
+++ b/usr.bin/systat/sysput.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2019 Yoshihiro Ota
+ * Copyright (c) 2019, 2020 Yoshihiro Ota
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -43,17 +43,28 @@ __FBSDID("$FreeBSD$");
void
sysputspaces(WINDOW *wd, int row, int col, int width)
{
- static char str40[] = " ";
+ static char str60[] = " "
+ " ";
- mvwaddstr(wd, row, col, str40 + sizeof(str40) - width - 1);
+ mvwaddstr(wd, row, col, str60 + sizeof(str60) - width - 1);
}
void
sysputstrs(WINDOW *wd, int row, int col, int width)
{
- static char str40[] = "****************************************";
+ static char str60[] = "********************"
+ "****************************************";
- mvwaddstr(wnd, row, col, str40 + sizeof(str40) - width - 1);
+ mvwaddstr(wnd, row, col, str60 + sizeof(str60) - width - 1);
+}
+
+void
+sysputXs(WINDOW *wd, int row, int col, int width)
+{
+ static char str60[] = "XXXXXXXXXXXXXXXXXXXX"
+ "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
+
+ mvwaddstr(wnd, row, col, str60 + sizeof(str60) - width - 1);
}
void