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

Collapse All | Expand All

(-)usr.bin/systat/devs.c (-8 / +118 lines)
Lines 2-7 Link Here
2
 * SPDX-License-Identifier: BSD-3-Clause
2
 * SPDX-License-Identifier: BSD-3-Clause
3
 *
3
 *
4
 * Copyright (c) 1998 Kenneth D. Merry.
4
 * Copyright (c) 1998 Kenneth D. Merry.
5
 *               2015 Yoshihiro Ota
5
 * All rights reserved.
6
 * All rights reserved.
6
 *
7
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * Redistribution and use in source and binary forms, with or without
Lines 69-75 Link Here
69
#include <sys/resource.h>
70
#include <sys/resource.h>
70
71
71
#include <ctype.h>
72
#include <ctype.h>
72
#include <devstat.h>
73
#include <err.h>
73
#include <err.h>
74
#include <stdlib.h>
74
#include <stdlib.h>
75
#include <string.h>
75
#include <string.h>
Lines 84-89 Link Here
84
	DS_MATCHTYPE_PATTERN
84
	DS_MATCHTYPE_PATTERN
85
} last_match_type;
85
} last_match_type;
86
86
87
struct statinfo cur_dev, last_dev, run_dev;
88
87
last_match_type last_type;
89
last_match_type last_type;
88
struct device_selection *dev_select;
90
struct device_selection *dev_select;
89
long generation;
91
long generation;
Lines 101-110 Link Here
101
		    int maxshowdevs, struct statinfo *s1);
103
		    int maxshowdevs, struct statinfo *s1);
102
104
103
int
105
int
104
dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2 __unused,
106
dsinit(int maxshowdevs)
105
       struct statinfo *s3 __unused)
106
{
107
{
107
108
	/*
108
	/*
109
	 * Make sure that the userland devstat version matches the kernel
109
	 * Make sure that the userland devstat version matches the kernel
110
	 * devstat version.  If not, exit and print a message informing
110
	 * devstat version.  If not, exit and print a message informing
Lines 113-118 Link Here
113
	if (devstat_checkversion(NULL) < 0)
113
	if (devstat_checkversion(NULL) < 0)
114
		errx(1, "%s", devstat_errbuf);
114
		errx(1, "%s", devstat_errbuf);
115
115
116
	if( cur_dev.dinfo ) // init was alreay ran
117
		return(1);
118
119
	if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
120
		warnx("%s", devstat_errbuf);
121
		return(0);
122
	}
123
124
	cur_dev.dinfo = calloc(1, sizeof(struct devinfo));
125
	last_dev.dinfo = calloc(1, sizeof(struct devinfo));
126
	run_dev.dinfo = calloc(1, sizeof(struct devinfo));
127
116
	generation = 0;
128
	generation = 0;
117
	num_devices = 0;
129
	num_devices = 0;
118
	num_selected = 0;
130
	num_selected = 0;
Lines 120-130 Link Here
120
	select_generation = 0;
132
	select_generation = 0;
121
	last_type = DS_MATCHTYPE_NONE;
133
	last_type = DS_MATCHTYPE_NONE;
122
134
123
	if (devstat_getdevs(NULL, s1) == -1)
135
	if (devstat_getdevs(NULL, &cur_dev) == -1)
124
		errx(1, "%s", devstat_errbuf);
136
		errx(1, "%s", devstat_errbuf);
125
137
126
	num_devices = s1->dinfo->numdevs;
138
	num_devices = cur_dev.dinfo->numdevs;
127
	generation = s1->dinfo->generation;
139
	generation = cur_dev.dinfo->generation;
128
140
129
	dev_select = NULL;
141
	dev_select = NULL;
130
142
Lines 134-140 Link Here
134
	 * or 1.  If we get back -1, though, there is an error.
146
	 * or 1.  If we get back -1, though, there is an error.
135
	 */
147
	 */
136
	if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
148
	if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
137
	    &select_generation, generation, s1->dinfo->devices, num_devices,
149
	    &select_generation, generation, cur_dev.dinfo->devices, num_devices,
138
	    NULL, 0, NULL, 0, DS_SELECT_ADD, maxshowdevs, 0) == -1)
150
	    NULL, 0, NULL, 0, DS_SELECT_ADD, maxshowdevs, 0) == -1)
139
		errx(1, "%d %s", __LINE__, devstat_errbuf);
151
		errx(1, "%d %s", __LINE__, devstat_errbuf);
140
152
Lines 141-146 Link Here
141
	return(1);
153
	return(1);
142
}
154
}
143
155
156
157
void
158
dsgetinfo(struct statinfo* dev)
159
{
160
	switch (devstat_getdevs(NULL, dev)) {
161
	case -1:
162
		errx(1, "%s", devstat_errbuf);
163
		break;
164
	case 1:
165
		num_devices = dev->dinfo->numdevs;
166
		generation = dev->dinfo->generation;
167
		cmdkre("refresh", NULL);
168
		break;
169
	default:
170
		break;
171
	}
172
}
173
144
int
174
int
145
dscmd(const char *cmd, const char *args, int maxshowdevs, struct statinfo *s1)
175
dscmd(const char *cmd, const char *args, int maxshowdevs, struct statinfo *s1)
146
{
176
{
Lines 321-323 Link Here
321
	}
351
	}
322
	return(1);
352
	return(1);
