Patch systat -zarc to display cumulative rate and round down large numbers by SI units

PR:		237664
Submitted by:	ota@j.email.ne.jp
MFC after:	2 weeks
This commit is contained in:
Michael Reifenberger 2020-05-11 20:34:52 +00:00
parent 97e251327f
commit 4bde63536c
4 changed files with 49 additions and 46 deletions

View File

@ -4,7 +4,7 @@
.include <src.opts.mk> .include <src.opts.mk>
PROG= systat 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 \ netcmds.c netstat.c pigs.c swap.c icmp.c \
mode.c ip.c sctp.c tcp.c zarc.c \ mode.c ip.c sctp.c tcp.c zarc.c \
vmstat.c convtbl.c ifcmds.c ifstat.c vmstat.c convtbl.c ifcmds.c ifstat.c

View File

@ -165,6 +165,8 @@ void showtcp(void);
void status(void); void status(void);
void suspend(int); void suspend(int);
char *sysctl_dynread(const char *, size_t *); 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) \ #define SYSTAT_CMD(name) \
void close ## name(WINDOW *); \ void close ## name(WINDOW *); \
@ -176,4 +178,4 @@ char *sysctl_dynread(const char *, size_t *);
void show ## name(void) void show ## name(void)
SYSTAT_CMD( zarc ); SYSTAT_CMD( zarc );
SYSTAT_CMD ( sctp ); SYSTAT_CMD( sctp );

View File

@ -300,17 +300,8 @@ display(void)
GETSYSCTL("kstat.zfs.misc.arcstats.dbuf_size", arc_stat); GETSYSCTL("kstat.zfs.misc.arcstats.dbuf_size", arc_stat);
arc[6] += arc_stat; arc[6] += arc_stat;
wmove(wload, 0, 0); wclrtoeol(wload); wmove(wload, 0, 0); wclrtoeol(wload);
for (i = 0 ; i < nitems(arc); i++) { for (i = 0 ; i < nitems(arc); i++)
if (arc[i] > 10llu * 1024 * 1024 * 1024 ) { sysputuint64(wload, 0, i*8+2, 6, arc[i], 0);
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);
}
}
} }
} }
(*curcmd->c_refresh)(); (*curcmd->c_refresh)();

View File

