View | Details | Raw Unified | Return to bug 237664 | Differences between
and this patch

Collapse All | Expand All

(-)usr.bin/systat/Makefile (-1 / +1 lines)
Lines 4-10 Link Here
4
.include <src.opts.mk>
4
.include <src.opts.mk>
5
5
6
PROG=	systat
6
PROG=	systat
7
SRCS=	cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c \
7
SRCS=	cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c sysput.c \
8
	netcmds.c netstat.c pigs.c swap.c icmp.c \
8
	netcmds.c netstat.c pigs.c swap.c icmp.c \
9
	mode.c ip.c sctp.c tcp.c zarc.c \
9
	mode.c ip.c sctp.c tcp.c zarc.c \
10
	vmstat.c convtbl.c ifcmds.c ifstat.c
10
	vmstat.c convtbl.c ifcmds.c ifstat.c
(-)usr.bin/systat/extern.h (-1 / +3 lines)
Lines 165-170 Link Here
165
void	 status(void);
165
void	 status(void);
166
void	 suspend(int);
166
void	 suspend(int);
167
char	*sysctl_dynread(const char *, size_t *);
167
char	*sysctl_dynread(const char *, size_t *);
168
void	 sysputstrs(WINDOW* , int, int, int);
169
void	 sysputuint64(WINDOW* , int, int, int, uint64_t, int);
168
170
169
#define SYSTAT_CMD(name)	\
171
#define SYSTAT_CMD(name)	\
170
	void	 close ## name(WINDOW *); \
172
	void	 close ## name(WINDOW *); \
Lines 176-179 Link Here
176
	void	 show ## name(void)
178
	void	 show ## name(void)
177
179
178
SYSTAT_CMD( zarc );
180
SYSTAT_CMD( zarc );
179
SYSTAT_CMD ( sctp );
181
SYSTAT_CMD( sctp );
(-)usr.bin/systat/main.c (-11 / +2 lines)
Lines 300-316 Link Here
300
		    GETSYSCTL("kstat.zfs.misc.arcstats.dbuf_size", arc_stat);
300
		    GETSYSCTL("kstat.zfs.misc.arcstats.dbuf_size", arc_stat);
301
		    arc[6] += arc_stat;
301
		    arc[6] += arc_stat;
302
		    wmove(wload, 0, 0); wclrtoeol(wload);
302
		    wmove(wload, 0, 0); wclrtoeol(wload);
303
		    for (i = 0 ; i < nitems(arc); i++) {
303
		    for (i = 0 ; i < nitems(arc); i++)
304
			if (arc[i] > 10llu * 1024 * 1024 * 1024 ) {
304
			sysputuint64(wload, 0, i*8+2, 6, arc[i], 0);
305
				wprintw(wload, "%7lluG", arc[i] >> 30);
306
			}
307
			else if (arc[i] > 10 * 1024 * 1024 ) {
308
				wprintw(wload, "%7lluM", arc[i] >> 20);
309
			}
310
			else {
311
				wprintw(wload, "%7lluK", arc[i] >> 10);
312
			}
313
		    }
314
	    }
305
	    }
315
	}
306
	}
316
	(*curcmd->c_refresh)();
307
	(*curcmd->c_refresh)();
(-)usr.bin/systat/sysput.c (+77 lines)
Line 0 Link Here
1
/*-
2
 * Copyright (c) 2019 Yoshihiro Ota
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 * 3. Neither the name of the University nor the names of its contributors
13
 *    may be used to endorse or promote products derived from this software
14
 *    without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
 * SUCH DAMAGE.
27
 */