323
}
353
}
354
355
356
void
357
dslabel(int maxdrives, int diskcol, int diskrow)
358
{
359
	int i, j;
360
361
	mvprintw(diskrow, diskcol, "Disks");
362
	mvprintw(diskrow + 1, diskcol, "KB/t");
363
	mvprintw(diskrow + 2, diskcol, "tps");
364
	mvprintw(diskrow + 3, diskcol, "MB/s");
365
	mvprintw(diskrow + 4, diskcol, "%%busy");
366
	/*
367
	 * For now, we don't support a fourth disk statistic.  So there's
368
	 * no point in providing a label for it.  If someone can think of a
369
	 * fourth useful disk statistic, there is room to add it.
370
	 */
371
	/* mvprintw(diskrow + 4, diskcol, " msps"); */
372
	j = 0;
373
	for (i = 0; i < num_devices && j < maxdrives; i++)
374
		if (dev_select[i].selected) {
375
			char tmpstr[80];
376
			sprintf(tmpstr, "%s%d", dev_select[i].device_name,
377
				dev_select[i].unit_number);
378
			mvprintw(diskrow, diskcol + 5 + 6 * j,
379
				" %5.5s", tmpstr);
380
			j++;
381
		}
382
}
383
384
static void
385
dsshow2(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct statinfo *then)
386
{
387
	long double transfers_per_second;
388
	long double kb_per_transfer, mb_per_second;
389
	long double elapsed_time, device_busy;
390
	int di;
391
392
	di = dev_select[dn].position;
393
394
	if (then != NULL) {
395
		/* Calculate relative to previous sample */
396
		elapsed_time = now->snap_time - then->snap_time;
397
	} else {
398
		/* Calculate relative to device creation */
399
		elapsed_time = now->snap_time - devstat_compute_etime(
400
		    &now->dinfo->devices[di].creation_time, NULL);
401
	}
402
403
	if (devstat_compute_statistics(&now->dinfo->devices[di], then ?
404
	    &then->dinfo->devices[di] : NULL, elapsed_time,
405
	    DSM_KB_PER_TRANSFER, &kb_per_transfer,
406
	    DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
407
	    DSM_MB_PER_SECOND, &mb_per_second,
408
	    DSM_BUSY_PCT, &device_busy,
409
	    DSM_NONE) != 0)
410
		errx(1, "%s", devstat_errbuf);
411
412
	lc = diskcol + lc * 6;
413
	putlongdouble(kb_per_transfer, diskrow + 1, lc, 5, 2, 0);
414
	putlongdouble(transfers_per_second, diskrow + 2, lc, 5, 0, 0);
415
	putlongdouble(mb_per_second, diskrow + 3, lc, 5, 2, 0);
416
	putlongdouble(device_busy, diskrow + 4, lc, 5, 0, 0);
417
}
418
419
static void
420
dsshow3(int diskcol, int diskrow, int dn, int lc, struct statinfo *now, struct statinfo *then)
421
{
422
	dsshow2(diskcol, diskrow, dn, lc, now, then);
423
}
424
425
void
426
dsshow(int maxdrives, int diskcol, int diskrow, struct statinfo *now, struct statinfo *then)
427
{
428
	int i, lc;
429
430
	for (i = 0, lc = 0; i < num_devices && lc < maxdrives; i++)
431
		if (dev_select[i].selected)
432
			dsshow3(diskcol, diskrow, i, ++lc, now, then);
433
}
(-)usr.bin/systat/devs.h (-1 / +15 lines)
Lines 2-7 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
 * All rights reserved.
6
 * All rights reserved.
6
 *
7
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * Redistribution and use in source and binary forms, with or without
Lines 28-32 Link Here
28
 * $FreeBSD$
29
 * $FreeBSD$
29
 */
30
 */
30
31
31
int dsinit(int, struct statinfo *, struct statinfo *, struct statinfo *);
32
#ifndef DEVS_H
33
#define DEVS_H
34
35
#include <devstat.h>
36
37
int dsinit(int);
38
void dsgetinfo(struct statinfo *);
32
int dscmd(const char *, const char *, int, struct statinfo *);
39
int dscmd(const char *, const char *, int, struct statinfo *);
40
41
void dslabel(int, int, int);
42
void dsshow(int, int, int, struct statinfo *, struct statinfo *);
43
44
extern struct statinfo cur_dev, last_dev, run_dev;
45
46
#endif
(-)usr.bin/systat/iostat.c (-27 / +19 lines)
Lines 79-86 Link Here
79
#include "extern.h"
79
#include "extern.h"
80
#include "devs.h"
80
#include "devs.h"
81
81
82
struct statinfo cur, last;
83
84
static  int linesperregion;
82
static  int linesperregion;
85
static  double etime;
83
static  double etime;
86
static  int numbers = 0;		/* default display bar graphs */
84
static  int numbers = 0;		/* default display bar graphs */
Lines 111-127 Link Here
111
int
109
int
112
initiostat(void)
110
initiostat(void)
113
{
111
{
114
	if ((num_devices = devstat_getnumdevs(NULL)) < 0)
115
		return(0);
116
117
	cur.dinfo = calloc(1, sizeof(struct devinfo));
118
	last.dinfo = calloc(1, sizeof(struct devinfo));
119
120
	/*
112
	/*
121
	 * This value for maxshowdevs (100) is bogus.  I'm not sure exactly
113
	 * This value for maxshowdevs (100) is bogus.  I'm not sure exactly
122
	 * how to calculate it, though.
114
	 * how to calculate it, though.
123
	 */
115
	 */
124
	if (dsinit(100, &cur, &last, NULL) != 1)
116
	if (dsinit(7) != 1)
125
		return(0);
117
		return(0);
126
118
127
	return(1);
119
	return(1);
Lines 133-149 Link Here
133
	struct devinfo *tmp_dinfo;
125
	struct devinfo *tmp_dinfo;
134
	size_t len;
126
	size_t len;
135
127
136
	len = sizeof(cur.cp_time);
128
	len = sizeof(cur_dev.cp_time);
137
	if (sysctlbyname("kern.cp_time", &cur.cp_time, &len, NULL, 0)
129
	if (sysctlbyname("kern.cp_time", &cur_dev.cp_time, &len, NULL, 0)
138
	    || len != sizeof(cur.cp_time)) {
130
	    || len != sizeof(cur_dev.cp_time)) {
139
		perror("kern.cp_time");
131
		perror("kern.cp_time");
140
		exit (1);
132
		exit (1);
141
	}
133
	}
142
	tmp_dinfo = last.dinfo;
134
	tmp_dinfo = last_dev.dinfo;
143
	last.dinfo = cur.dinfo;
135
	last_dev.dinfo = cur_dev.dinfo;
144
	cur.dinfo = tmp_dinfo;
136
	cur_dev.dinfo = tmp_dinfo;
145
137
146
	last.snap_time = cur.snap_time;
138
	last_dev.snap_time = cur_dev.snap_time;
147
139
148
	/*
140
	/*
149
	 * Here what we want to do is refresh our device stats.
141
	 * Here what we want to do is refresh our device stats.
Lines 152-158 Link Here
152
	 * the selection process again, in case a device that we
144
	 * the selection process again, in case a device that we
153
	 * were previously displaying has gone away.
145
	 * were previously displaying has gone away.
154
	 */
146
	 */
155
	switch (devstat_getdevs(NULL, &cur)) {
147
	switch (devstat_getdevs(NULL, &cur_dev)) {
156
	case -1:
148
	case -1:
157
		errx(1, "%s", devstat_errbuf);
149
		errx(1, "%s", devstat_errbuf);
158
		break;
150
		break;
Lines 162-169 Link Here
162
	default:
154
	default:
163
		break;
155
		break;
164
	}
156
	}
165
	num_devices = cur.dinfo->numdevs;
157
	num_devices = cur_dev.dinfo->numdevs;
166
	generation = cur.dinfo->generation;
158
	generation = cur_dev.dinfo->generation;
167
159
168
}
160
}
169
161
Lines 260-270 Link Here
260
	long t;