@ -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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -32,16 +32,16 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
/* #include <stdlib.h> */
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include <err.h> #include <err.h>
#include <libutil.h>
#include "systat.h" #include "systat.h"
#include "extern.h" #include "extern.h"
#include "devs.h" #include "devs.h"
struct zfield{ struct zfield {
uint64_t arcstats; uint64_t arcstats;
uint64_t arcstats_demand_data; uint64_t arcstats_demand_data;
uint64_t arcstats_demand_metadata; uint64_t arcstats_demand_metadata;
@ -57,18 +57,25 @@ static struct zarcstats {
struct zfield misses; struct zfield misses;
} curstat, initstat, oldstat; } curstat, initstat, oldstat;
struct zarcrates {
struct zfield current;
struct zfield total;
};
static void static void
getinfo(struct zarcstats *ls); getinfo(struct zarcstats *ls);
WINDOW * WINDOW *
openzarc(void) openzarc(void)
{ {
return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0));
return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0));
} }
void void
closezarc(WINDOW *w) closezarc(WINDOW *w)
{ {
if (w == NULL) if (w == NULL)
return; return;
wclear(w); wclear(w);
@ -80,12 +87,12 @@ void
labelzarc(void) labelzarc(void)
{ {
int row = 1; int row = 1;
wmove(wnd, 0, 0); wclrtoeol(wnd); wmove(wnd, 0, 0); wclrtoeol(wnd);
mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s", mvwprintw(wnd, 0, 31+1, "%4.4s %6.6s %6.6s | Total %4.4s %6.6s %6.6s",
"rate", "hits", "misses", "total hits", "total misses"); "Rate", "Hits", "Misses", "Rate", "Hits", "Misses");
#define L(str) mvwprintw(wnd, row, 5, #str); \ #define L(str) mvwprintw(wnd, row++, 5, \
mvwprintw(wnd, row, 31, ":"); \ "%-26.26s: %% | %%", #str)
mvwprintw(wnd, row, 31+4, "%%"); ++row
L(arcstats); L(arcstats);
L(arcstats.demand_data); L(arcstats.demand_data);
L(arcstats.demand_metadata); L(arcstats.demand_metadata);
@ -98,21 +105,23 @@ labelzarc(void)
dslabel(12, 0, 18); 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 ) if(hits)
return 100 * hits / ( hits + misses ); return 100 * hits / (hits + misses);
else else
return 0; return 0;
} }
static void static void
domode(struct zarcstats *delta, struct zarcstats *rate) domode(struct zarcstats *delta, struct zarcrates *rate)
{ {
#define DO(stat) \ #define DO(stat) \
delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \ delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \
delta->misses.stat = (curstat.misses.stat - oldstat.misses.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);
DO(arcstats_demand_data); DO(arcstats_demand_data);
DO(arcstats_demand_metadata); DO(arcstats_demand_metadata);
@ -136,21 +145,20 @@ void
showzarc(void) showzarc(void)
{ {
int row = 1; 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); domode(&delta, &rate);
#define DO(stat, col, fmt) \ #define DO(stat, col, width) \
mvwprintw(wnd, row, col, fmt, stat) sysputuint64(wnd, row, col, width, stat, HN_DIVISOR_1000)
#define R(stat) DO(rate.hits.stat, 31+1, "%3"PRIu64) #define RATES(stat) mvwprintw(wnd, row, 31+1, "%3"PRIu64, rate.current.stat);\
#define H(stat) DO(delta.hits.stat, 31+1+5, "%7"PRIu64); \ mvwprintw(wnd, row, 31+1+5+7+7+8, "%3"PRIu64, rate.total.stat)
DO(curstat.hits.stat, 31+1+5+8+8, "%12"PRIu64) #define HITS(stat) DO(delta.hits.stat, 31+1+5, 6); \
#define M(stat) DO(delta.misses.stat, 31+1+5+8, "%7"PRIu64); \ DO(curstat.hits.stat, 31+1+5+7+7+8+5, 6)
DO(curstat.misses.stat, 31+1+5+8+8+13, "%12"PRIu64) #define MISSES(stat) DO(delta.misses.stat, 31+1+5+7, 6); \
#define E(stat) R(stat); H(stat); M(stat); ++row 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);
E(arcstats_demand_data); E(arcstats_demand_data);
E(arcstats_demand_metadata); E(arcstats_demand_metadata);
@ -161,9 +169,9 @@ showzarc(void)
E(vdev_cache_stats); E(vdev_cache_stats);
#undef DO #undef DO
#undef E #undef E
#undef M #undef MISSES
#undef H #undef HITS
#undef R #undef RATES
dsshow(12, 0, 18, &cur_dev, &last_dev); dsshow(12, 0, 18, &cur_dev, &last_dev);
} }
@ -180,6 +188,7 @@ initzarc(void)
void void
resetzarc(void) resetzarc(void)
{ {
initzarc(); initzarc();
} }
@ -193,11 +202,11 @@ getinfo(struct zarcstats *ls)
cur_dev.dinfo = tmp_dinfo; cur_dev.dinfo = tmp_dinfo;
last_dev.snap_time = cur_dev.snap_time; last_dev.snap_time = cur_dev.snap_time;
dsgetinfo( &cur_dev ); dsgetinfo(&cur_dev);
size_t size = sizeof( ls->hits.arcstats ); size_t size = sizeof(ls->hits.arcstats);
if ( sysctlbyname("kstat.zfs.misc.arcstats.hits", if (sysctlbyname("kstat.zfs.misc.arcstats.hits",
&ls->hits.arcstats, &size, NULL, 0 ) != 0 ) &ls->hits.arcstats, &size, NULL, 0) != 0)
return; return;
GETSYSCTL("kstat.zfs.misc.arcstats.misses", GETSYSCTL("kstat.zfs.misc.arcstats.misses",
ls->misses.arcstats); ls->misses.arcstats);
@ -234,6 +243,7 @@ getinfo(struct zarcstats *ls)
void void
fetchzarc(void) fetchzarc(void)
{ {
oldstat = curstat; oldstat = curstat;
getinfo(&curstat); getinfo(&curstat);
} }