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

(-)b/usr.bin/systat/Makefile (-2 / +2 lines)
Lines 5-11 Link Here
5
5
6
PROG=	systat
6
PROG=	systat
7
SRCS=	cmds.c cmdtab.c devs.c fetch.c iostat.c keyboard.c main.c sysput.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 proc.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
11
11
Lines 16-21 CFLAGS+= -DINET6 Link Here
16
16
17
WARNS?=	1
17
WARNS?=	1
18
18
19
LIBADD=	ncursesw m devstat kvm util
19
LIBADD=	ncursesw m devstat kvm util procstat
20
20
21
.include <bsd.prog.mk>
21
.include <bsd.prog.mk>
(-)b/usr.bin/systat/devs.c (-8 / +1 lines)
Lines 426-438 dsshow2(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct s Link Here
426
	putlongdouble(device_busy, diskrow + 4, lc, 5, 0, 0);
426
	putlongdouble(device_busy, diskrow + 4, lc, 5, 0, 0);
427
}
427
}
428
428
429
static void
430
dsshow3(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct statinfo *then)
431
{
432
433
	dsshow2(diskcol, diskrow, dn, lc, now, then);
434
}
435
436
void
429
void
437
dsshow(int maxdrives, int diskcol, int diskrow, struct statinfo *now, struct statinfo *then)
430
dsshow(int maxdrives, int diskcol, int diskrow, struct statinfo *now, struct statinfo *then)
438
{
431
{
Lines 440-444 dsshow(int maxdrives, int diskcol, int diskrow, struct statinfo *now, struct sta Link Here
440
433
441
	for (i = 0, lc = 0; i < num_devices && lc < maxdrives; i++)
434
	for (i = 0, lc = 0; i < num_devices && lc < maxdrives; i++)
442
		if (dev_select[i].selected)
435
		if (dev_select[i].selected)
443
			dsshow3(diskcol, diskrow, i, ++lc, now, then);
436
			dsshow2(diskcol, diskrow, i, ++lc, now, then);
444
}
437
}
(-)b/usr.bin/systat/devs.h (-1 / +3 lines)
Lines 2-8 Link Here
2
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
2
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
 *
3
 *
4
 * Copyright (c) 1998 David E. O'Brien
4
 * Copyright (c) 1998 David E. O'Brien
5
 *               2015 Yoshihiro Ota
5
 *               2015, 2021 Yoshihiro Ota
6
 * All rights reserved.
6
 * All rights reserved.
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
Lines 34-39 Link Here
34
34
35
#include <devstat.h>
35
#include <devstat.h>
36
36
37
#define DISKHIGHT 5
38
37
int dsinit(int);
39
int dsinit(int);
38
void dsgetinfo(struct statinfo *);
40
void dsgetinfo(struct statinfo *);
39
int dscmd(const char *, const char *, int, struct statinfo *);
41
int dscmd(const char *, const char *, int, struct statinfo *);
(-)b/usr.bin/systat/extern.h (-66 / +14 lines)
Lines 71-87 extern struct nlist namelist[]; Link Here
71
71
72
int	 checkhost(struct in_conninfo *);
72
int	 checkhost(struct in_conninfo *);
73
int	 checkport(struct in_conninfo *);
73
int	 checkport(struct in_conninfo *);
74
void	 closeicmp(WINDOW *);
75
void	 closeicmp6(WINDOW *);
76
void	 closeifstat(WINDOW *);
77
void	 closeiostat(WINDOW *);
78
void	 closeip(WINDOW *);
79
void	 closeip6(WINDOW *);
80
void	 closekre(WINDOW *);
81
void	 closenetstat(WINDOW *);
82
void	 closepigs(WINDOW *);
83
void	 closeswap(WINDOW *);
84
void	 closetcp(WINDOW *);
85
int	 cmdifstat(const char *, const char *);
74
int	 cmdifstat(const char *, const char *);
86
int	 cmdiostat(const char *, const char *);
75
int	 cmdiostat(const char *, const char *);
87
int	 cmdkre(const char *, const char *);
76
int	 cmdkre(const char *, const char *);
Lines 93-166 void display(void); Link Here
93
int	 dkinit(void);
82
int	 dkinit(void);
94
int	 dkcmd(char *, char *);
83
int	 dkcmd(char *, char *);
95
void	 error(const char *fmt, ...) __printflike(1, 2);
84
void	 error(const char *fmt, ...) __printflike(1, 2);
96
void	 fetchicmp(void);
97
void	 fetchicmp6(void);
98
void	 fetchifstat(void);
85
void	 fetchifstat(void);
99
void	 fetchip(void);
100
void	 fetchip6(void);
101
void	 fetchiostat(void);
102
void	 fetchkre(void);
103
void	 fetchnetstat(void);
104
void	 fetchpigs(void);
105
void	 fetchswap(void);
106
void	 fetchtcp(void);
107
void	 getsysctl(const char *, void *, size_t);
86
void	 getsysctl(const char *, void *, size_t);
108
int	 ifcmd(const char *cmd, const char *args);
87
int	 ifcmd(const char *cmd, const char *args);
109
int	 initicmp(void);
110
int	 initicmp6(void);
111
int	 initifstat(void);
112
int	 initip(void);
113
int	 initip6(void);
114
int	 initiostat(void);
115
int	 initkre(void);
116
int	 initnetstat(void);
117
int	 initpigs(void);
118
int	 initswap(void);
119
int	 inittcp(void);
120
int	 keyboard(void);
88
int	 keyboard(void);
121
int	 kvm_ckread(void *, void *, int);
89
int	 kvm_ckread(void *, void *, int);
122
void	 labelicmp(void);
123
void	 labelicmp6(void);
124
void	 labelifstat(void);
125
void	 labelip(void);
126
void	 labelip6(void);
127
void	 labeliostat(void);
128
void	 labelkre(void);
129
void	 labelnetstat(void);
130
void	 labelpigs(void);
131
void	 labels(void);
90
void	 labels(void);
132
void	 labelswap(void);
133
void	 labeltcp(void);
134
void	 load(void);
91
void	 load(void);
135
int	 netcmd(const char *, const char *);
92
int	 netcmd(const char *, const char *);
136
void	 nlisterr(struct nlist []);
93
void	 nlisterr(struct nlist []);
137
WINDOW	*openicmp(void);
138
WINDOW	*openicmp6(void);
139
WINDOW	*openifstat(void);
140
WINDOW	*openip(void);
141
WINDOW	*openip6(void);
142
WINDOW	*openiostat(void);
143
WINDOW	*openkre(void);
144
WINDOW	*opennetstat(void);
145
WINDOW	*openpigs(void);
146
WINDOW	*openswap(void);
147
WINDOW	*opentcp(void);
148
int	 prefix(const char *, const char *);
94
int	 prefix(const char *, const char *);
149
void	 reseticmp(void);
95
void	 reseticmp(void);
150
void	 reseticmp6(void);
96
void	 reseticmp6(void);
151
void	 resetip(void);
97
void	 resetip(void);
152
void	 resetip6(void);
98
void	 resetip6(void);
153
void	 resettcp(void);
99
void	 resettcp(void);
154
void	 showicmp(void);
100
void	 resetsctp(void);
155
void	 showicmp6(void);
101
void	 resetzarc(void);
156
void	 showifstat(void);
157
void	 showip(void);
158
void	 showip6(void);
159
void	 showiostat(void);
160
void	 showkre(void);
161
void	 shownetstat(void);
162
void	 showpigs(void);
163
void	 showswap(void);
164
void	 showtcp(void);
102
void	 showtcp(void);
165
void	 status(void);
103
void	 status(void);
166
void	 suspend(int);
104
void	 suspend(int);
Lines 178-185 void sysputwuint64(WINDOW* , int, int, int, uint64_t, int); Link Here
178
	int	 init ## name(void); \
116
	int	 init ## name(void); \
179
	void	 label ## name(void); \
117
	void	 label ## name(void); \
180
	WINDOW	*open ## name(void); \
118
	WINDOW	*open ## name(void); \
181
	void	 reset ## name(void); \
182
	void	 show ## name(void)
119
	void	 show ## name(void)
183
120
184
SYSTAT_CMD( zarc );
121
SYSTAT_CMD( kre );
122
SYSTAT_CMD( icmp );
123
SYSTAT_CMD( icmp6 );
124
SYSTAT_CMD( ifstat );
125
SYSTAT_CMD( iostat );
126
SYSTAT_CMD( ip );
127
SYSTAT_CMD( ip6 );
128
SYSTAT_CMD( netstat );
129
SYSTAT_CMD( pigs );
185
SYSTAT_CMD( sctp );
130
SYSTAT_CMD( sctp );
131
SYSTAT_CMD( swap );
132
SYSTAT_CMD( tcp );
133
SYSTAT_CMD( zarc );
(-)b/usr.bin/systat/main.c (+16 lines)
Lines 135-140 parse_cmd_args (int argc, char **argv) Link Here
135
135
136
}
136
}
137
137
138
static void
139
resize(int signo __unused)
140
{
141
142
	endwin();
143
	refresh();
144
	clear();
145
146
	CMDLINE = LINES - 1;
147
	labels();
148
	display();
149
	status();
150
}
151
152
138
int
153
int
139
main(int argc, char **argv)
154
main(int argc, char **argv)
140
{
155
{
Lines 191-196 main(int argc, char **argv) Link Here
191
	signal(SIGINT, die);
206
	signal(SIGINT, die);
192
	signal(SIGQUIT, die);
207
	signal(SIGQUIT, die);
193
	signal(SIGTERM, die);
208
	signal(SIGTERM, die);
209
	signal(SIGWINCH, resize);
194
210
195
	/*
211
	/*
196
	 * Initialize display.  Load average appears in a one line
212
	 * Initialize display.  Load average appears in a one line
(-)b/usr.bin/systat/pigs.c (-1 / +1 lines)
Lines 56-62 __FBSDID("$FreeBSD$"); Link Here
56
#include "systat.h"
56
#include "systat.h"
57
#include "extern.h"
57
#include "extern.h"
58
58
59
int compar(const void *, const void *);
59
static int compar(const void *, const void *);
60
60
61
static int nproc;
61
static int nproc;
62
static struct p_times {
62
static struct p_times {
(-)b/usr.bin/systat/proc.c (+192 lines)
Added Link Here
1
/*-
2
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
 *
4
 * Copyright (c) 2021 Yoshihiro Ota
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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
 * $FreeBSD$
29
 */
30
31
#include <sys/cdefs.h>
32
__FBSDID("$FreeBSD$");
33
34
#include <sys/param.h>
35
#include <sys/sysctl.h>
36
#include <sys/user.h>
37
38
#include <libprocstat.h>
39
40
#include <curses.h>
41
#include <pwd.h>
42
#include <stdlib.h>
43
#include <string.h>
44
45
#include "subs.h"
46
#include "systat.h"
47
#include "extern.h"
48
49
static int compar(const void *, const void *);
50
51
static unsigned int nproc;
52
53
static struct procstat *prstat = NULL;
54
static struct proc_usage {
55
	pid_t pid;
56
	uid_t uid;
57
	char command[COMMLEN+1];
58
	uint64_t total;
59
	uint64_t swap;
60
} *pu = NULL, pzero;
61
62
63
void
64
closeproc(WINDOW *w)
65
{
66
	procstat_close(prstat);
67
	prstat = NULL;
68
	if (w == NULL)
69
		return;
70
	wclear(w);
71
	wrefresh(w);
72
	delwin(w);
73
}
74
75
void
76
procshow(int col, int hight, uint64_t totalswappages)
77
{
78
	int i, j, y, offset;
79
	int rate;
80
	const char *uname, *pname;
81
	char buf[30];
82
83
	if (nproc > 1)
84
		qsort(pu, nproc, sizeof (struct proc_usage), compar);
85
	y = col + 1 /* HEADING */;
86
	offset = 0;
87
	for (i = 0; i < hight; i++, y++) {
88
		wmove(wnd, y, 0);
89
		wclrtoeol(wnd);
90
		if (i >= nproc)
91
			continue;
92
93
		uname = user_from_uid(pu[i].uid, 0);
94
		snprintf(buf, sizeof(buf), "%6d %-10s %-10.10s", pu[i].pid,
95
		    uname, pu[i].command);
96
		offset = 6 + 1 + 10 + 1 + 10 + 1;
97
		mvwaddstr(wnd, y, 0, buf);
98
		sysputuint64(wnd, y, offset, 4, pu[i].swap, 0);
99
		offset += 4;
100
		mvwaddstr(wnd, y, offset, " / ");
101
		offset += 3;
102
		sysputuint64(wnd, y, offset, 4, pu[i].total, 0);
103
		offset += 4;
104
105
		rate = (pu[i].total > 1 ? 100 * pu[i].swap / pu[i].total : 0);
106
		snprintf(buf, sizeof(buf), "%3d%%", rate);
107
		mvwaddstr(wnd, y, offset, buf);
108
		sysputXs(wnd, y, offset + 5, rate / 10);
109
110
		rate = 100 * byte_to_page(pu[i].swap) / totalswappages;
111
		snprintf(buf, sizeof(buf), "%3d%%", rate);
112
		mvwaddstr(wnd, y, offset + 16, buf);
113
		sysputXs(wnd, y, offset + 21, rate / 10);
114
	}
115
}
116
117
int
118
procinit(void)
119
{
120
121
	if (prstat != NULL)
122
		return(1);
123
	prstat = procstat_open_sysctl();
124
	return (prstat == NULL);
125
}
126
127
void
128
procgetinfo(void)
129
{
130
	static unsigned int maxnproc = 0;
131
	int i, j, k;
132
	unsigned int cnt;
133
	struct kinfo_proc *kipp;
134
	struct kinfo_vmentry *freep, *kve;
135
136
	kipp = procstat_getprocs(prstat, KERN_PROC_PROC, 0, &nproc);
137
	if (kipp == NULL) {
138
		error("procstat_getprocs()");
139
		return;
140
	}
141
142
	if (nproc > maxnproc) {
143
		maxnproc = nproc;
144
		if ((pu = realloc(pu, maxnproc * sizeof(*pu))) == NULL) {
145
			error("Out of memory");
146
			die(0);
147
		}
148
	}
149
	for (i = 0, k = 0; i < nproc; i++) {
150
		freep = procstat_getvmmap(prstat, &kipp[i], &cnt);
151
		if (freep == NULL) {
152
			continue;
153
		}
154
		pu[k].swap = 0;
155
		for (j = 0; j < cnt; j++) {
156
			kve = &freep[j];
157
			if (kve->kve_type == KVME_TYPE_SWAP) {
158
				pu[k].swap += kve->kve_end - kve->kve_start;
159
				pu[k].swap -= page_to_byte(kve->kve_resident);
160
			}
161
		}
162
		if (pu[k].swap != 0) {
163
			strcpy(pu[k].command, kipp[i].ki_comm);
164
			pu[k].pid = kipp[i].ki_pid;
165
			pu[k].uid = kipp[i].ki_uid;
166
			pu[k].total = kipp[i].ki_size;
167
			k++;
168
		}
169
		free(freep);
170
	}
171
	procstat_freeprocs(prstat, kipp);
172
	nproc = k;
173
}
174
175
void
176
proclabel(int col)
177
{
178
179
	wmove(wnd, col, 0);
180
	wclrtoeol(wnd);
181
	mvwaddstr(wnd, col, 0,
182
	    "Pid    Username   Command     Swap/Total "
183
	    "Per-Process    Per-System");
184
}
185
186
int
187
compar(const void *a, const void *b)
188
{
189
190
	return (((const struct proc_usage *) a)->swap >
191
		((const struct proc_usage *) b)->swap) ? -1: 1;
192
}
(-)b/usr.bin/systat/subs.h (+42 lines)
Added Link Here
1
/*-
2
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3
 *
4
 * Copyright (c) 2021 Yoshihiro Ota
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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
 * $FreeBSD$
29
 */
30
31
#ifndef SUBS_H
32
#define SUBS_H
33
34
#include <sys/stdint.h>
35
36
int procinit(void);
37
void procgetinfo(void);
38
39
void proclabel(int col);
40
void procshow(int col, int hight, uint64_t totalswappages);
41
42
#endif
(-)b/usr.bin/systat/swap.c (-14 / +20 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, 2020 Yoshihiro Ota
6
 * Copyright (c) 2017, 2020, 2021 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 57-62 static const char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95"; Link Here
57
#include "systat.h"
57
#include "systat.h"
58
#include "extern.h"
58
#include "extern.h"
59
#include "devs.h"
59
#include "devs.h"
60
#include "subs.h"
60
61
61
static int pathlen;
62
static int pathlen;
62
63
Lines 103-108 initswap(void) Link Here
103
	}
104
	}
104
	pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */;
105
	pathlen = 80 - 50 /* % */ - 5 /* Used */ - 5 /* Size */ - 3 /* space */;
105
	dsinit(12);
106
	dsinit(12);
107
	procinit();
106
	once = 1;
108
	once = 1;
107
109
108
	return (1);
110
	return (1);
Lines 125-142 fetchswap(void) Link Here
125
	cur_dev.dinfo = tmp_dinfo;
127
	cur_dev.dinfo = tmp_dinfo;
126
128
127
	last_dev.snap_time = cur_dev.snap_time;
129
	last_dev.snap_time = cur_dev.snap_time;
128
	dsgetinfo( &cur_dev );
130
	dsgetinfo(&cur_dev);
131
	procgetinfo();
129
}
132
}
130
133
131
void
134
void
132
labelswap(void)
135
labelswap(void)
133
{
136
{
134
	const char *name;
135
	int i;
136
137
137
	werase(wnd);
138
	werase(wnd);
138
139
139
	dslabel(12, 0, 18);
140
	dslabel(12, 0, LINES - DISKHIGHT - 1);
140
141
141
	if (kvnsw <= 0) {
142
	if (kvnsw <= 0) {
142
		mvwprintw(wnd, 0, 0, "(swap not configured)");
143
		mvwprintw(wnd, 0, 0, "(swap not configured)");
Lines 146-173 labelswap(void) Link Here
146
	mvwprintw(wnd, 0, 0, "%*s%5s %5s %s",
147
	mvwprintw(wnd, 0, 0, "%*s%5s %5s %s",
147
	    -pathlen, "Device/Path", "Size", "Used",
148
	    -pathlen, "Device/Path", "Size", "Used",
148
	    "|0%  /10  /20  /30  /40  / 60\\  70\\  80\\  90\\ 100|");
149
	    "|0%  /10  /20  /30  /40  / 60\\  70\\  80\\  90\\ 100|");
149
150
	for (i = 0; i <= kvnsw; ++i) {
151
		name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname;
152
		mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name);
153
	}
154
}
150
}
155
151
156
void
152
void
157
showswap(void)
153
showswap(void)
158
{
154
{
159
	int count;
155
	const char *name;
160
	int i;
156
	int count, i;
161
157
162
	if (kvnsw != okvnsw)
158
	if (kvnsw != okvnsw)
163
		labelswap();
159
		labelswap();
164
160
165
	dsshow(12, 0, 18, &cur_dev, &last_dev);
161
	dsshow(12, 0, LINES - DISKHIGHT - 1, &cur_dev, &last_dev);
166
162
167
	if (kvnsw <= 0)
163
	if (kvnsw <= 0)
168
		return;
164
		return;
169
165
170
	for (i = 0; i <= kvnsw; ++i) {
166
	for (i = (kvnsw == 1 ? 0 : kvnsw); i >= 0; i--) {
167
		name = i == kvnsw ? "Total" : kvmsw[i].ksw_devname;
168
		mvwprintw(wnd, 1 + i, 0, "%-*.*s", pathlen, pathlen - 1, name);
169
171
		sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0);
170
		sysputpage(wnd, i + 1, pathlen, 5, kvmsw[i].ksw_total, 0);
172
		sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used,
171
		sysputpage(wnd, i + 1, pathlen + 5 + 1, 5, kvmsw[i].ksw_used,
173
		    0);
172
		    0);
Lines 178-181 showswap(void) Link Here
178
		}
177
		}
179
		wclrtoeol(wnd);
178
		wclrtoeol(wnd);
180
	}