252
	long t;
261
	int i, row, _col;
253
	int i, row, _col;
262
254
263
#define X(fld)	t = cur.fld[i]; cur.fld[i] -= last.fld[i]; last.fld[i] = t
255
#define X(fld)	t = cur_dev.fld[i]; cur_dev.fld[i] -= last_dev.fld[i]; last_dev.fld[i] = t
264
	etime = 0;
256
	etime = 0;
265
	for(i = 0; i < CPUSTATES; i++) {
257
	for(i = 0; i < CPUSTATES; i++) {
266
		X(cp_time);
258
		X(cp_time);
267
		etime += cur.cp_time[i];
259
		etime += cur_dev.cp_time[i];
268
	}
260
	}
269
	if (etime == 0.0)
261
	if (etime == 0.0)
270
		etime = 1.0;
262
		etime = 1.0;
Lines 313-322 Link Here
313
305
314
	di = dev_select[dn].position;
306
	di = dev_select[dn].position;
315
307
316
	busy_seconds = cur.snap_time - last.snap_time;
308
	busy_seconds = cur_dev.snap_time - last_dev.snap_time;
317
309
318
	if (devstat_compute_statistics(&cur.dinfo->devices[di],
310
	if (devstat_compute_statistics(&cur_dev.dinfo->devices[di],
319
	    &last.dinfo->devices[di], busy_seconds,
311
	    &last_dev.dinfo->devices[di], busy_seconds,
320
	    DSM_KB_PER_TRANSFER, &kb_per_transfer,
312
	    DSM_KB_PER_TRANSFER, &kb_per_transfer,
321
	    DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
313
	    DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
322
	    DSM_MB_PER_SECOND, &mb_per_second, DSM_NONE) != 0)
314
	    DSM_MB_PER_SECOND, &mb_per_second, DSM_NONE) != 0)
Lines 349-360 Link Here
349
341
350
	dtime = 0.0;
342
	dtime = 0.0;
351
	for (i = 0; i < CPUSTATES; i++)
343
	for (i = 0; i < CPUSTATES; i++)
352
		dtime += cur.cp_time[i];
344
		dtime += cur_dev.cp_time[i];
353
	if (dtime == 0.0)
345
	if (dtime == 0.0)
354
		dtime = 1.0;
346
		dtime = 1.0;
355
	wmove(wnd, row, INSET);
347
	wmove(wnd, row, INSET);
356
#define CPUSCALE	0.5
348
#define CPUSCALE	0.5
357
	histogram(100.0 * cur.cp_time[o] / dtime, 50, CPUSCALE);
349
	histogram(100.0 * cur_dev.cp_time[o] / dtime, 50, CPUSCALE);
358
}
350
}
359
351
360
static void
352
static void
Lines 388-394 Link Here
388
		numbers = 1;
380
		numbers = 1;
389
	else if (prefix(cmd, "bars"))
381
	else if (prefix(cmd, "bars"))
390
		numbers = 0;
382
		numbers = 0;
391
	else if (!dscmd(cmd, args, 100, &cur))
383
	else if (!dscmd(cmd, args, 100, &cur_dev))
392
		return (0);
384
		return (0);
393
	wclear(wnd);
385
	wclear(wnd);
394
	labeliostat();
386
	labeliostat();
(-)usr.bin/systat/swap.c (-5 / +30 lines)
Lines 3-8 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
 *
