FreeBSD Bugzilla – Attachment 204155 Details for
Bug 237664
[patch] systat -zarc to display cumulative rate and round down large numbers by SI units
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
systat -zarc improved 4
systat-humanize-5.diff (text/plain), 9.56 KB, created by
ota
on 2019-05-01 22:22:18 UTC
(
hide
)
Description:
systat -zarc improved 4
Filename:
MIME Type:
Creator:
ota
Created:
2019-05-01 22:22:18 UTC
Size:
9.56 KB
patch
obsolete
>Index: usr.bin/systat/Makefile >=================================================================== >--- usr.bin/systat/Makefile (revision 346979) >+++ usr.bin/systat/Makefile (working copy) >@@ -4,7 +4,7 @@ > .include <src.opts.mk> > > PROG= systat >-SRCS= cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c \ >+SRCS= cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c sysput.c \ > netcmds.c netstat.c pigs.c swap.c icmp.c \ > mode.c ip.c sctp.c tcp.c zarc.c \ > vmstat.c convtbl.c ifcmds.c ifstat.c >Index: usr.bin/systat/extern.h >=================================================================== >--- usr.bin/systat/extern.h (revision 346979) >+++ usr.bin/systat/extern.h (working copy) >@@ -165,6 +165,8 @@ > void status(void); > void suspend(int); > char *sysctl_dynread(const char *, size_t *); >+void sysputstrs(WINDOW* , int, int, int); >+void sysputuint64(WINDOW* , int, int, int, uint64_t, int); > > #define SYSTAT_CMD(name) \ > void close ## name(WINDOW *); \ >@@ -176,4 +178,4 @@ > void show ## name(void) > > SYSTAT_CMD( zarc ); >-SYSTAT_CMD ( sctp ); >+SYSTAT_CMD( sctp ); >Index: usr.bin/systat/main.c >=================================================================== >--- usr.bin/systat/main.c (revision 346979) >+++ usr.bin/systat/main.c (working copy) >@@ -300,17 +300,8 @@ > GETSYSCTL("kstat.zfs.misc.arcstats.dbuf_size", arc_stat); > arc[6] += arc_stat; > wmove(wload, 0, 0); wclrtoeol(wload); >- for (i = 0 ; i < nitems(arc); i++) { >- if (arc[i] > 10llu * 1024 * 1024 * 1024 ) { >- wprintw(wload, "%7lluG", arc[i] >> 30); >- } >- else if (arc[i] > 10 * 1024 * 1024 ) { >- wprintw(wload, "%7lluM", arc[i] >> 20); >- } >- else { >- wprintw(wload, "%7lluK", arc[i] >> 10); >- } >- } >+ for (i = 0 ; i < nitems(arc); i++) >+ sysputuint64(wload, 0, i*8+2, 6, arc[i], 0); > } > } > (*curcmd->c_refresh)(); >Index: usr.bin/systat/sysput.c >=================================================================== >--- usr.bin/systat/sysput.c (nonexistent) >+++ usr.bin/systat/sysput.c (working copy) >@@ -0,0 +1,77 @@ >+/*- >+ * Copyright (c) 2019 Yoshihiro Ota >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * 3. Neither the name of the University nor the names of its contributors >+ * may be used to endorse or promote products derived from this software >+ * without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND >+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE >+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ */ >+ >+#include <sys/cdefs.h> >+__FBSDID("$FreeBSD$"); >+ >+#include <sys/types.h> >+#include <sys/sysctl.h> >+ >+#include <inttypes.h> >+#include <string.h> >+#include <err.h> >+#include <libutil.h> >+ >+#include "systat.h" >+#include "extern.h" >+ >+void >+sysputstrs(WINDOW *wnd, int row, int col, int width) >+{ >+ static char str40[] = "****************************************"; >+ >+ mvwaddstr(wnd, row, col, str40 + sizeof(str40) - width - 1); >+} >+ >+void >+sysputuint64(WINDOW *wnd, int row, int col, int width, uint64_t val, int flags) >+{ >+ char unit, *ptr, *start, wrtbuf[width + width + 1]; >+ int len; >+ >+ unit = 0; >+ start = wrtbuf; >+ flags |= HN_NOSPACE; >+ >+ if (val > INT64_MAX) >+ goto error; >+ else >+ len = humanize_number(&wrtbuf[width], width + 1, val, "", >+ HN_AUTOSCALE, flags); >+ if (len < 0) >+ goto error; >+ else if (len < width) >+ memset(wrtbuf + len, ' ', width - len); >+ start += len; >+ >+ mvwaddstr(wnd, row, col, start); >+ return; >+ >+error: >+ sysputstrs(wnd, row, col, width); >+} > >Property changes on: usr.bin/systat/sysput.c >___________________________________________________________________ >Added: svn:eol-style >## -0,0 +1 ## >+native >\ No newline at end of property >Added: svn:keywords >## -0,0 +1 ## >+FreeBSD=%H >\ No newline at end of property >Added: svn:mime-type >## -0,0 +1 ## >+text/plain >\ No newline at end of property >Index: usr.bin/systat/zarc.c >=================================================================== >--- usr.bin/systat/zarc.c (revision 346979) >+++ usr.bin/systat/zarc.c (working copy) >@@ -1,5 +1,5 @@ > /*- >- * Copyright (c) 2014 - 2017 Yoshihiro Ota >+ * Copyright (c) 2014 - 2017, 2019 Yoshihiro Ota > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -32,16 +32,16 @@ > #include <sys/types.h> > #include <sys/sysctl.h> > >-/* #include <stdlib.h> */ > #include <inttypes.h> > #include <string.h> > #include <err.h> >+#include <libutil.h> > > #include "systat.h" > #include "extern.h" > #include "devs.h" > >-struct zfield{ >+struct zfield { > uint64_t arcstats; > uint64_t arcstats_demand_data; > uint64_t arcstats_demand_metadata; >@@ -57,6 +57,11 @@ > struct zfield misses; > } curstat, initstat, oldstat; > >+struct zarcrates { >+ struct zfield current; >+ struct zfield total; >+}; >+ > static void > getinfo(struct zarcstats *ls); > >@@ -63,12 +68,14 @@ > WINDOW * > openzarc(void) > { >- return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0)); >+ >+ return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0)); > } > > void > closezarc(WINDOW *w) > { >+ > if (w == NULL) > return; > wclear(w); >@@ -80,12 +87,12 @@ > labelzarc(void) > { > int row = 1; >+ > wmove(wnd, 0, 0); wclrtoeol(wnd); >- mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s", >- "rate", "hits", "misses", "total hits", "total misses"); >-#define L(str) mvwprintw(wnd, row, 5, #str); \ >- mvwprintw(wnd, row, 31, ":"); \ >- mvwprintw(wnd, row, 31+4, "%%"); ++row >+ mvwprintw(wnd, 0, 31+1, "%4.4s %6.6s %6.6s | Total %4.4s %6.6s %6.6s", >+ "Rate", "Hits", "Misses", "Rate", "Hits", "Misses"); >+#define L(str) mvwprintw(wnd, row++, 5, \ >+ "%-26.26s: %% | %%", #str) > L(arcstats); > L(arcstats.demand_data); > L(arcstats.demand_metadata); >@@ -98,21 +105,23 @@ > dslabel(12, 0, 18); > } > >-static int calc(uint64_t hits, uint64_t misses) >+static int >+calc_rate(uint64_t hits, uint64_t misses) > { >- if( hits ) >- return 100 * hits / ( hits + misses ); >+ if(hits) >+ return 100 * hits / (hits + misses); > else > return 0; > } > > static void >-domode(struct zarcstats *delta, struct zarcstats *rate) >+domode(struct zarcstats *delta, struct zarcrates *rate) > { > #define DO(stat) \ > delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \ > delta->misses.stat = (curstat.misses.stat - oldstat.misses.stat); \ >- rate->hits.stat = calc(delta->hits.stat, delta->misses.stat) >+ rate->current.stat = calc_rate(delta->hits.stat, delta->misses.stat); \ >+ rate->total.stat = calc_rate(curstat.hits.stat, curstat.misses.stat) > DO(arcstats); > DO(arcstats_demand_data); > DO(arcstats_demand_metadata); >@@ -136,21 +145,20 @@ > showzarc(void) > { > int row = 1; >- struct zarcstats delta, rate; >+ struct zarcstats delta = {}; >+ struct zarcrates rate = {}; > >- memset(&delta, 0, sizeof delta); >- memset(&rate, 0, sizeof rate); >- > domode(&delta, &rate); > >-#define DO(stat, col, fmt) \ >- mvwprintw(wnd, row, col, fmt, stat) >-#define R(stat) DO(rate.hits.stat, 31+1, "%3"PRIu64) >-#define H(stat) DO(delta.hits.stat, 31+1+5, "%7"PRIu64); \ >- DO(curstat.hits.stat, 31+1+5+8+8, "%12"PRIu64) >-#define M(stat) DO(delta.misses.stat, 31+1+5+8, "%7"PRIu64); \ >- DO(curstat.misses.stat, 31+1+5+8+8+13, "%12"PRIu64) >-#define E(stat) R(stat); H(stat); M(stat); ++row >+#define DO(stat, col, width) \ >+ sysputuint64(wnd, row, col, width, stat, HN_DIVISOR_1000) >+#define RATES(stat) mvwprintw(wnd, row, 31+1, "%3"PRIu64, rate.current.stat);\ >+ mvwprintw(wnd, row, 31+1+5+7+7+8, "%3"PRIu64, rate.total.stat) >+#define HITS(stat) DO(delta.hits.stat, 31+1+5, 6); \ >+ DO(curstat.hits.stat, 31+1+5+7+7+8+5, 6) >+#define MISSES(stat) DO(delta.misses.stat, 31+1+5+7, 6); \ >+ DO(curstat.misses.stat, 31+1+5+7+7+8+5+7, 6) >+#define E(stat) RATES(stat); HITS(stat); MISSES(stat); ++row > E(arcstats); > E(arcstats_demand_data); > E(arcstats_demand_metadata); >@@ -161,9 +169,9 @@ > E(vdev_cache_stats); > #undef DO > #undef E >-#undef M >-#undef H >-#undef R >+#undef MISSES >+#undef HITS >+#undef RATES > dsshow(12, 0, 18, &cur_dev, &last_dev); > } > >@@ -180,6 +188,7 @@ > void > resetzarc(void) > { >+ > initzarc(); > } > >@@ -193,11 +202,11 @@ > cur_dev.dinfo = tmp_dinfo; > > last_dev.snap_time = cur_dev.snap_time; >- dsgetinfo( &cur_dev ); >+ dsgetinfo(&cur_dev); > >- size_t size = sizeof( ls->hits.arcstats ); >- if ( sysctlbyname("kstat.zfs.misc.arcstats.hits", >- &ls->hits.arcstats, &size, NULL, 0 ) != 0 ) >+ size_t size = sizeof(ls->hits.arcstats); >+ if (sysctlbyname("kstat.zfs.misc.arcstats.hits", >+ &ls->hits.arcstats, &size, NULL, 0) != 0) > return; > GETSYSCTL("kstat.zfs.misc.arcstats.misses", > ls->misses.arcstats); >@@ -234,6 +243,7 @@ > void > fetchzarc(void) > { >+ > oldstat = curstat; > getinfo(&curstat); > }
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 237664
:
204106
|
204133
|
204134
| 204155