FreeBSD Bugzilla – Attachment 220333 Details for
Bug 251655
[patch] systat -swap to improve readability and fix display issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
systat swap improvments patch
systat-swap.diff (text/plain), 5.81 KB, created by
ota
on 2020-12-07 00:09:07 UTC
(
hide
)
Description:
systat swap improvments patch
Filename:
MIME Type:
Creator:
ota
Created:
2020-12-07 00:09:07 UTC
Size:
5.81 KB
patch
obsolete
>Index: extern.h >=================================================================== >--- extern.h (revision 368395) >+++ extern.h (working copy) >@@ -168,6 +168,7 @@ > 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); > >Index: swap.c >=================================================================== >--- swap.c (revision 368395) >+++ swap.c (working copy) >@@ -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,17 +58,12 @@ > #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 >@@ -92,29 +87,6 @@ > 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,23 +95,14 @@ > 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; >- >+ pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */; >+ dsinit(12); > once = 1; > >- dsinit(12); >- > return (1); > } > >@@ -152,10 +115,6 @@ > return; > } > >- odlen = dlen; >- oulen = ulen; >- calclens(); >- > struct devinfo *tmp_dinfo; > > tmp_dinfo = last_dev.dinfo; >@@ -172,24 +131,23 @@ > 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 <= 1) { >+ 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 +156,23 @@ > int count; > int i; > >- if (kvnsw != okvnsw || dlen != odlen || ulen != oulen) >+ if (kvnsw != okvnsw) > labelswap(); > >+ dsshow(12, 0, 18, &cur_dev, &last_dev); >+ >+ if (kvnsw <= 1) >+ return; >+ > for (i = 0; i <= kvnsw; ++i) { >- if (i == kvnsw) { >- if (kvnsw == 1) >- break; >- } >+ sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0); >+ sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used, >+ 0); > >- if (kvmsw[i].ksw_total == 0) { >- mvwprintw( >- wnd, >- i + 1, >- dlen + hlen + ulen + 1, >- "(swap not configured)" >- ); >- continue; >+ if (kvmsw[i].ksw_used > 0) { >+ count = 50 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1; >+ sysputXs(wnd, i + 1, pathlen + 5 + 1 + 5 + 1, count); > } >- >- wmove(wnd, i + 1, dlen); >- >- wprintw(wnd, "%*d", hlen, CONVERT(kvmsw[i].ksw_total)); >- wprintw(wnd, "%*d", ulen, CONVERT(kvmsw[i].ksw_used)); >- >- count = 50.0 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1; >- >- waddch(wnd, ' '); >- while (count--) >- waddch(wnd, 'X'); > wclrtoeol(wnd); > } >- dsshow(12, 0, 18, &cur_dev, &last_dev); > } >Index: sysput.c >=================================================================== >--- sysput.c (revision 368395) >+++ sysput.c (working copy) >@@ -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,20 +43,31 @@ > 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 > sysputuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags) > { > char unit, *ptr, *start, wrtbuf[width + width + 1];
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 251655
: 220333