7
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * modification, are permitted provided that the following conditions
Lines 55-60 Link Here
55
56
56
#include "systat.h"
57
#include "systat.h"
57
#include "extern.h"
58
#include "extern.h"
59
#include "devs.h"
58
60
59
kvm_t	*kd;
61
kvm_t	*kd;
60
62
Lines 63-69 Link Here
63
static int dlen, odlen;
65
static int dlen, odlen;
64
static int hlen;
66
static int hlen;
65
static int ulen, oulen;
67
static int ulen, oulen;
68
static int voffset = 2;
69
70
/* constants after booting */
66
static int pagesize;
71
static int pagesize;
72
static unsigned long swap_maxpages;
67
73
68
WINDOW *
74
WINDOW *
69
openswap(void)
75
openswap(void)
Lines 91-96 Link Here
91
97
92
static struct kvm_swap kvmsw[NSWAP];
98
static struct kvm_swap kvmsw[NSWAP];
93
static int kvnsw, okvnsw;
99
static int kvnsw, okvnsw;
100
static int64_t swap_total;
94
101
95
static void calclens(void);
102
static void calclens(void);
96
103
Lines 125-130 Link Here
125
132
126
	header = getbsize(&hlen, &blocksize);
133
	header = getbsize(&hlen, &blocksize);
127
	pagesize = getpagesize();
134
	pagesize = getpagesize();
135
	GETSYSCTL("vm.swap_maxpages", swap_maxpages);
128
136
129
	if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
137
	if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
130
		error("systat: kvm_getswapinfo failed");
138
		error("systat: kvm_getswapinfo failed");
Lines 137-142 Link Here
137
	oulen = ulen;
145
	oulen = ulen;
138
146
139
	once = 1;
147
	once = 1;
148
149
	dsinit(12);
150
140
	return (1);
151
	return (1);
141
}
152
}
142
153
Lines 143-158 Link Here
143
void
154
void
144
fetchswap(void)
155
fetchswap(void)
145
{
156
{
146
147
	okvnsw = kvnsw;
157
	okvnsw = kvnsw;
148
	if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
158
	if ((kvnsw = kvm_getswapinfo(kd, kvmsw, NSWAP, 0)) < 0) {
149
		error("systat: kvm_getswapinfo failed");
159
		error("systat: kvm_getswapinfo failed");
150
		return;
160
		return;
151
	}
161
	}
162
	GETSYSCTL("vm.swap_total", swap_total);
152
163
153
	odlen = dlen;
164
	odlen = dlen;
154
	oulen = ulen;
165
	oulen = ulen;
155
	calclens();
166
	calclens();
167
168
	struct devinfo *tmp_dinfo;
169
170
	tmp_dinfo = last_dev.dinfo;
171
	last_dev.dinfo = cur_dev.dinfo;
172
	cur_dev.dinfo = tmp_dinfo;
173
174
	last_dev.snap_time = cur_dev.snap_time;
175
	dsgetinfo( &cur_dev );
156
}
176
}
157
177
158
void
178
void
Lines 165-171 Link Here
165
185
166
	werase(wnd);
186
	werase(wnd);
167
187
168
	mvwprintw(wnd, 0, 0, "%*s%*s%*s %s",
188
	mvwprintw(wnd, 0, 0, "swap_maxpages: %ld", swap_maxpages);
189
	mvwprintw(wnd, 0, 40, "swap_total: %ld", swap_total / 1024);
190
191
	mvwprintw(wnd, voffset + 0, 0, "%*s%*s%*s %s",
169
	    -dlen, "Disk", hlen, header, ulen, "Used",
192
	    -dlen, "Disk", hlen, header, ulen, "Used",
170
	    "/0%  /10  /20  /30  /40  /50  /60  /70  /80  /90  /100");
193
	    "/0%  /10  /20  /30  /40  /50  /60  /70  /80  /90  /100");
171
194
Lines 176-183 Link Here
176
			name = "Total";
199
			name = "Total";
177
		} else
200
		} else
178
			name = kvmsw[i].ksw_devname;
201
			name = kvmsw[i].ksw_devname;
179
		mvwprintw(wnd, i + 1, 0, "%*s", -dlen, name);
202
		mvwprintw(wnd, voffset + i + 1, 0, "%*s", -dlen, name);
180
	}
203
	}
204
	dslabel(12, 0, 18);
181
}
205
}
182
206
183
void
207
void
Lines 198-204 Link Here
198
		if (kvmsw[i].ksw_total == 0) {
222
		if (kvmsw[i].ksw_total == 0) {
199
			mvwprintw(
223
			mvwprintw(
200
			    wnd,
224
			    wnd,
201
			    i + 1,
225
			    voffset + i + 1,
202
			    dlen + hlen + ulen + 1,
226
			    dlen + hlen + ulen + 1,
203
			    "(swap not configured)"
227
			    "(swap not configured)"
204
			);
228
			);
Lines 205-211 Link Here
205
			continue;
229
			continue;
206
		}
230
		}
207
231
208
		wmove(wnd, i + 1, dlen);
232
		wmove(wnd, voffset + i + 1, dlen);
209
233
210
		wprintw(wnd, "%*d", hlen, CONVERT(kvmsw[i].ksw_total));
234
		wprintw(wnd, "%*d", hlen, CONVERT(kvmsw[i].ksw_total));
211
		wprintw(wnd, "%*d", ulen, CONVERT(kvmsw[i].ksw_used));
235
		wprintw(wnd, "%*d", ulen, CONVERT(kvmsw[i].ksw_used));
Lines 217-220 Link Here
217
			waddch(wnd, 'X');
241
			waddch(wnd, 'X');
218
		wclrtoeol(wnd);
242
		wclrtoeol(wnd);
219
	}
243
	}
244
	dsshow(12, 0, 18, &cur_dev, &last_dev);