179
	}
180
	if (kvnsw == 1)
181
		count = 2;
182
	else
183
		count = 3;
184
	proclabel(kvnsw + count);
185
	procshow(kvnsw + count, LINES - 5 - (kvnsw + 3) - (DISKHIGHT + 1),
186
	    kvmsw[kvnsw].ksw_total);
181
}
187
}
(-)b/usr.bin/systat/sysput.c (-10 / +25 lines)
Lines 1-4 Link Here
1
/*-
1
/*-
2
 * SPDX-License-Identifier: BSD-3-Clause
3
 *
2
 * Copyright (c) 2019, 2020 Yoshihiro Ota
4
 * Copyright (c) 2019, 2020 Yoshihiro Ota
3
 *
5
 *
4
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
Lines 40-45 __FBSDID("$FreeBSD$"); Link Here
40
#include "systat.h"
42
#include "systat.h"
41
#include "extern.h"
43
#include "extern.h"
42
44
45
static int page_shift();
46
47
uint64_t
48
byte_to_page(uint64_t size)
49
{
50
51
    return (size >> page_shift());
52
}
53
54
uint64_t
55
page_to_byte(uint64_t size)
56
{
57
58
    return (size << page_shift());
59
}
60
43
void
61
void
44
sysputspaces(WINDOW *wd, int row, int col, int width)
62
sysputspaces(WINDOW *wd, int row, int col, int width)
45
{
63
{
Lines 104-118 sysputwuint64(WINDOW *wd, int row, int col, int width, uint64_t val, int flags) Link Here
104
		sysputuint64(wd, row, col, width, val, flags);
122
		sysputuint64(wd, row, col, width, val, flags);
105
}
123
}
106
124
107
static int
125
int
108
calc_page_shift()
126
page_shift()
109
{
127
{
110
	u_int page_size;
128
	u_int page_size;
111
	int shifts;
129
	static int shifts = 0;
112
130
113
	shifts = 0;
131
	if (shifts != 0)
132
		return (shifts);
114
	GETSYSCTL("vm.stats.vm.v_page_size", page_size);
133
	GETSYSCTL("vm.stats.vm.v_page_size", page_size);
115
	for(; page_size > 1; page_size >>= 1)
134
	for (; page_size > 1; page_size >>= 1)
116
		shifts++;
135
		shifts++;
117
	return shifts;
136
	return shifts;
118
}
137
}
Lines 120-129 calc_page_shift() Link Here
120
void
139
void
121
sysputpage(WINDOW *wd, int row, int col, int width, uint64_t pages, int flags)
140
sysputpage(WINDOW *wd, int row, int col, int width, uint64_t pages, int flags)
122
{
141
{
123
	static int shifts = 0;
124
142
125
	if (shifts == 0)
143
	sysputuint64(wd, row, col, width, page_to_byte(pages), flags);
126
		shifts = calc_page_shift();
127
	pages <<= shifts;
128
	sysputuint64(wd, row, col, width, pages, flags);
129
}
144
}
(-)b/usr.bin/systat/systat.1 (-3 / +15 lines)
Lines 297-305 not display kilobytes per transaction). Link Here
297
.El
297
.El
298
.It Ic swap
298
.It Ic swap
299
Show information about swap space usage on all the
299
Show information about swap space usage on all the
300
swap areas compiled into the kernel.
300
swap areas compiled into the kernel and processes that are swapped out.
301
The first column is the device name of the partition.
301
The swap areas are displayed first with their name, sizes and
302
The next column is the total space available in the partition.
302
percentage usage.
303
Then, processes are listed in order of higher swap vm object counts.
304
Pid, username, a part of command line, the total number of swap objects
305
in bytes, the size of process, and per-process swap usage percentage and
306
per-system swap space percentage.
307
A default vm objecte is converted to a swap vm objects when paging
308
out to swap space first time.  Even if such a swap object is paged-in,
309
the object remains as a swap object.
310
In other words, under some circumstances, the number of swap objects
311
may be higher than actual swap space usage.
312
One known case is when
313
.Dl $ swapoff -a
314
 is run.
303
The
315
The
304
.Ar Used
316
.Ar Used
305
column indicates the total blocks used so far;
317
column indicates the total blocks used so far;
(-)b/usr.bin/systat/systat.h (+4 lines)
Lines 33-38 Link Here
33
 */
33
 */
34
34
35
#include <curses.h>
35
#include <curses.h>
36
#include <sys/stdint.h>
36
37
37
struct  cmdtab {
38
struct  cmdtab {
38
	const char *c_name;		/* command name */
39
	const char *c_name;		/* command name */
Lines 69-74 extern int use_kvm; Link Here
69
#define NPTR(indx)  (void *)NVAL((indx))
70
#define NPTR(indx)  (void *)NVAL((indx))
70
#define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len))
71
#define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len))
71
72
73
extern uint64_t byte_to_page(uint64_t size);
74
extern uint64_t page_to_byte(uint64_t size);
75
72
extern void putint(int, int, int, int);
76
extern void putint(int, int, int, int);
73
extern void putfloat(double, int, int, int, int, int);
77
extern void putfloat(double, int, int, int, int, int);
74
extern void putlongdouble(long double, int, int, int, int, int);
78
extern void putlongdouble(long double, int, int, int, int, int);

Return to bug 254723