28
29
#include <sys/cdefs.h>
30
__FBSDID("$FreeBSD$");
31
32
#include <sys/types.h>
33
#include <sys/sysctl.h>
34
35
#include <inttypes.h>
36
#include <string.h>
37
#include <err.h>
38
#include <libutil.h>
39
40
#include "systat.h"
41
#include "extern.h"
42
43
void
44
sysputstrs(WINDOW *wnd, int row, int col, int width)
45
{
46
	static char str40[] = "****************************************";
47
48
	mvwaddstr(wnd, row, col, str40 + sizeof(str40) - width - 1);
49
}
50
51
void
52
sysputuint64(WINDOW *wnd, int row, int col, int width, uint64_t val, int flags)
53
{
54
	char unit, *ptr, *start, wrtbuf[width + width + 1];
55
	int len;
56
57
	unit = 0;
58
	start = wrtbuf;
59
	flags |= HN_NOSPACE;
60
61
	if (val > INT64_MAX)
62
		goto error;
63
	else
64
		len = humanize_number(&wrtbuf[width], width + 1, val, "",
65
			HN_AUTOSCALE, flags);
66
	if (len < 0)
67
		goto error;
68
	else if (len < width)
69
		memset(wrtbuf + len, ' ', width - len);
70
	start += len;
71
72
	mvwaddstr(wnd, row, col, start);
73
	return;
74
75
error:
76
	sysputstrs(wnd, row, col, width);
77
}
(-)usr.bin/systat/zarc.c (-33 / +43 lines)
Lines 1-5 Link Here
1
/*-
1
/*-
2
 * Copyright (c) 2014 - 2017 Yoshihiro Ota
2
 * Copyright (c) 2014 - 2017, 2019 Yoshihiro Ota
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 32-47 Link Here
32
#include <sys/types.h>
32
#include <sys/types.h>
33
#include <sys/sysctl.h>
33
#include <sys/sysctl.h>
34
34
35
/* #include <stdlib.h> */
36
#include <inttypes.h>
35
#include <inttypes.h>
37
#include <string.h>
36
#include <string.h>
38
#include <err.h>
37
#include <err.h>
38
#include <libutil.h>
39
39
40
#include "systat.h"
40
#include "systat.h"
41
#include "extern.h"
41
#include "extern.h"
42
#include "devs.h"
42
#include "devs.h"
43
43
44
struct zfield{
44
struct zfield {
45
	uint64_t arcstats;
45
	uint64_t arcstats;
46
	uint64_t arcstats_demand_data;
46
	uint64_t arcstats_demand_data;
47
	uint64_t arcstats_demand_metadata;
47
	uint64_t arcstats_demand_metadata;
Lines 57-62 Link Here
57
	struct zfield misses;
57
	struct zfield misses;
58
} curstat, initstat, oldstat;
58
} curstat, initstat, oldstat;
59
59
60
struct zarcrates {
61
	struct zfield current;
62
	struct zfield total;
63
};
64
60
static void
65
static void
61
getinfo(struct zarcstats *ls);
66
getinfo(struct zarcstats *ls);
62
67
Lines 63-74 Link Here
63
WINDOW *
68
WINDOW *
64
openzarc(void)
69
openzarc(void)
65
{
70
{
66
	return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0));
71
72
	return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0));