220
}
245
}
(-)usr.bin/systat/systat.h (+4 lines)
Lines 68-70 Link Here
68
#define NVAL(indx)  namelist[(indx)].n_value
68
#define NVAL(indx)  namelist[(indx)].n_value
69
#define NPTR(indx)  (void *)NVAL((indx))
69
#define NPTR(indx)  (void *)NVAL((indx))
70
#define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len))
70
#define NREAD(indx, buf, len) kvm_ckread(NPTR((indx)), (buf), (len))
71
72
extern void putint(int, int, int, int);
73
extern void putfloat(double, int, int, int, int, int);
74
extern void putlongdouble(long double, int, int, int, int, int);
(-)usr.bin/systat/vmstat.c (-117 / +35 lines)
Lines 66-72 Link Here
66
#include <time.h>
66
#include <time.h>
67
#include <unistd.h>
67
#include <unistd.h>
68
#include <utmpx.h>
68
#include <utmpx.h>
69
#include <devstat.h>
70
#include "systat.h"
69
#include "systat.h"
71
#include "extern.h"
70
#include "extern.h"
72
#include "devs.h"
71
#include "devs.h"
Lines 125-131 Link Here
125
static u_long kmem_size;
124
static u_long kmem_size;
126
static u_int v_page_count;
125
static u_int v_page_count;
127
126
128
struct statinfo cur, last, run;
129
127
130
#define	total s.Total
128
#define	total s.Total
131
#define	nchtotal s.nchstats
129
#define	nchtotal s.nchstats
Lines 137-149 Link Here
137
static void allocinfo(struct Info *);
135
static void allocinfo(struct Info *);
138
static void copyinfo(struct Info *, struct Info *);
136
static void copyinfo(struct Info *, struct Info *);
139
static float cputime(int);
137
static float cputime(int);
140
static void dinfo(int, int, struct statinfo *, struct statinfo *);
141
static void do_putuint64(uint64_t, int, int, int, int);
138
static void do_putuint64(uint64_t, int, int, int, int);
142
static void getinfo(struct Info *);
139
static void getinfo(struct Info *);
143
static void putint(int, int, int, int);
144
static void putuint64(uint64_t, int, int, int);
140
static void putuint64(uint64_t, int, int, int);
145
static void putfloat(double, int, int, int, int, int);
146
static void putlongdouble(long double, int, int, int, int, int);
147
static int ucount(void);
141
static int ucount(void);
148
142
149
static	int ncpu;
143
static	int ncpu;
Lines 209-226 Link Here
209
	int i;
203
	int i;
210
	size_t sz;
204
	size_t sz;
211
205
212
	if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
206
	if (dsinit(MAXDRIVES) != 1)
213
		warnx("%s", devstat_errbuf);
214
		return(0);
207
		return(0);
215
	}
216
208
217
	cur.dinfo = calloc(1, sizeof(struct devinfo));
218
	last.dinfo = calloc(1, sizeof(struct devinfo));
219
	run.dinfo = calloc(1, sizeof(struct devinfo));
220
221
	if (dsinit(MAXDRIVES, &cur, &last, &run) != 1)
222
		return(0);
223
224
	if (nintr == 0) {
209
	if (nintr == 0) {
225
		if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) {
210
		if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) {
226
			error("sysctl(hw.intrcnt...) failed: %s",
211
			error("sysctl(hw.intrcnt...) failed: %s",
Lines 318-324 Link Here
318
303
319
	clear();
304
	clear();
320
	mvprintw(STATROW, STATCOL + 6, "users    Load");
305
	mvprintw(STATROW, STATCOL + 6, "users    Load");
321
	mvprintw(STATROW + 1, STATCOL + 3, "Mem usage:    %%Phy   %%Kmem");
306
	mvprintw(STATROW + 1, STATCOL + 3, "Mem usage:    %%Phy   %%Kmem   %%VM");
322
	mvprintw(MEMROW, MEMCOL, "Mem: KB    REAL            VIRTUAL");
307
	mvprintw(MEMROW, MEMCOL, "Mem: KB    REAL            VIRTUAL");
323
	mvprintw(MEMROW + 1, MEMCOL, "        Tot   Share      Tot    Share");
308
	mvprintw(MEMROW + 1, MEMCOL, "        Tot   Share      Tot    Share");
324
	mvprintw(MEMROW + 2, MEMCOL, "Act");
309
	mvprintw(MEMROW + 2, MEMCOL, "Act");
Lines 371-397 Link Here
371
	mvprintw(NAMEIROW, NAMEICOL, "Namei     Name-cache   Dir-cache");
356
	mvprintw(NAMEIROW, NAMEICOL, "Namei     Name-cache   Dir-cache");
372
	mvprintw(NAMEIROW + 1, NAMEICOL,
357
	mvprintw(NAMEIROW + 1, NAMEICOL,
373
		"   Calls    hits   %%    hits   %%");
358
		"   Calls    hits   %%    hits   %%");
374
	mvprintw(DISKROW, DISKCOL, "Disks");
359
	dslabel(MAXDRIVES, DISKCOL, DISKROW);
375
	mvprintw(DISKROW + 1, DISKCOL, "KB/t");
376
	mvprintw(DISKROW + 2, DISKCOL, "tps");
377
	mvprintw(DISKROW + 3, DISKCOL, "MB/s");
378
	mvprintw(DISKROW + 4, DISKCOL, "%%busy");
379
	/*
380
	 * For now, we don't support a fourth disk statistic.  So there's
381
	 * no point in providing a label for it.  If someone can think of a
382
	 * fourth useful disk statistic, there is room to add it.
383
	 */
384
	/* mvprintw(DISKROW + 4, DISKCOL, " msps"); */
385
	j = 0;
386
	for (i = 0; i < num_devices && j < MAXDRIVES; i++)
387
		if (dev_select[i].selected) {
388
			char tmpstr[80];
389
			sprintf(tmpstr, "%s%d", dev_select[i].device_name,
390
				dev_select[i].unit_number);
391
			mvprintw(DISKROW, DISKCOL + 5 + 6 * j,
392
				" %5.5s", tmpstr);
393
			j++;
394
		}
395
360
396
	for (i = 0; i < nintr; i++) {
361
	for (i = 0; i < nintr; i++) {
397
		if (intrloc[i] == 0)
362
		if (intrloc[i] == 0)
Lines 401-407 Link Here
401
}
366
}
402
367
403
#define X(fld)	{t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
368
#define X(fld)	{t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
404
#define Q(fld)	{t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;}
369
#define Q(fld)	{t=cur_dev.fld[i]; cur_dev.fld[i]-=last_dev.fld[i]; if(state==TIME) last_dev.fld[i]=t;}
405
#define Y(fld)	{t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
370
#define Y(fld)	{t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
406
#define Z(fld)	{t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
371
#define Z(fld)	{t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
407
	if(state == TIME) s1.nchstats.fld = t;}
372
	if(state == TIME) s1.nchstats.fld = t;}
Lines 494-499 Link Here
494
	   STATROW + 1, STATCOL + 15, 2, 0, 1);
459
	   STATROW + 1, STATCOL + 15, 2, 0, 1);
