View | Details | Raw Unified | Return to bug 251655
Collapse All | Expand All

(-)extern.h (+1 lines)
Lines 168-173 Link Here
168
void	 sysputpage(WINDOW* , int, int, int, uint64_t, int);
168
void	 sysputpage(WINDOW* , int, int, int, uint64_t, int);
169
void	 sysputspaces(WINDOW* , int, int, int);
169
void	 sysputspaces(WINDOW* , int, int, int);
170
void	 sysputstrs(WINDOW* , int, int, int);
170
void	 sysputstrs(WINDOW* , int, int, int);
171
void	 sysputXs(WINDOW* , int, int, int);
171
void	 sysputuint64(WINDOW* , int, int, int, uint64_t, int);
172
void	 sysputuint64(WINDOW* , int, int, int, uint64_t, int);
172
void	 sysputwuint64(WINDOW* , int, int, int, uint64_t, int);
173
void	 sysputwuint64(WINDOW* , int, int, int, uint64_t, int);
173
174
(-)swap.c (-84 / +29 lines)
Lines 3-9 Link Here
3
 *
3
 *
4
 * Copyright (c) 1980, 1992, 1993
4
 * Copyright (c) 1980, 1992, 1993
5
 *	The Regents of the University of California.  All rights reserved.
5
 *	The Regents of the University of California.  All rights reserved.
6
 * Copyright (c) 2017 Yoshihiro Ota
6
 * Copyright (c) 2017, 2020 Yoshihiro Ota
7
 *
7
 *
8
 * Redistribution and use in source and binary forms, with or without
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
9
 * modification, are permitted provided that the following conditions
Lines 58-74 Link Here
58
#include "extern.h"
58
#include "extern.h"
59
#include "devs.h"
59
#include "devs.h"
60
60
61
static char *header;
61
static int pathlen;
62
static long blocksize;
63
static int dlen, odlen;
64
static int hlen;
65
static int ulen, oulen;
66
static int pagesize;
67
62
68
WINDOW *
63
WINDOW *
69
openswap(void)
64
openswap(void)
70
{
65
{
71
	return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0));
66
	return (subwin(stdscr, LINES - 3 - 1, 0, MAINWIN_ROW, 0));
72
}
67
}
73
68
74
void
69
void
Lines 92-120 Link Here
92
static struct kvm_swap kvmsw[NSWAP];
87
static struct kvm_swap kvmsw[NSWAP];
93
static int kvnsw, okvnsw;
88
static int kvnsw, okvnsw;
94
89
95
static void calclens(void);
96
97
#define CONVERT(v)	((int)((int64_t)(v) * pagesize / blocksize))
98
99
static void
100
calclens(void)
101
{
102
	int i, n;
103
	int len;
104
105
	dlen = sizeof("Disk");
106
	for (i = 0; i < kvnsw; ++i) {
107
		len = strlen(kvmsw[i].ksw_devname);
108
		if (dlen < len)
109
			dlen = len;
110
	}
111
112
	ulen = sizeof("Used");
113
	for (n = CONVERT(kvmsw[kvnsw].ksw_used), len = 2; n /= 10; ++len);
114
	if (ulen < len)
115
		ulen = len;
116
}
117
118
int
90
int
119
initswap(void)
91
initswap(void)
120
{
92
{
Lines 123-145 Link Here
123
	if (once)
95
	if (once)
124
		return (1);
96
		return (1);
125
97
126
	header = getbsize(&hlen, &blocksize);
127
	pagesize = getpagesize();
128
129
	if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
98
	if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
130
		error("systat: kvm_getswapinfo failed");
99
		error("systat: kvm_getswapinfo failed");
131
		return (0);
100
		return (0);
132
	}
101
	}
133
	okvnsw = kvnsw;
102
	pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */;
134
103
	dsinit(12);
135
	calclens();
136
	odlen = dlen;
137
	oulen = ulen;
138
139
	once = 1;
104
	once = 1;
140
105
141
	dsinit(12);
142
143
	return (1);
106
	return (1);
144
}
107
}
145
108
Lines 152-161 Link Here
152
		return;
115
		return;
153
	}
116
	}
154
117
155
	odlen = dlen;
156
	oulen = ulen;
157
	calclens();
158
159
	struct devinfo *tmp_dinfo;
118
	struct devinfo *tmp_dinfo;
160
119
161
	tmp_dinfo = last_dev.dinfo;
120
	tmp_dinfo = last_dev.dinfo;
Lines 172-195 Link Here
172
	const char *name;
131
	const char *name;
173
	int i;
132
	int i;
174
133
175
	fetchswap();
176
177
	werase(wnd);
134
	werase(wnd);
178
135
179
	mvwprintw(wnd, 0, 0, "%*s%*s%*s %s",
136
	dslabel(12, 0, 18);
180
	    -dlen, "Disk", hlen, header, ulen, "Used",
181
	    "/0%  /10  /20  /30  /40  /50  /60  /70  /80  /90  /100");