67
}
73
}
68
74
69
void
75
void
70
closezarc(WINDOW *w)
76
closezarc(WINDOW *w)
71
{
77
{
78
72
	if (w == NULL)
79
	if (w == NULL)
73
		return;
80
		return;
74
	wclear(w);
81
	wclear(w);
Lines 80-91 Link Here
80
labelzarc(void)
87
labelzarc(void)
81
{
88
{
82
	int row = 1;
89
	int row = 1;
90
83
	wmove(wnd, 0, 0); wclrtoeol(wnd);
91
	wmove(wnd, 0, 0); wclrtoeol(wnd);
84
	mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s",
92
	mvwprintw(wnd, 0, 31+1, "%4.4s %6.6s %6.6s | Total %4.4s %6.6s %6.6s",
85
		"rate", "hits", "misses", "total hits", "total misses");
93
		"Rate", "Hits", "Misses", "Rate", "Hits", "Misses");
86
#define L(str) mvwprintw(wnd, row, 5, #str); \
94
#define L(str) mvwprintw(wnd, row++, 5, \
87
	mvwprintw(wnd, row, 31, ":"); \
95
		"%-26.26s:   %%               |          %%", #str)
88
	mvwprintw(wnd, row, 31+4, "%%"); ++row
89
	L(arcstats);
96
	L(arcstats);
90
	L(arcstats.demand_data);
97
	L(arcstats.demand_data);
91
	L(arcstats.demand_metadata);
98
	L(arcstats.demand_metadata);
Lines 98-118 Link Here
98
	dslabel(12, 0, 18);
105
	dslabel(12, 0, 18);
99
}
106
}
100
107
101
static int calc(uint64_t hits, uint64_t misses)
108
static int
109
calc_rate(uint64_t hits, uint64_t misses)
102
{
110
{
103
    if( hits )
111
    if(hits)
104
	return 100 * hits / ( hits + misses );
112
	return 100 * hits / (hits + misses);
105
    else
113
    else
106
	return 0;
114
	return 0;
107
}
115
}
108
116
109
static void
117
static void
110
domode(struct zarcstats *delta, struct zarcstats *rate)
118
domode(struct zarcstats *delta, struct zarcrates *rate)
111
{
119
{
112
#define DO(stat) \
120
#define DO(stat) \
113
	delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \
121
	delta->hits.stat = (curstat.hits.stat - oldstat.hits.stat); \
114
	delta->misses.stat = (curstat.misses.stat - oldstat.misses.stat); \
122
	delta->misses.stat = (curstat.misses.stat - oldstat.misses.stat); \
115
	rate->hits.stat = calc(delta->hits.stat, delta->misses.stat)
123
	rate->current.stat = calc_rate(delta->hits.stat, delta->misses.stat); \
124
	rate->total.stat = calc_rate(curstat.hits.stat, curstat.misses.stat)
116
	DO(arcstats);
125
	DO(arcstats);
117
	DO(arcstats_demand_data);
126
	DO(arcstats_demand_data);
118
	DO(arcstats_demand_metadata);
127
	DO(arcstats_demand_metadata);
Lines 136-156 Link Here
136
showzarc(void)
145
showzarc(void)
137
{
146
{
138
	int row = 1;
147
	int row = 1;
139
	struct zarcstats delta, rate;
148
	struct zarcstats delta = {};
149
	struct zarcrates rate = {};
140
150
141
	memset(&delta, 0, sizeof delta);
142
	memset(&rate, 0, sizeof rate);
143
144
	domode(&delta, &rate);
151
	domode(&delta, &rate);
145
152
146
#define DO(stat, col, fmt) \
153
#define DO(stat, col, width) \
147
	mvwprintw(wnd, row, col, fmt, stat)
154
	sysputuint64(wnd, row, col, width, stat, HN_DIVISOR_1000)
148
#define	R(stat) DO(rate.hits.stat, 31+1, "%3"PRIu64)
155
#define	RATES(stat) mvwprintw(wnd, row, 31+1, "%3"PRIu64, rate.current.stat);\
149
#define	H(stat) DO(delta.hits.stat, 31+1+5, "%7"PRIu64); \
156
	mvwprintw(wnd, row, 31+1+5+7+7+8, "%3"PRIu64, rate.total.stat)
150
	DO(curstat.hits.stat, 31+1+5+8+8, "%12"PRIu64)
157
#define	HITS(stat) DO(delta.hits.stat, 31+1+5, 6); \
151
#define	M(stat) DO(delta.misses.stat, 31+1+5+8, "%7"PRIu64); \
158
	DO(curstat.hits.stat, 31+1+5+7+7+8+5, 6)
152
	DO(curstat.misses.stat, 31+1+5+8+8+13, "%12"PRIu64)
159
#define	MISSES(stat) DO(delta.misses.stat, 31+1+5+7, 6); \
153
#define	E(stat) R(stat); H(stat); M(stat); ++row
160
	DO(curstat.misses.stat, 31+1+5+7+7+8+5+7, 6)
161
#define	E(stat) RATES(stat); HITS(stat); MISSES(stat); ++row
154
	E(arcstats);
162
	E(arcstats);
155
	E(arcstats_demand_data);
163
	E(arcstats_demand_data);
156
	E(arcstats_demand_metadata);
164
	E(arcstats_demand_metadata);
Lines 161-169 Link Here
161
	E(vdev_cache_stats);
169
	E(vdev_cache_stats);
162
#undef DO
170
#undef DO
163
#undef E
171
#undef E
164
#undef M
172
#undef MISSES
165
#undef H
173
#undef HITS
166
#undef R
174
#undef RATES
167
	dsshow(12, 0, 18, &cur_dev, &last_dev);
175
	dsshow(12, 0, 18, &cur_dev, &last_dev);
168
}
176
}
169
177
Lines 180-185 Link Here
180
void
188
void
181
resetzarc(void)
189
resetzarc(void)
182
{
190
{
191
183
	initzarc();
192
	initzarc();
184
}
193
}
185
194
Lines 193-203 Link Here
193
	cur_dev.dinfo = tmp_dinfo;
202
	cur_dev.dinfo = tmp_dinfo;
194
203
195
	last_dev.snap_time = cur_dev.snap_time;
204
	last_dev.snap_time = cur_dev.snap_time;
196
	dsgetinfo( &cur_dev );
205
	dsgetinfo(&cur_dev);
197
206
198
	size_t size = sizeof( ls->hits.arcstats );
207
	size_t size = sizeof(ls->hits.arcstats);
199
	if ( sysctlbyname("kstat.zfs.misc.arcstats.hits",
208
	if (sysctlbyname("kstat.zfs.misc.arcstats.hits",
200
		&ls->hits.arcstats, &size, NULL, 0 ) != 0 )
209
		&ls->hits.arcstats, &size, NULL, 0) != 0)
201
		return;
210
		return;
202
	GETSYSCTL("kstat.zfs.misc.arcstats.misses",
211
	GETSYSCTL("kstat.zfs.misc.arcstats.misses",
203
		ls->misses.arcstats);
212
		ls->misses.arcstats);
Lines 234-239 Link Here
234
void
243
void
235
fetchzarc(void)
244
fetchzarc(void)
236
{
245
{
246
237
	oldstat = curstat;
247
	oldstat = curstat;
238
	getinfo(&curstat);
248
	getinfo(&curstat);
239
}
249
}

Return to bug 237664