495
	putfloat(100.0 * s.v_kmem_map_size / kmem_size,
460
	putfloat(100.0 * s.v_kmem_map_size / kmem_size,
496
	   STATROW + 1, STATCOL + 22, 2, 0, 1);
461
	   STATROW + 1, STATCOL + 22, 2, 0, 1);
462
	putfloat(100.0 * total.t_avm / total.t_vm,
463
	   STATROW + 1, STATCOL + 30, 2, 0, 1);
497
464
498
	putuint64(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7);
465
	putuint64(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7);
499
	putuint64(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7);
466
	putuint64(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7);
Lines 543-562 Link Here
543
	PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4);
510
	PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4);
544
	PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4);
511
	PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4);
545
	PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4);
512
	PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4);
546
	for (i = 0, lc = 0; i < num_devices && lc < MAXDRIVES; i++)
513
	switch(state) {
547
		if (dev_select[i].selected) {
514
	case TIME:
548
			switch(state) {
515
		dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &last_dev);
549
			case TIME:
516
		break;
550
				dinfo(i, ++lc, &cur, &last);
517
	case RUN:
551
				break;
518
		dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &run_dev);
552
			case RUN:
519
		break;
553
				dinfo(i, ++lc, &cur, &run);
520
	case BOOT:
554
				break;
521
		dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, NULL);
555
			case BOOT:
522
		break;
556
				dinfo(i, ++lc, &cur, NULL);
523
	}
557
				break;
558
			}
559
		}
560
	putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7);
524
	putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7);
561
	putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7);
525
	putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7);
562
	putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7);
526
	putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7);
Lines 582-595 Link Here
582
	if (prefix(cmd, "run")) {
546
	if (prefix(cmd, "run")) {
583
		retval = 1;
547
		retval = 1;
584
		copyinfo(&s2, &s1);
548
		copyinfo(&s2, &s1);
585
		switch (devstat_getdevs(NULL, &run)) {
549
		switch (devstat_getdevs(NULL, &run_dev)) {
586
		case -1:
550
		case -1:
587
			errx(1, "%s", devstat_errbuf);
551
			errx(1, "%s", devstat_errbuf);
588
			break;
552
			break;
589
		case 1:
553
		case 1:
590
			num_devices = run.dinfo->numdevs;
554
			num_devices = run_dev.dinfo->numdevs;
591
			generation = run.dinfo->generation;
555
			generation = run_dev.dinfo->generation;
592
			retval = dscmd("refresh", NULL, MAXDRIVES, &cur);
556
			retval = dscmd("refresh", NULL, MAXDRIVES, &cur_dev);
593
			if (retval == 2)
557
			if (retval == 2)
594
				labelkre();
558
				labelkre();
595
			break;
559
			break;
Lines 612-625 Link Here
612
		retval = 1;
576
		retval = 1;
613
		if (state == RUN) {
577
		if (state == RUN) {
614
			getinfo(&s1);
578
			getinfo(&s1);
615
			switch (devstat_getdevs(NULL, &run)) {
579
			switch (devstat_getdevs(NULL, &run_dev)) {
616
			case -1:
580
			case -1:
617
				errx(1, "%s", devstat_errbuf);
581
				errx(1, "%s", devstat_errbuf);
618
				break;
582
				break;
619
			case 1:
583
			case 1:
620
				num_devices = run.dinfo->numdevs;
584
				num_devices = run_dev.dinfo->numdevs;
621
				generation = run.dinfo->generation;
585
				generation = run_dev.dinfo->generation;
622
				retval = dscmd("refresh",NULL, MAXDRIVES, &cur);
586
				retval = dscmd("refresh",NULL, MAXDRIVES, &cur_dev);
623
				if (retval == 2)
587
				if (retval == 2)
624
					labelkre();
588
					labelkre();
625
				break;
589
				break;
Lines 629-635 Link Here
629
		}
593
		}
630
		return (retval);
594
		return (retval);
631
	}
595
	}
632
	retval = dscmd(cmd, args, MAXDRIVES, &cur);
596
	retval = dscmd(cmd, args, MAXDRIVES, &cur_dev);
633
597
634
	if (retval == 2)
598
	if (retval == 2)
635
		labelkre();
599
		labelkre();
Lines 667-673 Link Here
667
	return (s.time[indx] * 100.0 / lt);
631
	return (s.time[indx] * 100.0 / lt);
668
}
632
}
669
633
670
static void
634
void
671
putint(int n, int l, int lc, int w)
635
putint(int n, int l, int lc, int w)
672
{
636
{
673
637
Lines 713-719 Link Here
713
	addstr(b);
677
	addstr(b);
714
}
678
}
715
679
716
static void
680
void
717
putfloat(double f, int l, int lc, int w, int d, int nz)
681
putfloat(double f, int l, int lc, int w, int d, int nz)
718
{
682
{
719
	int snr;
683
	int snr;
Lines 745-751 Link Here
745
	addstr(b);
709
	addstr(b);
746
}
710
}
747
711
748
static void
712
void
749
putlongdouble(long double f, int l, int lc, int w, int d, int nz)
713
putlongdouble(long double f, int l, int lc, int w, int d, int nz)
750
{
714
{
751
	int snr;
715
	int snr;
Lines 785-791 Link Here
785
	int mib[2];
749
	int mib[2];
786
750
787
	GETSYSCTL("kern.cp_time", ls->time);
751
	GETSYSCTL("kern.cp_time", ls->time);
788
	GETSYSCTL("kern.cp_time", cur.cp_time);
752
	GETSYSCTL("kern.cp_time", cur_dev.cp_time);
789
	GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch);
753
	GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch);
790
	GETSYSCTL("vm.stats.sys.v_trap", ls->v_trap);
754
	GETSYSCTL("vm.stats.sys.v_trap", ls->v_trap);
791
	GETSYSCTL("vm.stats.sys.v_syscall", ls->v_syscall);
755
	GETSYSCTL("vm.stats.sys.v_syscall", ls->v_syscall);
Lines 838-860 Link Here
838
	    size != sizeof(ncpu))
802
	    size != sizeof(ncpu))