182
137
138
	if (kvnsw <= 1) {
139
		mvwprintw(wnd, 0, 0, "(swap not configured)");
140
		return;
141
	}
142
143
	mvwprintw(wnd, 0, 0, "%*s%5s %5s %s",
144
	    -pathlen, "Device/Path", "Size", "Used",
145
	    "|0%  /10  /20  /30  /40  |  60\\  70\\  80\\  90\\ 100|");
146
183
	for (i = 0; i <= kvnsw; ++i) {
147
	for (i = 0; i <= kvnsw; ++i) {
184
		if (i == kvnsw) {
148
		name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname;
185
			if (kvnsw == 1)
149
		mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name);
186
				break;
187
			name = "Total";
188
		} else
189
			name = kvmsw[i].ksw_devname;
190
		mvwprintw(wnd, i + 1, 0, "%*s", -dlen, name);
191
	}
150
	}
192
	dslabel(12, 0, 18);
193
}
151
}
194
152
195
void
153
void
Lines 198-233 Link Here
198
	int count;
156
	int count;
199
	int i;
157
	int i;
200
158
201
	if (kvnsw != okvnsw || dlen != odlen || ulen != oulen)
159
	if (kvnsw != okvnsw)
202
		labelswap();
160
		labelswap();
203
161
162
	dsshow(12, 0, 18, &cur_dev, &last_dev);
163
164
	if (kvnsw <= 1)
165
		return;
166
204
	for (i = 0; i <= kvnsw; ++i) {
167
	for (i = 0; i <= kvnsw; ++i) {
205
		if (i == kvnsw) {
168
		sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0);
206
			if (kvnsw == 1)
169
		sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used,
207
				break;
170
		    0);
208
		}
209
171
210
		if (kvmsw[i].ksw_total == 0) {
172
		if (kvmsw[i].ksw_used > 0) {
211
			mvwprintw(
173
			count = 50 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1;
212
			    wnd,
174
			sysputXs(wnd, i + 1, pathlen + 5 + 1 + 5 + 1, count);
213
			    i + 1,
214
			    dlen + hlen + ulen + 1,
215
			    "(swap not configured)"
216
			);
217
			continue;
218
		}
175
		}
219
220
		wmove(wnd, i + 1, dlen);
221
222
		wprintw(wnd, "%*d", hlen, CONVERT(kvmsw[i].ksw_total));
223
		wprintw(wnd, "%*d", ulen, CONVERT(kvmsw[i].ksw_used));
224
225
		count = 50.0 * kvmsw[i].ksw_used / kvmsw[i].ksw_total + 1;
226
227
		waddch(wnd, ' ');
228
		while (count--)
229
			waddch(wnd, 'X');
230
		wclrtoeol(wnd);
176
		wclrtoeol(wnd);
231
	}
177
	}
232
	dsshow(12, 0, 18, &cur_dev, &last_dev);
233
}
178
}
(-)sysput.c (-5 / +16 lines)
Lines 1-5 Link Here
1
/*-
1
/*-
2
 * Copyright (c) 2019 Yoshihiro Ota
2
 * Copyright (c) 2019, 2020 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 43-62 Link Here
43
void
43
void
44
sysputspaces(WINDOW *wd, int row, int col, int width)
44
sysputspaces(WINDOW *wd, int row, int col, int width)
45
{
45
{
46
	static char str40[] = "                                        ";
46
	static char str60[] = "                    "
47
	    "                                        ";
47
48
48
	mvwaddstr(wd, row, col, str40 + sizeof(str40) - width - 1);
49
	mvwaddstr(wd, row, col, str60 + sizeof(str60) - width - 1);
49
}
50
}
50
51
51
void
52
void
52
sysputstrs(WINDOW *wd, int row, int col, int width)
53
sysputstrs(WINDOW *wd, int row, int col, int width)
53
{
54
{
54
	static char str40[] = "****************************************";
55
	static char str60[] = "********************"
56
	    "****************************************";
55
57
56
	mvwaddstr(wnd, row, col, str40 + sizeof(str40) - width - 1);
58
	mvwaddstr(wnd, row, col, str60 + sizeof(str60) - width - 1);
57
}
59
}
58
60
59
void
61
void
62
sysputXs(WINDOW *wd, int row, int col, int width)
63
{
64
	static char str60[] = "XXXXXXXXXXXXXXXXXXXX"
65
	    "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
66
67
	mvwaddstr(wnd, row, col, str60 + sizeof(str60) - width - 1);
68
}
69
70
void
60
sysputuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags)
71
sysputuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags)
61
{
72
{
62
	char unit, *ptr, *start, wrtbuf[width + width + 1];
73
	char unit, *ptr, *start, wrtbuf[width + width + 1];

Return to bug 251655