839
		ncpu = 1;
803
		ncpu = 1;
840
804
841
	tmp_dinfo = last.dinfo;
805
	tmp_dinfo = last_dev.dinfo;
842
	last.dinfo = cur.dinfo;
806
	last_dev.dinfo = cur_dev.dinfo;
843
	cur.dinfo = tmp_dinfo;
807
	cur_dev.dinfo = tmp_dinfo;
844
808
845
	last.snap_time = cur.snap_time;
809
	last_dev.snap_time = cur_dev.snap_time;
846
	switch (devstat_getdevs(NULL, &cur)) {
810
	dsgetinfo(&cur_dev);
847
	case -1:
848
		errx(1, "%s", devstat_errbuf);
849
		break;
850
	case 1:
851
		num_devices = cur.dinfo->numdevs;
852
		generation = cur.dinfo->generation;
853
		cmdkre("refresh", NULL);
854
		break;
855
	default:
856
		break;
857
	}
858
}
811
}
859
812
860
static void
813
static void
Lines 881-918 Link Here
881
834
882
	bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
835
	bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
883
}
836
}
884
885
static void
886
dinfo(int dn, int lc, struct statinfo *now, struct statinfo *then)
887
{
888
	long double transfers_per_second;
889
	long double kb_per_transfer, mb_per_second;
890
	long double elapsed_time, device_busy;
891
	int di;
892
893
	di = dev_select[dn].position;
894
895
	if (then != NULL) {
896
		/* Calculate relative to previous sample */
897
		elapsed_time = now->snap_time - then->snap_time;
898
	} else {
899
		/* Calculate relative to device creation */
900
		elapsed_time = now->snap_time - devstat_compute_etime(
901
		    &now->dinfo->devices[di].creation_time, NULL);
902
	}
903
904
	if (devstat_compute_statistics(&now->dinfo->devices[di], then ?
905
	    &then->dinfo->devices[di] : NULL, elapsed_time,
906
	    DSM_KB_PER_TRANSFER, &kb_per_transfer,
907
	    DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
908
	    DSM_MB_PER_SECOND, &mb_per_second,
909
	    DSM_BUSY_PCT, &device_busy,
910
	    DSM_NONE) != 0)
911
		errx(1, "%s", devstat_errbuf);
912
913
	lc = DISKCOL + lc * 6;
914
	putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0);
915
	putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0);
916
	putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0);
917
	putlongdouble(device_busy, DISKROW + 4, lc, 5, 0, 0);
918
}
(-)usr.bin/systat/zarc.c (-27 / +44 lines)
Lines 1-6 Link Here
1
/*-
1
/*-
2
 * Copyright (c) 2014
2
 * Copyright (c) 2014 - 2017 Yoshihiro Ota
3
 *	The Regents of the University of California.  All rights reserved.
4
 *
3
 *
5
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 33-43 Link Here
33
#include <sys/types.h>
32
#include <sys/types.h>
34
#include <sys/sysctl.h>
33
#include <sys/sysctl.h>
35
34
35
/* #include <stdlib.h> */
36
#include <inttypes.h>
36
#include <inttypes.h>
37
#include <string.h>
37
#include <string.h>
38
#include <err.h>
38
39
39
#include "systat.h"
40
#include "systat.h"
40
#include "extern.h"
41
#include "extern.h"
42
#include "devs.h"
41
43
42
struct zfield{
44
struct zfield{
43
	uint64_t arcstats;
45
	uint64_t arcstats;
Lines 77-97 Link Here
77
void
79
void
78
labelzarc(void)
80
labelzarc(void)
79
{
81
{
82
	int row = 1;
80
	wmove(wnd, 0, 0); wclrtoeol(wnd);
83
	wmove(wnd, 0, 0); wclrtoeol(wnd);
81
	mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s",
84
	mvwprintw(wnd, 0, 31+1, "%4.4s %7.7s %7.7s %12.12s %12.12s",
82
		"rate", "hits", "misses", "total hits", "total misses");
85
		"rate", "hits", "misses", "total hits", "total misses");
83
#define L(row, str) mvwprintw(wnd, row, 5, str); \
86
#define L(str) mvwprintw(wnd, row, 5, #str); \
84
	mvwprintw(wnd, row, 31, ":"); \
87
	mvwprintw(wnd, row, 31, ":"); \
85
	mvwprintw(wnd, row, 31+4, "%%")
88
	mvwprintw(wnd, row, 31+4, "%%"); ++row
86
	L(1, "arcstats");
89
	L(arcstats);
87
	L(2, "arcstats.demand_data");
90
	L(arcstats.demand_data);
88
	L(3, "arcstats.demand_metadata");
91
	L(arcstats.demand_metadata);
89
	L(4, "arcstats.prefetch_data");
92
	L(arcstats.prefetch_data);
90
	L(5, "arcstats.prefetch_metadata");
93
	L(arcstats.prefetch_metadata);
91
	L(6, "zfetchstats");
94
	L(zfetchstats);
92
	L(7, "arcstats.l2");
95
	L(arcstats.l2);
93
	L(8, "vdev_cache_stats");
96
	L(vdev_cache_stats);
94
#undef L
97
#undef L
98
	dslabel(12, 0, 18);
95
}
99
}
96
100
97
static int calc(uint64_t hits, uint64_t misses)
101
static int calc(uint64_t hits, uint64_t misses)
Lines 131-136 Link Here
131
void
135
void
132
showzarc(void)
136
showzarc(void)
133
{
137
{
138
	int row = 1;
134
	struct zarcstats delta, rate;
139
	struct zarcstats delta, rate;
135
140
136
	memset(&delta, 0, sizeof delta);
141
	memset(&delta, 0, sizeof delta);
Lines 138-171 Link Here
138
143
139
	domode(&delta, &rate);
144
	domode(&delta, &rate);
140
145
141
#define DO(stat, row, col, fmt) \
146
#define DO(stat, col, fmt) \
142
	mvwprintw(wnd, row, col, fmt, stat)
147
	mvwprintw(wnd, row, col, fmt, stat)
143
#define	R(row, stat) DO(rate.hits.stat, row, 31+1, "%3"PRIu64)
148
#define	R(stat) DO(rate.hits.stat, 31+1, "%3"PRIu64)
144
#define	H(row, stat) DO(delta.hits.stat, row, 31+1+5, "%7"PRIu64); \
149
#define	H(stat) DO(delta.hits.stat, 31+1+5, "%7"PRIu64); \
145
	DO(curstat.hits.stat, row, 31+1+5+8+8, "%12"PRIu64)
150
	DO(curstat.hits.stat, 31+1+5+8+8, "%12"PRIu64)
146
#define	M(row, stat) DO(delta.misses.stat, row, 31+1+5+8, "%7"PRIu64); \
151
#define	M(stat) DO(delta.misses.stat, 31+1+5+8, "%7"PRIu64); \
147
	DO(curstat.misses.stat, row, 31+1+5+8+8+13, "%12"PRIu64)
152
	DO(curstat.misses.stat, 31+1+5+8+8+13, "%12"PRIu64)
148
#define	E(row, stat) R(row, stat); H(row, stat); M(row, stat); 
153
#define	E(stat) R(stat); H(stat); M(stat); ++row
149
	E(1, arcstats);
154
	E(arcstats);
150
	E(2, arcstats_demand_data);
155
	E(arcstats_demand_data);
151
	E(3, arcstats_demand_metadata);
156
	E(arcstats_demand_metadata);
152
	E(4, arcstats_prefetch_data);
157
	E(arcstats_prefetch_data);
153
	E(5, arcstats_prefetch_metadata);
158
	E(arcstats_prefetch_metadata);
154
	E(6, zfetchstats);
159
	E(zfetchstats);
155
	E(7, arcstats_l2);
160
	E(arcstats_l2);
156
	E(8, vdev_cache_stats);
161
	E(vdev_cache_stats);
157
#undef DO
162
#undef DO
158
#undef E
163
#undef E
159
#undef M
164
#undef M
160
#undef H
165
#undef H
161
#undef R
166
#undef R
167
	dsshow(12, 0, 18, &cur_dev, &last_dev);
162
}
168
}
163
169
164
int
170
int
165
initzarc(void)
171
initzarc(void)
166
{
172
{
173
	dsinit(12);
167
	getinfo(&initstat);
174
	getinfo(&initstat);
168
	curstat = oldstat = initstat;
175
	curstat = oldstat = initstat;
176
169
	return 1;
177
	return 1;
170
}
178
}
171
179
Lines 178-183 Link Here
178
static void
186
static void
179
getinfo(struct zarcstats *ls)
187
getinfo(struct zarcstats *ls)
180
{
188
{
189
	struct devinfo *tmp_dinfo;
190
191
	tmp_dinfo = last_dev.dinfo;
192
	last_dev.dinfo = cur_dev.dinfo;
193
	cur_dev.dinfo = tmp_dinfo;
194
195
	last_dev.snap_time = cur_dev.snap_time;
196
	dsgetinfo( &cur_dev );
197
181
	size_t size = sizeof( ls->hits.arcstats );
198
	size_t size = sizeof( ls->hits.arcstats );
182
	if ( sysctlbyname("kstat.zfs.misc.arcstats.hits",
199
	if ( sysctlbyname("kstat.zfs.misc.arcstats.hits",
183
		&ls->hits.arcstats, &size, NULL, 0 ) != 0 )
200
		&ls->hits.arcstats, &size, NULL, 0 ) != 0 )

Return to bug 213310